Game Development Reference
In-Depth Information
// Compute velocity magnitude.
double vx = newQ[0];
double vy = newQ[2];
double vz = newQ[4];
double v = Math.sqrt(vx*vx + vy*vy + vz*vz) + 1.0e-8;
// Compute the total drag force.
double Fd = 0.5*getDensity()*getArea()*getCd()*v*v;
// Compute the force of rolling friction. Because
// the G constant defined in the SimpleProjectile
// class has a negative sign, the value computed here
// will be negative.
double Fr = getMuR()*getMass()*G;
The final part of the getRightHandSide method defines the right-hand side of the ODEs
that describe the motion of the car. If the car is accelerating, the acceleration of the car is
computed from Equation (8.20). If the car is braking and the velocity is positive, the acceleration
of the car is set to -5.0 m/s 2 . If the car is cruising at constant velocity, the acceleration is set to
zero. The equations for the y- and z-components of velocity are all set to zero.
// Compute the right-hand sides of the six ODEs
// newQ[0] is the intermediate value of velocity.
// The acceleration of the car is determined by
// whether the car is accelerating, cruising, or
// braking. The braking acceleration is assumed to
// be a constant -5.0 m/s^2.
if ( mode.equals("accelerating") ) {
double c1 = -Fd/getMass();
double tmp = getGearRatio()*getFinalDriveRatio()/
getWheelRadius();
double c2 = 60.0*tmp*tmp*b*v/(2.0*Math.PI*getMass());
double c3 = (tmp*d + Fr)/getMass();
dQ[0] = ds*(c1 + c2 + c3);
}
else if ( mode.equals("braking") ) {
// Only brake if the velocity is positive.
if ( newQ[0] > 0.1 ) {
dQ[0] = ds*(-5.0);
}
else {
dQ[0] = 0.0;
}
}
else {
dQ[0] = 0.0;
}
Search WWH ::




Custom Search