Game Development Reference
In-Depth Information
where q rel is the position of the point we are interested in, relative to the object's center
of mass; p is the position of the object's center of mass (i.e.,
p is the linear velocity of
the whole object); and θ is the object's angular velocity.
To calculate the velocity in contact coordinates we use this equation and then
transform the result by the transpose of the contact basis matrix:
Excerpt from src/contacts.cpp
Vector3 Contact::calculateLocalVelocity(unsigned bodyIndex, real duration)
RigidBody *thisBody = body[bodyIndex];
// Work out the velocity of the contact point.
Vector3 velocity =
thisBody->getRotation() % relativeContactPosition[bodyIndex];
velocity += thisBody->getVelocity();
// Turn the velocity into contact coordinates
Vector3 contactVelocity = contactToWorld.transformTranspose(velocity);
// And return it.
return contactVelocity;
The calculateInternals method finds the overall closing velocity at the contact
point, by subtracting the second body's closing velocity from the first:
// Find the relative velocity of the bodies at the contact point.
contactVelocity = calculateLocalVelocity(0, duration);
if (body[1]) {
contactVelocity -= calculateLocalVelocity(1, duration);
Because this algorithm uses both the contact basis matrix and the relative contact
positions, it must be done last.
We have visited each contact and calculated the data we'll need for both resolution
steps. We now turn our attention to resolving the interpenetration for all contacts.
We will do this by taking each contact in turn and calling a method ( applyPosition-
Change ) that contains the algorithm in section 14.3 for resolving a single contact.
We could simply do this in the same way as for prepareContacts :
Search Nedrilad ::

Custom Search