Game Development Reference
In-Depth Information
c[i].penetration -= rotationAmount[0]*cp.scalarProduct(
If the second object has changed, the code is similar, but the value is added at the end:
cp = rotationChange[1].vectorProduct(
cp += velocityChange[1];
c[i].penetration += rotationAmount[1]*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,
unsigned numContacts,
real duration)
unsigned i,index;
Vector3 velocityChange[2], rotationChange[2];
real rotationAmount[2];
real max;
Vector3 cp;
// Iteratively resolve interpenetration in order of severity.
positionIterationsUsed = 0;
while(positionIterationsUsed < positionIterations)
// Find biggest penetration.
max = positionEpsilon;
index = numContacts;
for(i=0;i<numContacts;i++) {
if(c[i].penetration > max)
Search Nedrilad ::

Custom Search