Implement dominance.

This commit is contained in:
Crozet Sébastien
2021-02-24 13:26:51 +01:00
parent 3cc2738e5f
commit 96ecb877e2
11 changed files with 42 additions and 10 deletions

View File

@@ -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();