Game Development Reference
In-Depth Information
// result by -1.
Matrix3 velocityPerUnitImpulse =
rotationPerUnitImpulse * impulseToTorque;
velocityPerUnitImpulse *= -1;
// Finally convert the result into contact coordinates.
Matrix3 velocityPerUnitImpulseContact =
contactToWorld.transpose() * velocityPerUnitImpulse;
The resulting matrix, velocityPerUnitImpulseContact , can be used to transform
an impulse in contact coordinates into a velocity in contact coordinates. This is ex-
actly what we need for this stage of the algorithm.
In practice there may be two objects involved in the contact. We can follow the
same process through each time and combine the results. The most efficient way to
do this is to notice that only the impulseToTorque and inverseInertiaTensor matrices
will change for each body. The contactToWorld matrices are the same in each case. We
can therefore separate them out and multiply them after the two objects have been
processed independently. The code looks like this:
Excerpt from src/contacts.cpp
// The equivalent of a cross product in matrices is multiplication
// by a skew symmetric matrix - we build the matrix for converting
// between linear and angular quantities.
Matrix3 impulseToTorque;
// Build the matrix to convert contact impulse to change in velocity
// in world coordinates.
Matrix3 deltaVelWorld = impulseToTorque;
deltaVelWorld *= inverseInertiaTensor[0];
deltaVelWorld *= impulseToTorque;
deltaVelWorld *= -1;
// Check if we need to add body two's data
if (body[1])
// Find the inertia tensor for this body.
// Set the cross product matrix.
// Calculate the velocity change matrix.
Matrix3 deltaVelWorld2 = impulseToTorque;
Search Nedrilad ::

Custom Search