Game Development Reference
In-Depth Information
Next, to enforce the constraint that this orientation quaternion be a unit quaternion,
you must normalize the orientation quaternion. The following code sample illustrates
these steps:
// calculate the angular velocity of the airplane in body space:
Airplane.vAngularVelocity += Airplane.mInertiaInverse *
(Airplane.vMoments -
(Airplane.mInertia *
* dt;
// calculate the new rotation quaternion:
Airplane.qOrientation += (Airplane.qOrientation *
Airplane.vAngularVelocity) *
(0.5f * dt);
// now normalize the orientation quaternion:
mag = Airplane.qOrientation.Magnitude();
if (mag != 0)
Airplane.qOrientation /= mag;
// calculate the velocity in body space:
// (we'll need this to calculate lift and drag forces)
Airplane.vVelocityBody = QVRotate(~Airplane.qOrientation,
Notice the last line of code in the preceding sample. That line converts the airplane's
velocity vector from earth-fixed coordinates to body-fixed coordinates using QVRo
tate . Recall that it's more convenient to compute body forces in body-fixed coordinates.
QVRotate allows you to work with vectors back and forth from body-fixed to earth-fixed
Search Nedrilad ::

Custom Search