Game Development Reference
In-Depth Information
// Add to the total delta velocity.
deltaVelWorld += deltaVelWorld2;
// Add to the inverse mass.
inverseMass += body[1]->getInverseMass();
}
// Do a change of basis to convert into contact coordinates.
Matrix3 deltaVelocity = contactToWorld.transpose();
deltaVelocity *= deltaVelWorld;
deltaVelocity *= contactToWorld;
// Add in the linear velocity change.
deltaVelocity.data[0] += inverseMass;
deltaVelocity.data[4] += inverseMass;
deltaVelocity.data[8] += inverseMass;
// Invert to get the impulse needed per unit velocity.
Matrix3 impulseMatrix = deltaVelocity.inverse();
// Find the target velocities to kill.
Vector3 velKill(desiredDeltaVelocity,
-contactVelocity.y,
-contactVelocity.z);
// Find the impulse to kill target velocities.
impulseContact = impulseMatrix.transform(velKill);
// Check for exceeding friction.
real planarImpulse = real_sqrt(impulseContact.y*impulseContact.y +
impulseContact.z*impulseContact.z);
if (planarImpulse > impulseContact.x * friction)
{
// We need to use dynamic friction.
impulseContact.y /= planarImpulse;
impulseContact.z /= planarImpulse;
impulseContact.x = deltaVelocity.data[0] +
deltaVelocity.data[1] * friction * impulseContact.y +
deltaVelocity.data[2] * friction * impulseContact.z;
impulseContact.x = desiredDeltaVelocity / impulseContact.x;
impulseContact.y *= friction * impulseContact.x;
Search Nedrilad ::




Custom Search