Game Development Reference
In-Depth Information
// Check whether we're overextended.
if (currentLen == length)
return 0;
// Otherwise return the contact.
contact->particle[0] = particle[0];
contact->particle[1] = particle[1];
// Calculate the normal.
Vector3 normal = particle[1]->getPosition() - particle[0]
// The contact normal depends on whether we're extending
// or compressing.
if (currentLen > length) {
contact->contactNormal = normal;
contact->penetration = currentLen - length;
} else {
contact->contactNormal = normal * -1;
contact->penetration = length - currentLen;
// Always use zero restitution (no bounciness).
contact->restitution = 0;
return 1;
The code always generates two contacts, which should be added to the list returned
by the collision detector and passed to the contact resolver.
We've now built a set of physics code that can connect particles together using both
hard constraints, such as rods and cables, and elastic constraints, such as springs and
Rods and cables behave similarly to collisions between separate objects. Cables
can cause the particles joined together to bounce toward one another, just in the same
way that particles bounce off one another when they collide. In the same way rods
Search Nedrilad ::

Custom Search