From 95cd7d5c9c73574cde1d07774b3d0969cda6833e Mon Sep 17 00:00:00 2001 From: fabriceci Date: Wed, 21 Dec 2022 21:34:06 +0100 Subject: Adds methods to retrieve forces added by the user. --- src/dynamics/rigid_body.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index bb1e9bf..f9ea519 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -938,6 +938,22 @@ impl RigidBody { self.apply_impulse(impulse, wake_up); self.apply_torque_impulse(torque_impulse, wake_up); } + + /// Retrieves the constant force(s) that the user has added to the body. + pub fn user_force(&self) -> Vector { + if self.body_type == RigidBodyType::Dynamic { + return self.forces.user_force; + } + Vector::zeros() + } + + /// Retrieves the constant torque(s) that the user has added to the body. + pub fn user_torque(&self) -> AngVector { + if self.body_type == RigidBodyType::Dynamic { + return self.forces.user_torque; + } + AngVector::zero() + } } impl RigidBody { -- cgit From c77ed7c9bf9f39149364df2c9dd9041a0a4cf6fa Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 1 Jan 2023 16:51:40 +0100 Subject: Small coding style fix --- src/dynamics/rigid_body.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index f9ea519..78132b2 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -940,19 +940,25 @@ impl RigidBody { } /// Retrieves the constant force(s) that the user has added to the body. + /// + /// Returns zero if the rigid-body isn’t dynamic. pub fn user_force(&self) -> Vector { if self.body_type == RigidBodyType::Dynamic { - return self.forces.user_force; + self.forces.user_force + } else { + Vector::zeros() } - Vector::zeros() } /// Retrieves the constant torque(s) that the user has added to the body. + /// + /// Returns zero if the rigid-body isn’t dynamic. pub fn user_torque(&self) -> AngVector { if self.body_type == RigidBodyType::Dynamic { - return self.forces.user_torque; + self.forces.user_torque + } else { + AngVector::zero() } - AngVector::zero() } } -- cgit From 424d01747bba9861e213bb562b139d0992d0f14b Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 1 Jan 2023 16:52:47 +0100 Subject: Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72c99a1..e2a0acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Disabling a multibody joint isn’t supported yet. - Add `DynamicRayCastVehicleController`, a vehicle controller based on ray-casting and dynamic rigid-bodies (mostly a port of the vehicle controller from Bullet physics). +- Add `RigidBody::user_force` and `RigidBody::user_torque` to read the forces or torques added by the user to a + dynamic rigid-body. ### Modified - Add the `QueryPipeline` as an optional argument to `PhysicsPipeline::step` and `CollisionPipeline::step`. If this -- cgit