Allow disabling colliders, rigid-bodies and impulse joints
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user