Merge pull request #39817 from yrk06/ExposeInertiaTensor

Added Rigid Body Method "get_inverse_inertia_tensor"
This commit is contained in:
Rémi Verschelde 2020-07-21 16:50:56 +02:00 committed by GitHub
commit 7b4b83e9dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -120,6 +120,13 @@
Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
</description> </description>
</method> </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 RigidBody.
</description>
</method>
</methods> </methods>
<members> <members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0"> <member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0">

View File

@ -453,6 +453,7 @@ void RigidBody::_direct_state_changed(Object *p_state) {
set_global_transform(state->get_transform()); set_global_transform(state->get_transform());
linear_velocity = state->get_linear_velocity(); linear_velocity = state->get_linear_velocity();
angular_velocity = state->get_angular_velocity(); angular_velocity = state->get_angular_velocity();
inverse_inertia_tensor = state->get_inverse_inertia_tensor();
if (sleeping != state->is_sleeping()) { if (sleeping != state->is_sleeping()) {
sleeping = state->is_sleeping(); sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
@ -765,6 +766,10 @@ Vector3 RigidBody::get_angular_velocity() const {
return angular_velocity; return angular_velocity;
} }
Basis RigidBody::get_inverse_inertia_tensor() {
return inverse_inertia_tensor;
}
void RigidBody::set_use_custom_integrator(bool p_enable) { void RigidBody::set_use_custom_integrator(bool p_enable) {
if (custom_integrator == p_enable) if (custom_integrator == p_enable)
@ -956,6 +961,8 @@ void RigidBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody::set_angular_velocity); ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody::set_angular_velocity);
ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody::get_angular_velocity); ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody::get_angular_velocity);
ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &RigidBody::get_inverse_inertia_tensor);
ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody::set_gravity_scale); ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody::set_gravity_scale);
ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody::get_gravity_scale); ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody::get_gravity_scale);

View File

@ -135,6 +135,7 @@ protected:
Vector3 linear_velocity; Vector3 linear_velocity;
Vector3 angular_velocity; Vector3 angular_velocity;
Basis inverse_inertia_tensor;
real_t gravity_scale; real_t gravity_scale;
real_t linear_damp; real_t linear_damp;
real_t angular_damp; real_t angular_damp;
@ -224,6 +225,8 @@ public:
void set_angular_velocity(const Vector3 &p_velocity); void set_angular_velocity(const Vector3 &p_velocity);
Vector3 get_angular_velocity() const; Vector3 get_angular_velocity() const;
Basis get_inverse_inertia_tensor();
void set_gravity_scale(real_t p_gravity_scale); void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const; real_t get_gravity_scale() const;