Game Development Reference

In-Depth Information

transformMatrix);

}

Note particularly that the change of basis transform from section 9.4.6 is optimized

into one operation.

When we transform the inertia tensor, we are only interested in the rotational

component of the object's transform. It doesn't matter where the object is in space,

but only which direction it is oriented in. The code therefore treats the 4

×

3 transform

matrix as if it were a 3

3 matrix (i.e., a rotation matrix only). Together these two

optimizations make for considerably faster code.

So at each frame we calculate the transform matrix, transform the inverse inertia

tensor into world coordinates, and then perform the rigid-body integration with this

transformed version. Before we look at the code to perform the final integration, we

need to examine how a body reacts to a whole series of torques and forces (with their

corresponding torque components).

×

10.3

D'A
LEMBERT FOR
R
OTATION

Just as we have an equivalent of Newton's second law of motion, we can also find a

rotational version of D'Alembert's principle. Recall that D'Alembert's principle allows

us to accumulate a whole series of forces into one single force, and then apply just this

one force. The effect of the one accumulated force is identical to the effect of all its

component forces. We take advantage of this by simply adding together all the forces

applied to an object, and then only calculating its acceleration once, based on the

resulting total.

The same principle applies to torques: the effect of a whole series of torques is

equal to the effect of a single torque that combines them all. We have

τ

=

τ
i

i

where
τ
i
is the
i
th torque.

There is a complication, however. We saw earlier in the chapter that an off-center

force can be converted into torques. To get the correct set of forces and torques we

need to take into account this calculation.

Another consequence of D'Alembert's principle is that we can accumulate the

torques caused by forces in exactly the same way as we accumulate any other torques.

Note that we
cannot
merely accumulate the forces and then take the torque equiva-

lent of the resulting force. We could have two forces (like the finger and thumb on

a volume dial) that cancel each other out as linear forces but combine to generate a

large torque.

So we have two accumulators: one for forces and another for torques. Each force

applied is added to both the force and torque accumulator, where its torque is calcu-

lated by