Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added leapfrog integration #311

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

paulsinnett
Copy link

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.)

leapfrog integration applies half of the first acceleration update to velocity on the first frame of waking. After that, the updates proceed as usual. This corrects impulses and makes them work as expected rather than losing 5% of the energy after the first frame.
@paulsinnett
Copy link
Author

Brought this PR up to date with 5.4.2 and also the test projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant