diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-01-16 07:52:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-16 07:52:19 -0800 |
| commit | 4454a845e98b990abf3929ca46b59d0fca5a18ec (patch) | |
| tree | e4808725e872b7178ba81c3ac5475be3a04569ac /src/dynamics/rigid_body.rs | |
| parent | 0ccd15c4b1f57d6c85a1727a55ed991c835690f5 (diff) | |
| parent | 8213e92f146fab618a406e0f8fed8a15ebd9228c (diff) | |
| download | rapier-4454a845e98b990abf3929ca46b59d0fca5a18ec.tar.gz rapier-4454a845e98b990abf3929ca46b59d0fca5a18ec.tar.bz2 rapier-4454a845e98b990abf3929ca46b59d0fca5a18ec.zip | |
Merge pull request #276 from dimforge/lock-translation-axis
Allow locking individual translational axes
Diffstat (limited to 'src/dynamics/rigid_body.rs')
| -rw-r--r-- | src/dynamics/rigid_body.rs | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 0b41981..e5dcd04 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -195,7 +195,48 @@ impl RigidBody { } } + #[inline] + /// Locks or unlocks rotations of this rigid-body along each cartesian axes. + pub fn restrict_translations( + &mut self, + allow_translation_x: bool, + allow_translation_y: bool, + #[cfg(feature = "dim3")] allow_translation_z: bool, + wake_up: bool, + ) { + if self.is_dynamic() { + if wake_up { + self.wake_up(true); + } + + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_X, + !allow_translation_x, + ); + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_Y, + !allow_translation_y, + ); + #[cfg(feature = "dim3")] + self.rb_mprops.flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_Z, + !allow_translation_z, + ); + self.update_world_mass_properties(); + } + } + + /// Are the translations of this rigid-body locked? + #[cfg(feature = "dim2")] + pub fn is_translation_locked(&self) -> bool { + self.rb_mprops.flags.contains( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_X + | RigidBodyMassPropsFlags::TRANSLATION_LOCKED_Y, + ) + } + /// Are the translations of this rigid-body locked? + #[cfg(feature = "dim3")] pub fn is_translation_locked(&self) -> bool { self.rb_mprops .flags @@ -633,7 +674,7 @@ impl RigidBody { /// This does nothing on non-dynamic bodies. pub fn apply_impulse(&mut self, impulse: Vector<Real>, wake_up: bool) { if self.rb_type == RigidBodyType::Dynamic { - self.rb_vels.linvel += impulse * self.rb_mprops.effective_inv_mass; + self.rb_vels.linvel += impulse.component_mul(&self.rb_mprops.effective_inv_mass); if wake_up { self.wake_up(true); @@ -847,6 +888,29 @@ impl RigidBodyBuilder { self } + /// Only allow translations of this rigid-body around specific coordinate axes. + pub fn restrict_translations( + mut self, + allow_translations_x: bool, + allow_translations_y: bool, + #[cfg(feature = "dim3")] allow_translations_z: bool, + ) -> Self { + self.mprops_flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_X, + !allow_translations_x, + ); + self.mprops_flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_Y, + !allow_translations_y, + ); + #[cfg(feature = "dim3")] + self.mprops_flags.set( + RigidBodyMassPropsFlags::TRANSLATION_LOCKED_Z, + !allow_translations_z, + ); + self + } + /// Prevents this rigid-body from rotating because of forces. pub fn lock_rotations(mut self) -> Self { self.mprops_flags |
