Game Development Reference

In-Depth Information

// get the Euler angles for our information

Vector u;

u = MakeEulerAnglesFromQ(Airplane.qOrientation);

Airplane.vEulerAngles.x = u.x; // roll

Airplane.vEulerAngles.y = u.y; // pitch

Airplane.vEulerAngles.z = u.z; // yaw

Very often, it's more convenient to calculate loads on an object like the airplane using

body-fixed coordinates. For example, when computing aerodynamic drag on the air‐

plane, you'll want to know the relative air velocity over the aircraft in body-fixed coor‐

dinates. The resulting drag force will also be in body-fixed coordinates. However, when

resolving all the loads on the aircraft to determine its motion in earth-fixed coordinates,

you'll want to convert those forces from body-fixed coordinates to earth-fixed coordi‐

nates. You can use
QVRotate
to rotate any vector, such as a force vector, from one co‐

ordinate system to another. The following code sample shows how
QVRotate
is used to

convert a force vector in body-fixed coordinates to the equivalent force in earth-fixed

coordinates.

void CalcAirplaneLoads(void)

{

.

.

.

// Convert forces from model space to earth space

Airplane.vForces = QVRotate(Airplane.qOrientation, Fb);

.

.

.

}

Throughout the simulation, you'll have to update the airplane's orientation by integrat‐

ing the angular equations of motion. The first step in handling angular motion is to

calculate the new angular velocity at a given time step based on the previously calculated

moments acting on the airplane and its mass properties. We do this in body coordinates

using the angular equation of motion:

∑
M
cg
= d
H
cg
/dt
= I
(d
ω
/dt) + (
ω
× (
I ω
))

The next step is to integrate again to update the airplane's orientation, which is expressed

as a quaternion. Here, you need to use the differential equation relating an orientation

quaternion to angular velocity that we discussed earlier:

d
q
/dt = (1/2)
ω q