PhysX tip: max angular velocity
In PhysX, the angular velocity of dynamic bodies is limited and clamped to a user-defined “max angular velocity”. But the default value for it is a bit peculiar.
It’s 7.
Not 5 or 10 or 100. Just 7.
Why 7? Why not 8 or something else? This goes back all the way to NovodeX 2.0 and the story behind this specific value is not clear to me anymore. If I remember correctly it had to do with the lack of angular CCD (Continuous Collision Detection) in NovodeX: clamping the angular velocity to some low value seemed like a cheap way to prevent angular CCD issues. Or so we thought. It probably looked like a good idea at the time, but of course in retrospect, it wasn’t. Because this value is way too low - and no, I don’t remember why we picked “7″ in particular.
If you create a test scene for gyroscopic effects, like the one in this video, that default value prevents the objects from rotating, and you don’t get the expected behavior. Somehow this looks just as bad as CCD issues.
However, and fortunately, it is easy to change. For each body, call PxRigidDynamic::setMaxAngularVelocity() with a new, higher velocity limit (I used “100″ in the video). And suddenly the objects keep spinning and the scene works as expected. Problem solved!
For some reason we never updated that value. From NovodeX 2.0 to PhysX 3.4, the default max angular velocity is 7. I suppose we don’t modify it because we want to make sure that nothing breaks or changes in unexpected ways for users upgrading to a new version - as much as possible at least. We can be a bit paranoid and extreme about that kind of stuff. Do. Not. Break. People’s. Working. Code. (*)
(*) yeah I know, it didn’t always work out
EDIT: the default max angular velocity has finally been increased to 100 in PhysX 4.0.
April 21st, 2017 at 6:57 pm
It’s possible 7 was chosen to avoid a hard cap that might sea-saw above and below 50% object rotation per-frame on low end devices (as vsync might flip back and forth between clamping to 30 or 15 fps). Anything that caps the rendering of the rotation to just above 50% per frame is probably very undesirable as the object will appear to be rotating the wrong way.