Game Development Reference
In-Depth Information
{
if(c[i].body[1]==c[index].body[0])
{
cp = rotationChange[0].vectorProduct(c[i].
relativeContactPosition[1]);
cp += velocityChange[0];
c[i].penetration +=
rotationAmount[0]*cp.scalarProduct(c[i].
contactNormal);
}
else if(c[i].body[1]==c[index].body[1])
{
cp = rotationChange[1].vectorProduct(c[i].
relativeContactPosition[1]);
cp += velocityChange[1];
c[i].penetration +=
rotationAmount[1]*cp.scalarProduct(c[i].
contactNormal);
}
}
}
positionIterationsUsed++;
}
}
14.4.4
R ESOLVING V ELOCITY
With penetration resolved we can turn our attention to velocity. This is where differ-
ent physics engines vary the most, with several different but excellent strategies for
resolving velocity. We'll return to some of them in chapter 18.
For this chapter I have aimed for the simplest end of the spectrum: a velocity reso-
lution system that works and is stable, is as fast as possible, but avoids the complexity
of simultaneously resolving multiple collisions. The algorithm is almost identical to
the one for penetration resolution.
The algorithm runs in iterations. At each iteration it finds the collision with the
greatest closing velocity. If there is no collision with a closing velocity, then the al-
gorithm can terminate. If there is a collision, then it is resolved in isolation, using
the method we saw in the first three sections of the chapter. Other contacts are then
Search Nedrilad ::




Custom Search