Game Development Reference
In-Depth Information
the first body's point of view. So the calculated impulse will be correct for the first
body. The second body should receive the impulse in the opposite direction.
We can use the same code we used for the second body, but first we need to change
the sign of the impulse.
// Calculate velocity and rotation change for object one.
// ...
impulse *= -1;
// Calculate velocity and rotation change for object two.
// ...
Finally, the velocity and rotation changes calculated for each object can be directly
applied to the velocity and angular velocity of the rigid body. For example:
body->velocity += velocityChange;
body->rotation += rotationChange;
14.3
R ESOLVING I NTERPENETRATION
We have covered the procedure for representing the change in velocity when a colli-
sion happens. If the objects in our simulation were truly solid, this would be all that
is needed.
Unfortunately the objects can pass into one another before we detect that a colli-
sion has occurred. The simulation proceeds in time steps, during which no checking
takes place. By the end of a time step when collision detection occurs, two objects can
have touched and passed into one another. We need to resolve this interpenetration
in some way; otherwise objects in the game will not appear solid.
This is the same set of requirements we saw in the mass-aggregate engine. In that
case, when two objects were interpenetrating, it was quite easy to move them apart.
We moved each object back along the line of the contact normal to the first point
where they no longer intersected.
14.3.1
C HOOSING A R ESOLUTION M ETHOD
For rotating rigid bodies the situation is a little more complex. There are several
strategies we could employ to resolve interpenetration.