NVIDIA-Omniverse / PhysX

NVIDIA PhysX SDK
BSD 3-Clause "New" or "Revised" License
2.54k stars 361 forks source link

added leapfrog integration #311

Open paulsinnett opened 1 month ago

paulsinnett commented 1 month ago

Leapfrog integration applies half of the first acceleration update to velocity on the first frame after waking. After that, the updates proceed as usual with the full acceleration applied each frame. This corrects for impulses which otherwise have too much of the first frame's acceleration applied to them and lose mechincal energy as a result.

This fixes issue #308

I have also included some tests here: https://github.com/LSBUGPG/PhysXJump/tree/test-without-leapfrog-integration https://github.com/LSBUGPG/PhysXJump/tree/test-leapfrog-integration

Leapfrog integration is implemented by setting PxsRigidBody::mAccelScale to 0.5 when a body is first woken up (or added to a scene with an initial velocity) in Sc::Scene::onBodyWakeUp. It then resets this scale back to 1.0 after integration for all active bodies in Sc::Scene::afterIntegration. PxsRigidBody::mAccelScale is already used when applying the acceleration from the built in gravity. I've also modified BodySim::updateForces to use this value when manually applying gravity (or any other acceleration.)