-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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 Rigid Body Method "get_inverse_inertia_tensor" #39817
Conversation
Also, pull requests should be opened against the |
I tried to make the change using the Master branch, but I couldn't get the engine to run on my local computer. That's why I decided to go with the 3.2 version |
scene/3d/physics_body.cpp
Outdated
@@ -765,6 +766,10 @@ Vector3 RigidBody::get_angular_velocity() const { | |||
return angular_velocity; | |||
} | |||
|
|||
Basis RigidBody::get_inertia_tensor() { | |||
return inverse_inertia_tensor.inverse(); |
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.
The inverse of the inertia tensor is used for two reasons:
- For convenience: To calculate the rotational acceleration, we need to multiply the torque by the inverse of the inertia tensor.
- For
StaticBodies
: The inertia tensor needs to be infinite, which is not possible. However the inverse is zero, which is possible.
Inverting the zeroed inertial tensor of a StaticBody
, or a RigidBody
in Static
mode, would result in division by zero.
In short, don't invert the inverse of the inertia tensor. If you want to provide access to the inertia tensor, return the inverse instead.
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.
I see, thanks for pointing out. I didn't know that. I knew only about the convenience for calculations, but in order to calculate torque, the not-inversed is needed, thus the function was to get the not-inversed. I'll change that and commit it
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.
Looks good, aside from my nitpick below, the commits just need to be squashed into a single commit.
</return> | ||
<description> | ||
Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration made from a certain torque on the RigidBody. | ||
</description> |
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.
Nitpicking, but I think this would read better if it didn't include the word "certain" i.e. something like:
This is used to calculate the angular acceleration resulting from a torque applied to the RigidBody.
6681fef
to
952b04a
Compare
952b04a
to
0cd43cb
Compare
I force pushed the commit again in order to change the method name in the commit from |
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.
I'm was just looking at that. This should have been created as a property with a getter and a setter.
I didn't do it because the idea was just exposing using the already existent function on class I Haven't looked yet on how the engine calculates the Inertia Tensor, but my guess is that it would require a new function inside the Bullet Physics Classes in order to Overwrite it with a Setter |
Okay, let's leave it as it is then. One more change, please update the commit message, which still has all the individual commit messages to just the first commit message. Also, commit messages should be written in the present tense; so 'Add Rigid Body Method "get_inverse_inertia_tensor"'. Finally, please create a second PR against the master branch referencing this one. If you've thoroughly tested it on the 3.2 branch, you should be confident that it will work on the master branch without being able to run a test project. |
0cd43cb
to
d09b165
Compare
Thanks! |
Exposed inertia tensor to GDScript
How
This was done by creating a variable on the rigidbody class. The variable receives the inverse inertia tensor value each time the RigidBody state gets changed, then the
get_inverse_inertia_tensor()
returns the the inverse_inertia_tensor. The method is exposed to GDScript withbind_method
Consequences
As a consequence of this, rotations with rigid bodies can be controlled more accurately through the use of Physics Formulas of Torque
Requests
This was proposed in: godotengine/godot-proposals#1114 also in #2125 and kind of related to godotengine/godot-proposals#945