summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-07-21 16:49:24 +0200
committerGitHub <noreply@github.com>2020-07-21 16:49:24 +0200
commit01fb1f189fe71f2768db7231b2523197228a8b54 (patch)
tree653e4219adc14c7841d3146b39ec8080e0bea8f7
parent103b46733ac4f53259575a528a1f6a3be034f227 (diff)
parenta91103ac89ba2fb9ec5fb82ab24bc3a171dcb640 (diff)
Merge pull request #40512 from yrk06/ExposeInertiaTensorMaster
Add Method get_inverse_inertia_tensor
-rw-r--r--doc/classes/RigidBody3D.xml7
-rw-r--r--scene/3d/physics_body_3d.cpp7
-rw-r--r--scene/3d/physics_body_3d.h3
3 files changed, 17 insertions, 0 deletions
diff --git a/doc/classes/RigidBody3D.xml b/doc/classes/RigidBody3D.xml
index efd55f5566..370e6bd19c 100644
--- a/doc/classes/RigidBody3D.xml
+++ b/doc/classes/RigidBody3D.xml
@@ -100,6 +100,13 @@
[b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
</description>
</method>
+ <method name="get_inverse_inertia_tensor">
+ <return type="Basis">
+ </return>
+ <description>
+ Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the [RigidBody3D].
+ </description>
+ </method>
<method name="set_axis_lock">
<return type="void">
</return>
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 72ae75b236..fc021e5532 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -358,6 +358,7 @@ void RigidBody3D::_direct_state_changed(Object *p_state) {
set_global_transform(state->get_transform());
linear_velocity = state->get_linear_velocity();
angular_velocity = state->get_angular_velocity();
+ inverse_inertia_tensor = state->get_inverse_inertia_tensor();
if (sleeping != state->is_sleeping()) {
sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
@@ -594,6 +595,10 @@ Vector3 RigidBody3D::get_angular_velocity() const {
return angular_velocity;
}
+Basis RigidBody3D::get_inverse_inertia_tensor() {
+ return inverse_inertia_tensor;
+}
+
void RigidBody3D::set_use_custom_integrator(bool p_enable) {
if (custom_integrator == p_enable) {
return;
@@ -760,6 +765,8 @@ void RigidBody3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody3D::set_angular_velocity);
ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody3D::get_angular_velocity);
+ ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &RigidBody3D::get_inverse_inertia_tensor);
+
ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody3D::set_gravity_scale);
ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody3D::get_gravity_scale);
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index 413b587fc4..9830a55183 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -123,6 +123,7 @@ protected:
Vector3 linear_velocity;
Vector3 angular_velocity;
+ Basis inverse_inertia_tensor;
real_t gravity_scale;
real_t linear_damp;
real_t angular_damp;
@@ -201,6 +202,8 @@ public:
void set_angular_velocity(const Vector3 &p_velocity);
Vector3 get_angular_velocity() const override;
+ Basis get_inverse_inertia_tensor();
+
void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const;