aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/rigid_body.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-01-09 22:15:36 +0100
committerSébastien Crozet <developer@crozet.re>2022-01-09 22:15:36 +0100
commitb631fe9193a2e769e5ca1c5c8c4ac9843da870ac (patch)
tree8682f0870149b8ef6f741dccf0a96e2a26966c8c /src/dynamics/rigid_body.rs
parent2bfceadf0672572a360af33cf4a78cb42488e684 (diff)
downloadrapier-b631fe9193a2e769e5ca1c5c8c4ac9843da870ac.tar.gz
rapier-b631fe9193a2e769e5ca1c5c8c4ac9843da870ac.tar.bz2
rapier-b631fe9193a2e769e5ca1c5c8c4ac9843da870ac.zip
Allow locking individual translational axes
Diffstat (limited to 'src/dynamics/rigid_body.rs')
-rw-r--r--src/dynamics/rigid_body.rs66
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