Not a full set. I wrapped the physics engine and collision shapes in an abstraction that only exports the behaviour I'm interested in, and it is this abstraction that has lua bindings. I wanted to cover my back in case I needed to change physics engines in the future.
I did play with lots of attributes, including both damping values. Thinking about it though, using damping should have helped, in particular setting a linear damping of 1 should have stopped the motion altogether. I looked at the source and noticed a few things:
In btRigidBody::applyDamping, we have:
Code: Select all
m_linearVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_linearDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
m_angularVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_angularDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
I'm not sure multiplying by the timestep is the correct thing to do here. I think it should be raised to the power of the timestep. Note when timeStep==1 the behaviour is the same, but for smaller timesteps, the quantitiy of damping still ranges from 0 to 1.
I'm currently doing this:
Code: Select all
m_linearVelocity *= powf(GEN_clamped(1.0 - m_linearDamping, 0.0, 1.0),timeStep);
m_angularVelocity *= powf(GEN_clamped(1.0 - m_angularDamping, 0.0, 1.0),timeStep);
Which is obviously not up to bullet's quality standards (shouldn't be powf, etc) but is the correct equation in my opinion.
Also, bullet only damps the velocity induced by forces applied to the rigid body. It does not damp velocity induced by penetrations. I'm not sure how to approach this, since applying the damping before and after collision detection would result in twice as much damping. Maybe applying the damping to only the extra velocity induced by the collisions? Or maybe reversing the damping, integrating the transforms, and then applying the damping again would work.
Anyway, with just the first change, I can damp the jenga bricks properly, but in order to have much effect I have to damp them a lot - so much that their behaviour becomes unrealistic. I cannot currently stop the explosion with damping, because the penetration impulses propogate up the stack and magnify because they are not damped. I can only damp the explosion itself. Perhaps if the penetration impulses were also damped then it would be possible to build a tall realistic stack.
Dropping the gravity to moon-levels also helps of course
As does a smaller time step.