From 96ecb877e290ad15459258a415aca64ca4af3a69 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Wed, 24 Feb 2021 13:26:51 +0100 Subject: Implement dominance. --- src/dynamics/rigid_body.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/dynamics/rigid_body.rs') diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 859beb2..32c0cca 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -92,6 +92,8 @@ pub struct RigidBody { pub(crate) changes: RigidBodyChanges, /// The status of the body, governing how it is affected by external forces. pub body_status: BodyStatus, + /// The dominance group this rigid-body is part of. + dominance_group: i8, /// User-defined data associated to this rigid-body. pub user_data: u128, } @@ -122,6 +124,7 @@ impl RigidBody { flags: RigidBodyFlags::empty(), changes: RigidBodyChanges::all(), body_status: BodyStatus::Dynamic, + dominance_group: 0, user_data: 0, } } @@ -159,6 +162,19 @@ impl RigidBody { &self.mass_properties } + /// The dominance group of this rigid-body. + /// + /// This method always returns `i8::MAX + 1` for non-dynamic + /// rigid-bodies. + #[inline] + pub fn effective_dominance_group(&self) -> i16 { + if self.is_dynamic() { + self.dominance_group as i16 + } else { + i8::MAX as i16 + 1 + } + } + /// Sets the rigid-body's mass properties. /// /// If `wake_up` is `true` then the rigid-body will be woken up if it was @@ -648,6 +664,7 @@ pub struct RigidBodyBuilder { mass_properties: MassProperties, can_sleep: bool, sleeping: bool, + dominance_group: i8, user_data: u128, } @@ -666,6 +683,7 @@ impl RigidBodyBuilder { mass_properties: MassProperties::zero(), can_sleep: true, sleeping: false, + dominance_group: 0, user_data: 0, } } @@ -691,6 +709,12 @@ impl RigidBodyBuilder { self } + /// Sets the dominance group of this rigid-body. + pub fn dominance_group(mut self, group: i8) -> Self { + self.dominance_group = group; + self + } + /// Sets the initial translation of the rigid-body to be created. #[cfg(feature = "dim2")] pub fn translation(mut self, x: Real, y: Real) -> Self { @@ -880,6 +904,7 @@ impl RigidBodyBuilder { rb.angular_damping = self.angular_damping; rb.gravity_scale = self.gravity_scale; rb.flags = self.flags; + rb.dominance_group = self.dominance_group; if self.can_sleep && self.sleeping { rb.sleep(); -- cgit