Game Development Reference
which is implemented as
Excerpt from src/contacts.cpp
// Convert impulse to world coordinates.
Vector3 impulse = contactToWorld.transform(impulseContact);
With the impulse calculated in world coordinates we can go ahead and apply it to
the objects in the collision.
A PPLYING THE I MPULSE
To apply the impulse, we use equations 7.5 and 14.1. The first tells us that linear
impulses change the linear velocity of the object according to the formula
So the velocity change for the first object in the collision will be
Vector3 velocityChange = impulse * body->getInverseMass();
I − 1 u
We first need to calculate the impulsive torque, u , using equation 14.2 again:
q rel ×
In code this looks like
Vector3 impulsiveTorque = impulse % relativeContactPosition;
Vector3 rotationChange =
These calculations work for the first object in the collision but not for the second,
if there is one. To apply the impulse to the second object, we first need to make an
observation. We have calculated a single value for the impulse, but there may be two
objects involved in the collision.
Just as in chapter 7, both objects involved in a collision will receive the same sized
impulse, but in opposite directions. And as we saw in chapter 2, changing the direc-
tion of a vector to its opposite is equivalent to changing the sign of all its components.
We have worked so far using the contact normal as it was generated by the colli-
sion detector. By convention the collision detector generates a contact normal from