diff options
| author | Sébastien Crozet <developer@crozet.re> | 2023-01-01 18:47:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-01 18:47:48 +0100 |
| commit | 8456bf148bd7c28c6f745064c532d08f0b1100ac (patch) | |
| tree | 13990746bb753eb48d87c85e6de42fbc399726db | |
| parent | d482205f02138b8105557d09d315190b7b09a938 (diff) | |
| parent | 424d01747bba9861e213bb562b139d0992d0f14b (diff) | |
| download | rapier-8456bf148bd7c28c6f745064c532d08f0b1100ac.tar.gz rapier-8456bf148bd7c28c6f745064c532d08f0b1100ac.tar.bz2 rapier-8456bf148bd7c28c6f745064c532d08f0b1100ac.zip | |
Merge pull request #429 from fabriceci/add-methods-retrieves-forces-and-torques
Adds methods to retrieve forces added by the user.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | src/dynamics/rigid_body.rs | 22 |
2 files changed, 24 insertions, 0 deletions
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 diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index bb1e9bf..78132b2 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -938,6 +938,28 @@ 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. + /// + /// Returns zero if the rigid-body isn’t dynamic. + pub fn user_force(&self) -> Vector<Real> { + if self.body_type == RigidBodyType::Dynamic { + self.forces.user_force + } else { + 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<Real> { + if self.body_type == RigidBodyType::Dynamic { + self.forces.user_torque + } else { + AngVector::zero() + } + } } impl RigidBody { |
