I've written some code to get a rigid rod to bounce on the 'floor'. I have used Eberly's wild magic 4 code, which seems to match what bullet does too (I may have a one year old version of bullet though).
I find that when the object is a cube (l=w=h) and bouncing with its base parallel to the ground it does the right thing. However if I vary the dimensions - to make it more rod like, while keeping it flat as before.. things go wrong - it bounces either too much or too little (this is easy to check because I make restitution = 1 and bounce a ball - which keeps bouncing back upto the same height from which it is dropped). Please could somebody tell me what is wrong?
Here is my code:
for (int i = 0; i < numContacts; i++) {
Vector3f normal = box->contactNormal;
Vector3f relativeA = box->contactPosition - box->getPositionOfCentreOfMass();
Vector3f deltaTorqueA = relativeA.Cross(normal);
Vector3f deltaAngularVelocityA = box->getInverseInertiaTensorWorld() * deltaTorqueA;
float numerator = -(box->getAngularVelocity().Dot(deltaTorqueA)) - normal.Dot(box->getVelocity());
numerator *= -(currentContact->restitution_ + 1.0f);
float denominator = bodyA->getInverseMass() + deltaTorqueA.Dot(deltaAngularVelocityA);
impulseMagnitude = numerator/denominator;
if (impulseMagnitude != 0.0f) {
Vector3f impulse = impulseMagnitude * normal;
box->addVelocity(-impulse * box->getInverseMass());
box->addWorkingAngularVelocity(-(box->getInverseInertiaTensorWorld()*relativeA.Cross(impulse)));
}
}