-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Fixed inertia tensor computation and center of mass #7426
Conversation
Ah I see, I did not really think about it, but it makes sense that the
center of mass will be offset by the shapes..
will give it a good check asap and merge. Also some users requested the
ability to set custom center of mass offset in RigidBody in order to make
ragdolls better, do you think this could be added?
…On Tue, Jan 3, 2017 at 4:28 PM, m4nu3lf ***@***.***> wrote:
Issues fixed:
-
To compute the distribution of mass of a rigid body the AABB was used
for collision shapes for which the area (volume) is trivial to compute. Now
the exact area is computed for those shapes as the AABB can have a pretty
different volume if the shape is in an arbitrary orientation.
-
The inertia tensor was not computed correctly because the orientation
of the object w.r.t. the rigid body origin was not taken into account
-
The vector of inertia only makes sense in the "Principal Axes of
Inertia" frame of reference that isn't always equal to the rigid body frame
of reference and which has to be computed through diagonalization of the
tensor of inertia ( The Jacobi method has been implemented to diagonalize a
symmetric matrix, it is the same used by Bullet ).
https://en.wikipedia.org/wiki/Moment_of_inertia#Principal_axes
-
The vector of inertia/inertia tensor only makes sense if computed
w.r.t the rotation center i.e. the center of mass for a free rigid body,
which has to be computed. The center of mass returned by the new
*get_center_of_mass()* method is in global orientation with position
relative to the rigid body position.
NOTE: the slider joint dosn't work but it seems not to be related to these
changes as it wasn't working even without
Here is a test project with some test scenes that can be run before and
after my changes to see the difference https://www.dropbox.com/sh/
y44l0surabi56rb/AADpJjVHtJsv4IKwCaZnUISga?dl=0
------------------------------
You can view, comment on, or merge this pull request online at:
#7426
Commit Summary
- Fixed inertia tensor computation and center of mass
File Changes
- *M* core/math/matrix3.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-0> (74)
- *M* core/math/matrix3.h
<https://github.com/godotengine/godot/pull/7426/files#diff-1> (67)
- *M* core/math/quat.h
<https://github.com/godotengine/godot/pull/7426/files#diff-2> (4)
- *M* core/math/vector3.h
<https://github.com/godotengine/godot/pull/7426/files#diff-3> (20)
- *M* core/variant_call.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-4> (5)
- *M* doc/base/classes.xml
<https://github.com/godotengine/godot/pull/7426/files#diff-5> (38)
- *M* scene/3d/vehicle_body.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-6> (2)
- *M* servers/physics/body_pair_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-7> (24)
- *M* servers/physics/body_pair_sw.h
<https://github.com/godotengine/godot/pull/7426/files#diff-8> (2)
- *M* servers/physics/body_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-9> (71)
- *M* servers/physics/body_sw.h
<https://github.com/godotengine/godot/pull/7426/files#diff-10> (37)
- *M* servers/physics/collision_object_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-11> (2)
- *M* servers/physics/collision_object_sw.h
<https://github.com/godotengine/godot/pull/7426/files#diff-12> (2)
- *M* servers/physics/joints/cone_twist_joint_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-13> (8)
- *M* servers/physics/joints/generic_6dof_joint_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-14> (14)
- *M* servers/physics/joints/hinge_joint_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-15> (20)
- *M* servers/physics/joints/pin_joint_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-16> (8)
- *M* servers/physics/joints/slider_joint_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-17> (12)
- *M* servers/physics/physics_server_sw.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-18> (9)
- *M* servers/physics/physics_server_sw.h
<https://github.com/godotengine/godot/pull/7426/files#diff-19> (1)
- *M* servers/physics/shape_sw.h
<https://github.com/godotengine/godot/pull/7426/files#diff-20> (9)
- *M* servers/physics_server.cpp
<https://github.com/godotengine/godot/pull/7426/files#diff-21> (10)
- *M* servers/physics_server.h
<https://github.com/godotengine/godot/pull/7426/files#diff-22> (4)
Patch Links:
- https://github.com/godotengine/godot/pull/7426.patch
- https://github.com/godotengine/godot/pull/7426.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#7426>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z21grjtLtZlmHskqpiaLn22QmyCKiks5rOqFlgaJpZM4LZ8S1>
.
|
@reduz I'm not really sure how the custom center of mass would interact with the rest of the simulation, I have no real knowledge on why this is needed for ragdolls. Adding the method is trivial though |
I think @SaracenOne made a PR that was not merged for this functionality. Do you remember why it was needed to set custom center of mass? |
I don't see any corrections to the inertia tensor in #4912 |
@reduz I spent a fair amount of time trying to get ragdolls to work, and as far as I could tell, overriding the center of mass was the only way to make them anything resembling accurate. Unity has similar technique of allowing you to override centor of mass which is likewise used in ragdoll creation. The only other issue I encountered was discovering that the existing physics system wasn't truly deterministic, in that objects would often fall differently at random, but my meager understanding of physics is nowhere near good enough to understand why it works that way. That said, initial PR I did should be fine, though I'll likely have to update it to account for the recent changes. |
Hold on, let me see if I can upload a ragdoll example I have... |
@SaracenOne Yep, It would be much appreciated :) I guess we can have the same. Plus a flag like "use_custom_center_of_mass" and "use_custom_inertia" and "use_custom_principal_axes" to avoid the engine to recompute them automatically if the collider are changed change |
@m4nu3lf I've got an example ready along with an updated PR (though not quite synced to the latest due to compatibility breakage). It shows how a ragdoll can be constructed using this method, along with what I think are the optimal settings for sleep thresholds. For comparison, observe how this simulation breaks without overriding the centre of mass. The initial PR contains methods for auto-calculating the centre of mass, but I've included a GDScript addon which provides a simple tool to actually do it, though I've been meaning to provide this functionality natively too. Control over the centre of mass should also make it possible to construct single rigid bodies out of multiple collision primitives. I'll see if there's more that can be done with this tomorrow. |
Better example with an actual mesh. Shows how to map bones to ragdoll rigids. |
_inv_inertia=_inertia.inverse(); | ||
else | ||
_inv_inertia=Vector3(); | ||
if (Math::abs(inertia_tensor.determinant()) > CMP_EPSILON) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This make no sense, the determinant should be allowed to be smaller and we can allow it to be zero as we are computing the inverse through a simple transpose. Will fix asap
@SaracenOne @reduz Fixed a bug, now the ragdoll example provided works |
@@ -22,7 +22,7 @@ | |||
<description> | |||
Make a color from red, green, blue and alpha. Arguments can range from 0 to 255. | |||
</description> | |||
</method> | |||
</method>/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whops
No idea why the build fails on Windows and Mac, I didn't change anything in platform/windows/joypad.cpp what is going on? |
if you are working on master/head, everything is being broken and destroyed
ATM (we are breaking compatibility violently)
…On Sun, Jan 8, 2017 at 9:35 PM, m4nu3lf ***@***.***> wrote:
No idea why the build fails on Windows and Mac, I didn't change anything
in platform/windows/joypad.cpp what is going on?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7426 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z21p1cCyE56QImMhmXfcybGy6eo1Eks5rQYDUgaJpZM4LZ8S1>
.
|
But it worked before I updated the PR with the bugfix, and I didn't merge from master again. Does Travis merge before running the build? |
Yes. |
Issues fixed:
To compute the distribution of mass of a rigid body the AABB was used for collision shapes for which the area (volume) is trivial to compute. Now the exact area is computed for those shapes as the AABB can have a pretty different volume if the shape is in an arbitrary orientation.
The inertia tensor was not computed correctly because the orientation of the object w.r.t. the rigid body origin was not taken into account
The vector of inertia only makes sense in the "Principal Axes of Inertia" frame of reference that isn't always equal to the rigid body frame of reference and which has to be computed through diagonalization of the tensor of inertia ( The Jacobi method has been implemented to diagonalize a symmetric matrix, it is the same used by Bullet ).
https://en.wikipedia.org/wiki/Moment_of_inertia#Principal_axes
The vector of inertia/inertia tensor only makes sense if computed w.r.t the rotation center i.e. the center of mass for a free rigid body, which has to be computed. The center of mass returned by the new get_center_of_mass() method is in global orientation with position relative to the rigid body position.
NOTE: the slider joint dosn't work but it seems not to be related to these changes as it wasn't working even without
Here is a test project with some test scenes that can be run before and after my changes to see the difference https://www.dropbox.com/sh/y44l0surabi56rb/AADpJjVHtJsv4IKwCaZnUISga?dl=0