Game Development Reference
In-Depth Information
unsigned ParticleCable::fillContact(ParticleContact *contact,
unsigned limit) const
// Find the length of the cable.
real length = currentLength();
// Check whether we're overextended.
if (length < maxLength)
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]
contact->contactNormal = normal;
contact->penetration = length-maxLength;
contact->restitution = restitution;
return 1;
This code acts as a collision detector: it examines the current state of the cable and can
return a contact if the cable has reached its limit. This contact should then be added to
all the others generated by the collision detector and processed in the normal contact
resolver algorithm.
Rods combine the behaviors of cables and collisions. Two objects linked by a rod can
neither separate nor get closer together. They are kept at a fixed distance apart.
We can implement this in the same way as the cable contact generator. At each
frame we look at the current state of the rod and generate either a contact to bring
the ends inward or a contact to keep them apart.
We need to make two modifications to what we've seen so far, however. First we
should always use a zero coefficient of restitution. It doesn't make sense for the two
ends to bounce either together or apart. They should be kept at a constant distance
from each other, so their relative velocity along the line between them should be zero.
Search Nedrilad ::

Custom Search