Game Development Reference

In-Depth Information

deltaVelWorld2 *= inverseInertiaTensor[1];

deltaVelWorld2 *= impulseToTorque;

deltaVelWorld2 *= -1;

// Add to the total delta velocity.

deltaVelWorld += deltaVelWorld2;

}

// Do a change of basis to convert into contact coordinates.

Matrix3 deltaVelocity = contactToWorld.transpose();

deltaVelocity *= deltaVelWorld;

deltaVelocity *= contactToWorld;

where the same matrix is reused for intermediate stages of the calculation, as in chap-

ter 14.

What we are effectively doing here is performing all the calculations in world

coordinates (i.e., we end up with a matrix that transforms impulse into velocity, both

in world coordinates) for each body. Then we add the two results together, and then

change the basis of this matrix so that it transforms impulse into velocity in contact

coordinates. Recall from section 9.4.6 that we change the basis of a matrix by

BMB
−
1

where
B
is the basis matrix and
M
is the matrix being transformed. This is equivalent

to
BMB
when
B
is a rotation matrix only (as it is for the
contactToWorld
matrix).

Hence the last three lines of the code snippet.

Velocity from Linear Motion

So far we only have the change in velocity caused by rotation. We also need to include

the change in linear velocity from the impulse. As before, this is simply given by the

inverse mass:

m
−
1
g

˙

p

=

This again is a transformation from a vector (impulse) into another vector (veloc-

ity). Because we are trying to end up with one matrix combining linear and angular

components of velocity, it would be useful to express inverse mass as a matrix so that

it can be added to the angular matrix we already have.

This can be done simply. Multiplying a vector by a scalar quantity
k
is equivalent

to transforming it by the matrix

⎡

⎤

k
00

0
k
0

00
k

⎣

⎦

You can manually check this by trying a vector multiplication.