Game Development Reference
In-Depth Information
{
// Particle 1 goes in the opposite direction.
particle[1]->setVelocity(particle[1]->getVelocity() +
impulsePerIMass * -particle[1]->getInverseMass()
);
}
}
To keep two objects in resting contact we are applying a small change in velocity at
each frame. The change is just big enough to correct the increase in velocity that
would arise from their settling into each other over the course of one frame.
Other Approaches to Resting Contact
The micro-collision approach I described above is only one of many possibilities.
Resting contact is one of two key challenges to get right in a physics engine (the other
being friction: in fact the two often go together). There are many routes of attack as
well as countless variations and tweaks.
My solution is somewhat ad hoc. Effectively we second-guess the mistakes of a
rough implementation and then try to correct it after the event. This has the flavor of
a hack, and despite being easy to implement and suitable for adding in friction (which
we'll do in chapter 15), it is frowned on by engineering purists.
A more physically realistic approach would be to recognize that in reality a force
would be applied on the particle from the ground. This reaction force pushes the
object back so that its total acceleration in the vertical direction becomes zero. No
matter how hard the particle pushes down, the ground will push up with the same
force. We can create a force generator that works in this way, making sure there can
be no acceleration into the ground.
This works okay for particles that can have only one contact with the ground.
For more complex rigid bodies the situation becomes considerably more complex.
We may have several points of contact between an object and the ground (or worse,
we might have a whole series of contacts between an object and immovable resting
points). It isn't immediately clear how to calculate the reaction forces at each contact
so that the overall motion of the object is correct. We'll return to reaction forces in
some depth in chapter 15, and to more complex resolution methods in chapter 18.
7.3
T HE C ONTACT R ESOLVER A LGORITHM
The collision resolver receives a list of contacts from the collision detection system
and needs to update the objects being simulated to take account of the contacts. We
have three bits of code for performing this update:
1. The collision resolution function that applies impulses to objects to simulate their
bouncing apart.
Search Nedrilad ::




Custom Search