Game Development Reference
In-Depth Information
be awkward to do so. For example, consider the airplane from the FlightSim discussion
in Chapter 7 , where you'll have the local coordinate design axes running, relative to the
pilot, fore and aft, up and down, and left and right. This orientation is convenient for
locating the parts of the wings, tail, elevators, etc. with respect to one another, but these
axes don't necessarily represent the principal axes of the airplane. The end result is that
you'll use axes that are convenient and deal with the nonzero products of inertia (which,
by the way, can be either positive or negative).
We already showed you how to calculate the combined moments of inertia for a com‐
posite body made up of a few smaller elements. Accounting for the product of inertia
terms follows the same procedure except that, typically, your elements are such that
their local product of inertia terms are zero. This is the case only if you represent your
elements by simple geometries such as point masses, spheres, rectangles, etc. That being
the case, the main contribution to the rigid body's products of inertia will be due to the
transfer of axes terms for each element.
Before looking at some sample code, let's first revise the element structure to include a
new term to hold the element's local moment of inertia as follows:
typedef struct _PointMass
float mass;
Vector designPosition;
Vector correctedPosition;
Vector localInertia;
} PointMass;
Here we're using a vector to represent the three local moment of inertia terms and we're
also assuming that the local products of inertia are zero for each element.
The following code sample shows how to calculate the inertia tensor given the compo‐
nent elements:
float Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
Matrix3x3 InertiaTensor;
Ixx = 0; Iyy = 0; Izz = 0;
Ixy = 0; Ixz = 0; Iyz = 0;
for (i = 0; i<_NUMELEMENTS; i++)
Ixx += Element[i].LocalInertia.x +
Element[i].mass * (Element[i].correctedPosition.y *
Element[i].correctedPosition.y +
Element[i].correctedPosition.z *
Iyy += Element[i].LocalInertia.y +
Element[i].mass * (Element[i].correctedPosition.z *
Element[i].correctedPosition.z +
Search Nedrilad ::

Custom Search