Game Development Reference
In-Depth Information
// Otherwise, evaluate the acceleration according
// to the curve fit equation.
else {
ax = -4.44e-7*Math.pow(v,4.0) + 2.56e-4*Math.pow(v,3.0) -
0.0216*v*v + 0.527*v - 1.51;
}
}
If the mode is “decelerate,” the x-direction acceleration is set to -2.0
m/s
2
. If the mode is
“cruising,” the acceleration is set to zero.
else if ( getMode().equals("decelerating") ) {
// Only decelerate if the velocity is positive.
if ( newQ[0] > 0.1 ) {
ax = -2.0;
}
else {
ax = 0.0;
}
}
// If the mode is "cruising," set the acceleration
// to zero.
else {
ax = 0.0;
}
Once the x-direction acceleration is computed, the right-hand sides of the equation of
motion ODEs can be filled.
// Fill the right-hand sides of the equation of
// motion ODEs.
dQ[0] = ds*ax;
dQ[1] = ds*newQ[0];
dQ[2] = 0.0;
dQ[3] = 0.0;
dQ[4] = 0.0;
dQ[5] = 0.0;
return dQ;
}
}
The GUI for the Boat Simulator is implemented in a class named
BoatSimulator
. As with
the other GUIs in this topic, the
BoatSimulator
class will not be discussed in detail. You can
download the complete code listing from the Apress website for this topic.