Game Development Reference
In-Depth Information
Since the ODE solver will be used to update the position and velocity of the car, the Car
class has to declare a getRightHandSide method to define the right-hand sides of the equations
to be solved. The first part of the getRightHandSide method is similar to that found in many of
the classes we've written previously. The intermediate values of location and velocity for the
car are computed. In this simulation, we only are concerned with the x-components of location
and velocity, but the y- and z-components are included in the method to make the class easily
extendable to a car traveling in all three directions.
public double[] getRightHandSide(double s, double q[],
double deltaQ[], double ds,
double qScale) {
double dQ[] = new double[6];
double newQ[] = new double[6];
// Compute the intermediate values of the
// dependent variables.
for(int i=0; i<6; ++i) {
newQ[i] = q[i] + qScale*deltaQ[i];
} getRightHandSide
The next thing the method does is to define the torque curve. We're going to use the
simplified torque curve shown in Figure 8-7 where three straight lines approximate the torque
curve. The three lines are defined in Equations (8.17a) through (8.17c). Which line to use depends
on the engine turnover rate.
// Compute the constants that define the
// torque curve line.
double b, d;
if ( getOmegaE() <= 1000.0 ) {
b = 0.0;
d = 220.0;
}
else if ( getOmegaE() < 4600.0 ) {
b = 0.025;
d = 195.0;
}
else {
b = -0.032;
d = 457.2;
}
The getRightHandSide method computes the total drag and rolling friction forces from
Equations (8.3) and (8.4). Because the field that represents the gravitational acceleration, G ,
was given a value of -9.81 in the SimpleProjectile class, the value of the rolling friction force
will be negative.
Search WWH ::




Custom Search