aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint/generic_joint.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/joint/generic_joint.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/joint/generic_joint.rs')
-rw-r--r--src/dynamics/joint/generic_joint.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/dynamics/joint/generic_joint.rs b/src/dynamics/joint/generic_joint.rs
index bb1598d..4f0a791 100644
--- a/src/dynamics/joint/generic_joint.rs
+++ b/src/dynamics/joint/generic_joint.rs
@@ -5,6 +5,7 @@ use crate::utils::{WBasis, WReal};
#[cfg(feature = "dim3")]
use crate::dynamics::SphericalJoint;
+use crate::geometry::ColliderEnabled;
#[cfg(feature = "dim3")]
bitflags::bitflags! {
@@ -182,6 +183,19 @@ impl JointMotor {
}
}
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
+#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+/// Enum indicating whether or not a joint is enabled.
+pub enum JointEnabled {
+ /// The joint is enabled.
+ Enabled,
+ /// The joint wasn’t disabled by the user explicitly but it is attached to
+ /// a disabled rigid-body.
+ DisabledByAttachedBody,
+ /// The joint is disabled by the user explicitly.
+ Disabled,
+}
+
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
/// A generic joint.
@@ -208,6 +222,8 @@ pub struct GenericJoint {
pub motors: [JointMotor; SPATIAL_DIM],
/// Are contacts between the attached rigid-bodies enabled?
pub contacts_enabled: bool,
+ /// Whether or not the joint is enabled.
+ pub enabled: JointEnabled,
}
impl Default for GenericJoint {
@@ -222,6 +238,7 @@ impl Default for GenericJoint {
limits: [JointLimits::default(); SPATIAL_DIM],
motors: [JointMotor::default(); SPATIAL_DIM],
contacts_enabled: true,
+ enabled: JointEnabled::Enabled,
}
}
}
@@ -260,6 +277,27 @@ impl GenericJoint {
}
}
+ /// Is this joint enabled?
+ pub fn is_enabled(&self) -> bool {
+ self.enabled == JointEnabled::Enabled
+ }
+
+ /// Set whether this joint is enabled or not.
+ pub fn set_enabled(&mut self, enabled: bool) {
+ match self.enabled {
+ JointEnabled::Enabled | JointEnabled::DisabledByAttachedBody => {
+ if !enabled {
+ self.enabled = JointEnabled::Disabled;
+ }
+ }
+ JointEnabled::Disabled => {
+ if enabled {
+ self.enabled = JointEnabled::Enabled;
+ }
+ }
+ }
+ }
+
/// Add the specified axes to the set of axes locked by this joint.
pub fn lock_axes(&mut self, axes: JointAxesMask) -> &mut Self {
self.locked_axes |= axes;