aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/rigid_body.rs
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-02-24 13:26:51 +0100
committerCrozet Sébastien <developer@crozet.re>2021-02-24 13:26:51 +0100
commit96ecb877e290ad15459258a415aca64ca4af3a69 (patch)
treeead6af02da8c021841dfe3f7ba5fa75e8339a12d /src/dynamics/rigid_body.rs
parent3cc2738e5fdcb0d25818b550cdff93eab75f1b20 (diff)
downloadrapier-96ecb877e290ad15459258a415aca64ca4af3a69.tar.gz
rapier-96ecb877e290ad15459258a415aca64ca4af3a69.tar.bz2
rapier-96ecb877e290ad15459258a415aca64ca4af3a69.zip
Implement dominance.
Diffstat (limited to 'src/dynamics/rigid_body.rs')
-rw-r--r--src/dynamics/rigid_body.rs25
1 files changed, 25 insertions, 0 deletions
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();