Game Development Reference
gines that do very sophisticated velocity resolution, with all collisions handled at the
same time, often have a separate penetration resolver that uses the algorithms we im-
The collision resolver we implement in this chapter is set in a class: CollisionRe-
solver . It has a method, resolveContacts , that takes the whole set of collisions and
the duration of the frame, and it performs the resolution in three steps: first it cal-
culates internal data for each contact; then it passes the contacts to the penetration
resolver; and then they go to the velocity resolver:
Excerpt from include/cyclone/contacts.h
* The contact resolution routine. One resolver instance
* can be shared for the whole simulation, as long as you need
* roughly the same parameters each time (which is normal).
* Resolves a set of contacts for both penetration and velocity.
void resolveContacts(Contact *contactArray,
Excerpt from src/contacts.cpp
void ContactResolver::resolveContacts(Contact *contacts,
// Make sure we have something to do.
if (numContacts == 0) return;
// Prepare the contacts for processing
prepareContacts(contacts, numContacts, duration);
// Resolve the interpenetration problems with the contacts.
adjustPositions(contacts, numContacts, duration);
// Resolve the velocity problems with the contacts.
adjustVelocities(contacts, numContacts, duration);