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

Fix center of mass and inertia computations and add tests #127

Merged
merged 7 commits into from
Aug 19, 2023

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Aug 19, 2023

Previously, the combined center of mass of a body and its collider was computed as com1 + com2, but this doesn't take into account different masses. The combined inertia was also computed as inertia1 + inertia2 without taking into account mass or the center of mass, i.e. the offset.

This PR fixes the center of mass issue by computing it correctly like (com1 * mass1 + com2 * mass2) / (mass1 + mass2), and the inertia issue by first shifting the inertia values by the relative center of mass. Subtracting mass properties is handled similarly, but by simply using - instead of + in many places. These fixes will be very important especially when we implement child colliders.

I also added tests to verify that the mass and center of mass are correct after adding or subtracting mass properties. I didn't add tests for inertia yet (other than checking that self + other - other = self) as the calculations seem quite daunting to do by hand, so I'm not 100% sure if it's correct still. This can be verified later.

@Jondolf Jondolf added C-Testing Improvements or additions to testing bugfix labels Aug 19, 2023
@Jondolf Jondolf merged commit ac7f693 into main Aug 19, 2023
3 checks passed
@Jondolf Jondolf deleted the mass-prop-fixes branch August 19, 2023 16:58
@Jondolf Jondolf added C-Bug Something isn't working A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on and removed bugfix labels Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Bug Something isn't working C-Testing Improvements or additions to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant