Game Development Reference
c[i].penetration -= rotationAmount*cp.scalarProduct(
If the second object has changed, the code is similar, but the value is added at the end:
cp = rotationChange.vectorProduct(
cp += velocityChange;
c[i].penetration += rotationAmount*cp.scalarProduct(
Finally we need some mechanism for storing the adjustments made in the
applyPositionChange method for use in this update. The easiest method is to add
data members to the ContactResolver class.
The complete code puts these stages together: finding the worst penetration, re-
solving it, and then updating the remaining contacts. The full code looks like this:
Excerpt from src/contacts.cpp
void ContactResolver::adjustPositions(Contact *c,
Vector3 velocityChange, rotationChange;
// Iteratively resolve interpenetration in order of severity.
positionIterationsUsed = 0;
while(positionIterationsUsed < positionIterations)
// Find biggest penetration.
max = positionEpsilon;
index = numContacts;
if(c[i].penetration > max)