Game Development Reference
In-Depth Information
/**
* Creates a new contact resolver.
*/
ParticleContactResolver(unsigned iterations);
/**
* Sets the number of iterations that can be used.
*/
void setIterations(unsigned iterations);
/**
* Resolves a set of particle contacts for both penetration
* and velocity.
*/
void resolveContacts(ParticleContact *contactArray,
unsigned numContacts,
real duration);
};
Excerpt from src/pcontacts.cpp
void
ParticleContactResolver::resolveContacts(ParticleContact *contactArray,
unsigned numContacts,
real duration)
{
iterationsUsed = 0;
while(iterationsUsed < iterations)
{
// Find the contact with the largest closing velocity;
real max = 0;
unsigned maxIndex = numContacts;
for (unsigned i = 0; i < numContacts; i++)
{
real sepVel = contactArray[i].calculateSeparatingVelocity();
if (sepVel < max)
{
max = sepVel;
maxIndex = i;
}
}
// Resolve this contact.
contactArray[maxIndex].resolve(duration);
Search Nedrilad ::




Custom Search