aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/rigid_body.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-11-19 16:05:46 +0100
committerSébastien Crozet <developer@crozet.re>2022-12-11 15:20:33 +0100
commit46d976d97bc9334004a58a19bc9cab3ea78e9569 (patch)
tree0437f81f4c7882c89aafa685b2822b8c3e462b3c /src/dynamics/rigid_body.rs
parentc600549aacbde1361eba862b34a23f63d806d6a9 (diff)
downloadrapier-46d976d97bc9334004a58a19bc9cab3ea78e9569.tar.gz
rapier-46d976d97bc9334004a58a19bc9cab3ea78e9569.tar.bz2
rapier-46d976d97bc9334004a58a19bc9cab3ea78e9569.zip
Allow disabling colliders, rigid-bodies and impulse joints
Diffstat (limited to 'src/dynamics/rigid_body.rs')
-rw-r--r--src/dynamics/rigid_body.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs
index 9c38eee..a6384b7 100644
--- a/src/dynamics/rigid_body.rs
+++ b/src/dynamics/rigid_body.rs
@@ -35,6 +35,7 @@ pub struct RigidBody {
pub(crate) body_type: RigidBodyType,
/// The dominance group this rigid-body is part of.
pub(crate) dominance: RigidBodyDominance,
+ pub(crate) enabled: bool,
/// User-defined data associated to this rigid-body.
pub user_data: u128,
}
@@ -61,6 +62,7 @@ impl RigidBody {
changes: RigidBodyChanges::all(),
body_type: RigidBodyType::Dynamic,
dominance: RigidBodyDominance::default(),
+ enabled: true,
user_data: 0,
}
}
@@ -81,6 +83,28 @@ impl RigidBody {
&mut self.activation
}
+ /// Is this rigid-body enabled?
+ pub fn is_enabled(&self) -> bool {
+ self.enabled
+ }
+
+ /// Sets whether this rigid-body is enabled or not.
+ pub fn set_enabled(&mut self, enabled: bool) {
+ if enabled != self.enabled {
+ if enabled {
+ // NOTE: this is probably overkill, but it makes sure we don’t
+ // forget anything that needs to be updated because the rigid-body
+ // was basically interpreted as if it was removed while it was
+ // disabled.
+ self.changes = RigidBodyChanges::all();
+ } else {
+ self.changes |= RigidBodyChanges::ENABLED_OR_DISABLED;
+ }
+
+ self.enabled = enabled;
+ }
+ }
+
/// The linear damping coefficient of this rigid-body.
#[inline]
pub fn linear_damping(&self) -> Real {
@@ -963,6 +987,8 @@ pub struct RigidBodyBuilder {
pub ccd_enabled: bool,
/// The dominance group of the rigid-body to be built.
pub dominance_group: i8,
+ /// Will the rigid-body being built be enabled?
+ pub enabled: bool,
/// An arbitrary user-defined 128-bit integer associated to the rigid-bodies built by this builder.
pub user_data: u128,
}
@@ -984,6 +1010,7 @@ impl RigidBodyBuilder {
sleeping: false,
ccd_enabled: false,
dominance_group: 0,
+ enabled: true,
user_data: 0,
}
}
@@ -1230,6 +1257,12 @@ impl RigidBodyBuilder {
self
}
+ /// Enable or disable the rigid-body after its creation.
+ pub fn enabled(mut self, enabled: bool) -> Self {
+ self.enabled = enabled;
+ self
+ }
+
/// Build a new rigid-body with the parameters configured with this builder.
pub fn build(&self) -> RigidBody {
let mut rb = RigidBody::new();
@@ -1252,6 +1285,7 @@ impl RigidBodyBuilder {
rb.damping.angular_damping = self.angular_damping;
rb.forces.gravity_scale = self.gravity_scale;
rb.dominance = RigidBodyDominance(self.dominance_group);
+ rb.enabled = self.enabled;
rb.enable_ccd(self.ccd_enabled);
if self.can_sleep && self.sleeping {