
7.4 Collision-Like Things 141
virtual unsigned addContact(ParticleContact *contact,
unsigned limit) const;
};
Excerpt from file src/plinks.cpp
unsigned ParticleRod::addContact(ParticleContact *contact,
unsigned limit) const
{
// Find the length of the rod.
real currentLen = currentLength();
// Check if 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]->getPosition();
normal.normalize();
// The contact normal depends on whether we’re extending or
compressing.
if (currentLen ...