Allow disabling colliders, rigid-bodies and impulse joints

This commit is contained in:
Sébastien Crozet
2022-11-19 16:05:46 +01:00
parent c600549aac
commit 46d976d97b
15 changed files with 408 additions and 107 deletions

View File

@@ -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 wasnt 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;