Game Development Reference
In-Depth Information
To combine the linear motion with the angular motion we already have, we need
only add the inverse mass to the diagonal entries of the matrix:
deltaVelocity.data[0] += inverseMass;
deltaVelocity.data[4] += inverseMass;
deltaVelocity.data[8] += inverseMass;
15.4.3
P UTTING I T A LL T OGETHER
We are now ready to put together all the modifications we need to support isotropic
friction. These modifications are only made to the applyVelocityChange method of
the contact: they are all handled as a micro-collision. The final code looks like this:
Excerpt from src/contacts.cpp
real inverseMass = body[0]->getInverseMass();
// 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;
impulseToTorque.setSkewSymmetric(relativeContactPosition[0]);
// 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 whether we need to add body 2's data.
if (body[1])
{
// Find the inertia tensor for this body.
body[1]->getInverseInertiaTensorWorld(&inverseInertiaTensor[1]);
// Set the cross product matrix.
impulseToTorque.setSkewSymmetric(relativeContactPosition[1]);
// Calculate the velocity change matrix.
Matrix3 deltaVelWorld2 = impulseToTorque;
deltaVelWorld2 *= inverseInertiaTensor[1];
deltaVelWorld2 *= impulseToTorque;
deltaVelWorld2 *= -1;
Search Nedrilad ::




Custom Search