diff options
| author | Sébastien Crozet <sebcrozet@dimforge.com> | 2022-05-31 11:23:46 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebcrozet@dimforge.com> | 2022-05-31 11:23:46 +0200 |
| commit | 8b3c091ba785d5cba049015c213eb49bb6378762 (patch) | |
| tree | f235c408372aaea9dd4007838e3c51044d310daf /src/geometry | |
| parent | 31cfce4db30efeb15ccb8c51e6c20ff07406987c (diff) | |
| download | rapier-disabled-flag.tar.gz rapier-disabled-flag.tar.bz2 rapier-disabled-flag.zip | |
Start experimenting with collider/rigid-body disabling.disabled-flag
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/collider.rs | 21 | ||||
| -rw-r--r-- | src/geometry/collider_components.rs | 9 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 8d9b005..d12f7b2 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -46,6 +46,17 @@ impl Collider { self.coll_type.is_sensor() } + /// Is this collider enabled? + pub fn is_enabled(&self) -> bool { + self.flags.enabled + } + + /// Sets whether or not this collider is enabled. + pub fn set_enabled(&mut self, enabled: bool) { + self.changes.insert(ColliderChanges::ENABLED); + self.flags.enabled = enabled; + } + /// The physics hooks enabled for this collider. pub fn active_hooks(&self) -> ActiveHooks { self.flags.active_hooks @@ -309,6 +320,8 @@ pub struct ColliderBuilder { pub position: Isometry<Real>, /// Is this collider a sensor? pub is_sensor: bool, + /// Is this collider enabled after its creation? + pub enabled: bool, /// Contact pairs enabled for this collider. pub active_collision_types: ActiveCollisionTypes, /// Physics hooks enabled for this collider. @@ -334,6 +347,7 @@ impl ColliderBuilder { restitution: 0.0, position: Isometry::identity(), is_sensor: false, + enabled: true, user_data: 0, collision_groups: InteractionGroups::all(), solver_groups: InteractionGroups::all(), @@ -594,6 +608,12 @@ impl ColliderBuilder { self } + /// Is this collider enabled after its creation? + pub fn enabled(mut self, is_enabled: bool) -> Self { + self.enabled = is_enabled; + self + } + /// Sets the collision groups used by this collider. /// /// Two colliders will interact iff. their collision groups are compatible. @@ -775,6 +795,7 @@ impl ColliderBuilder { active_collision_types: self.active_collision_types, active_hooks: self.active_hooks, active_events: self.active_events, + enabled: self.enabled, }; let changes = ColliderChanges::all(); let pos = ColliderPosition(self.position); diff --git a/src/geometry/collider_components.rs b/src/geometry/collider_components.rs index 22f75e7..ab746a4 100644 --- a/src/geometry/collider_components.rs +++ b/src/geometry/collider_components.rs @@ -57,11 +57,13 @@ bitflags::bitflags! { const SHAPE = 1 << 4; // => BF & NF update. NF pair workspace invalidation. /// Flag indicating that the `ColliderType` component of the collider has been modified. const TYPE = 1 << 5; // => NF update. NF pair invalidation. + /// Flag indicating that this `Collider` or its parent `RigidBody` enabled status was changed. + const ENABLED = 1 << 6; // => NF update. /// Flag indicating that the dominance groups of the parent of this collider have been modified. /// /// This flags is automatically set by the `PhysicsPipeline` when the `RigidBodyChanges::DOMINANCE` /// or `RigidBodyChanges::TYPE` of the parent rigid-body of this collider is detected. - const PARENT_EFFECTIVE_DOMINANCE = 1 << 6; // NF update. + const PARENT_EFFECTIVE_DOMINANCE = 1 << 7; // NF update. } } @@ -309,7 +311,7 @@ impl ActiveCollisionTypes { // First, we associate the following bit masks: // - DYNAMIC = 0001 // - FIXED = 0010 - // - KINEMATIC = 1100 + // - KINEMATIC = 0011 // These are equal to the bits indexed by `RigidBodyType as u32`. // The bit masks defined by ActiveCollisionTypes are defined is such a way // that the first part of the variant name (e.g. DYNAMIC_*) indicates which @@ -368,6 +370,8 @@ pub struct ColliderFlags { pub active_hooks: ActiveHooks, /// The events enabled for this collider. pub active_events: ActiveEvents, + /// Whether the collider takes part into the simulation or should be igonred. + pub enabled: bool, } impl Default for ColliderFlags { @@ -378,6 +382,7 @@ impl Default for ColliderFlags { solver_groups: InteractionGroups::all(), active_hooks: ActiveHooks::empty(), active_events: ActiveEvents::empty(), + enabled: true, } } } |
