Game Development Reference
In-Depth Information
C ONVERTING F UNCTIONS TO R ESPONSE C URVES
As we touched on at the beginning of this chapter, response curves have another
valuable role to play for us. The functions from Chapter 10 are rather inflexible in
that we couldn't tweak specific areas of the curves the way we might want to. We are
stuck with whatever was spit out of the equation for a given x value. Similarly,
some of the probability distributions in Chapter 11 are function-based. While we
can calculate the probability ( y ) for a given x value, we lack the ability to extract a
random x value based on all of the different y probabilities.
While these two problems may not seem related, we can actually solve them
in much the same manner using response curves. The secret to both solutions is
converting the results of the function into a custom response curve. Once we have
created the response curve, we have much more flexibility available to us. Before we
get too far ahead of ourselves, however, we need to address the methods and code
for putting the numbers into the response curve to begin with.
S IMPLE 1- TO -1 M APPINGS
To keep the numbers manageable at first, we will start with a simple equation:
Because we are going to be filling a finite space with our results, it is important
that we establish the range with which we are working. In this case, we will limit
ourselves to the range 0
40.
As usual, we first need to define our vector.
x
typedef std::vector< double > CURVE_VECTOR;
CURVE_VECTOR mvEquationResults;
The process of filling the vector is rather intuitive.
void CLinearFunction::FillVector( int Size )
{
double y;
for ( int x = 0; x <= Size; x++ ) {
y = ( -2 * x ) + 100;
mvEquationResults.push_back( y );
} // end for
}
 
 
Search WWH ::




Custom Search