Game Development Reference
In-Depth Information
hovercraft simulation, without this sort of function, the airplane will do nothing. For
this purpose we've defined a function called CalcAirplaneLoads , which is called at every
step through the simulation. This function relies on a couple of other functions—
namely, LiftCoefficient , DragCoefficient , RudderLiftCoefficient , and Rudder
DragCoefficient . All of these functions are shown and discussed in detail in the section
“Modeling” on page 305 in Chapter 15 .
For the most part, the code contained in CalcAirplaneLoads is similar to the code you've
seen in the CalcLoads function of the hovercraft simulation. CalcAirplanLoads is a
little more involved since the airplane is modeled by a number of elements that con‐
tribute to the total lift and drag on the airplane. There's also another difference that
we've noted here:
{
.
.
.
// Convert forces from model space to earth space
Airplane.vForces = QVRotate(Airplane.qOrientation, Fb);
// Apply gravity (g is defined as −32.174 ft/s^2)
Airplane.vForces.z += g * Airplane.fMass;
.
.
.
}
Just about all of the forces acting on the airplane are first calculated in body-fixed co‐
ordinates and then converted to earth-fixed coordinates before the gravity force is ap‐
plied. The coordinate conversion is effected through the use of the function QVRotate ,
which rotates the force vector based on the airplane's current orientation, represented
by a quaternion. 1
Integration
Now that the code to define, initialize, and calculate loads on the airplane is complete,
you need to develop the code to actually integrate the equations of motion so that the
simulation can progress through time. The first thing you need to do is decide on the
integration scheme that you want to use. In this example, we decided to go with the
basic Euler's method. We've already discussed some better methods in Chapter 7 . We're
going with Euler's method here because it's simple and we didn't want to make the code
1. QVRotate is defined in Appendix C .