Game Development Reference

In-Depth Information

nators, thus dropping out of the equations. Recall that the weight of an object is its mass

times the acceleration due to gravity,
g
, which is 9.8 m/s
2
at sea level.

The formulas for calculating the total mass and center of gravity for a system of discrete

point masses can conveniently be written in vector notation as follows:

m
t
= Σ m
i

CG
=[Σ (
cg
i
) (m
i
)] / m
t

where
m
t
is the total mass,
m
i
is the mass of each point mass in the system,
CG
is the

combined center of gravity, and
cg
i
is the location of the center of gravity of each point

mass in design, or reference, coordinates. Notice that
CG
and
cg
i
are shown as vectors

since they denote position in Cartesian coordinates. This is a matter of convenience

since it allows you to take care of the
x
,
y
, and
z
components (or just
x
and
y
in two

dimensions) in one shot.

In the code samples that follow, let's assume that the point masses making up the body

are represented by an array of structures where each structure contains the point mass's

design coordinates and mass. The structure will also contain an element to hold the

coordinates of the point mass relative to the combined center of gravity of the rigid

body, which will be calculated later.

typedef struct _PointMass

{

float mass;

Vector designPosition;

Vector correctedPosition;

} PointMass;

// Assume that _NUMELEMENTS has been defined

PointMassElements[_NUMELEMENTS];

Here's some code that illustrates how to calculate the total mass and combined center

of gravity of the elements:

int i;

float TotalMass;

Vector CombinedCG;

Vector FirstMoment;

TotalMass = 0;

for(i=0; i<_NUMELEMENTS; i++)

TotalMass FAC+= Elements[i].mass;

FirstMoment = Vector(0, 0, 0);

for(i=0; i<_NUMELEMENTS; i++)

{

FirstMoment += Element[i].mass * Element[i].designPosition;