From 7153eb7779a29853289df90f28efaac738620386 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 1 Jun 2021 17:59:07 +0200 Subject: Add ActiveCollisionTypes to easily enable collision-detection between two non-static rigid-body. --- src/pipeline/collision_pipeline.rs | 6 ++---- src/pipeline/event_handler.rs | 6 +++--- src/pipeline/physics_pipeline.rs | 9 +++----- src/pipeline/query_pipeline.rs | 42 +++++++++++++++++++------------------- 4 files changed, 29 insertions(+), 34 deletions(-) (limited to 'src/pipeline') diff --git a/src/pipeline/collision_pipeline.rs b/src/pipeline/collision_pipeline.rs index e4ea157..d789da7 100644 --- a/src/pipeline/collision_pipeline.rs +++ b/src/pipeline/collision_pipeline.rs @@ -7,8 +7,8 @@ use crate::dynamics::{ }; use crate::geometry::{ BroadPhase, BroadPhasePairEvent, ColliderBroadPhaseData, ColliderChanges, ColliderFlags, - ColliderGroups, ColliderHandle, ColliderMaterial, ColliderPair, ColliderParent, - ColliderPosition, ColliderShape, ColliderType, NarrowPhase, + ColliderHandle, ColliderMaterial, ColliderPair, ColliderParent, ColliderPosition, + ColliderShape, ColliderType, NarrowPhase, }; use crate::math::Real; use crate::pipeline::{EventHandler, PhysicsHooks}; @@ -65,7 +65,6 @@ impl CollisionPipeline { + ComponentSet + ComponentSetOption + ComponentSet - + ComponentSet + ComponentSet + ComponentSet, { @@ -173,7 +172,6 @@ impl CollisionPipeline { + ComponentSet + ComponentSetOption + ComponentSet - + ComponentSet + ComponentSet + ComponentSet, { diff --git a/src/pipeline/event_handler.rs b/src/pipeline/event_handler.rs index 4ee5387..c54acc2 100644 --- a/src/pipeline/event_handler.rs +++ b/src/pipeline/event_handler.rs @@ -3,11 +3,11 @@ use crossbeam::channel::Sender; bitflags::bitflags! { #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. + /// Flags affecting the events generated for this collider. pub struct ActiveEvents: u32 { - /// If set, Rapier will call `PhysicsHooks::FILTER_CONTACT_PAIRS` whenever relevant. + /// If set, Rapier will call `EventHandler::handle_intersection_event` whenever relevant for this collider. const INTERSECTION_EVENTS = 0b0001; - /// If set, Rapier will call `PhysicsHooks::filter_intersection_pair` whenever relevant. + /// If set, Rapier will call `PhysicsHooks::handle_contact_event` whenever relevant for this collider. const CONTACT_EVENTS = 0b0010; } } diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index f5d9b27..987ca25 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -14,8 +14,8 @@ use crate::dynamics::{ use crate::dynamics::{JointGraphEdge, ParallelIslandSolver as IslandSolver}; use crate::geometry::{ BroadPhase, BroadPhasePairEvent, ColliderBroadPhaseData, ColliderChanges, ColliderFlags, - ColliderGroups, ColliderHandle, ColliderMaterial, ColliderPair, ColliderParent, - ColliderPosition, ColliderShape, ColliderType, ContactManifoldIndex, NarrowPhase, + ColliderHandle, ColliderMaterial, ColliderPair, ColliderParent, ColliderPosition, + ColliderShape, ColliderType, ContactManifoldIndex, NarrowPhase, }; use crate::math::{Real, Vector}; use crate::pipeline::{EventHandler, PhysicsHooks}; @@ -103,7 +103,6 @@ impl PhysicsPipeline { + ComponentSet + ComponentSetOption + ComponentSet - + ComponentSet + ComponentSet + ComponentSet, { @@ -367,8 +366,7 @@ impl PhysicsPipeline { + ComponentSet + ComponentSet + ComponentSet - + ComponentSet - + ComponentSet, + + ComponentSet, { self.counters.ccd.toi_computation_time.start(); // Handle CCD @@ -547,7 +545,6 @@ impl PhysicsPipeline { + ComponentSet + ComponentSetOption + ComponentSet - + ComponentSet + ComponentSet + ComponentSet, { diff --git a/src/pipeline/query_pipeline.rs b/src/pipeline/query_pipeline.rs index 31bf3a4..733d767 100644 --- a/src/pipeline/query_pipeline.rs +++ b/src/pipeline/query_pipeline.rs @@ -4,7 +4,7 @@ use crate::dynamics::{ RigidBodyVelocity, }; use crate::geometry::{ - ColliderGroups, ColliderHandle, ColliderParent, ColliderPosition, ColliderShape, + ColliderFlags, ColliderHandle, ColliderParent, ColliderPosition, ColliderShape, InteractionGroups, PointProjection, Ray, RayIntersection, AABB, QBVH, }; use crate::math::{Isometry, Point, Real, Vector}; @@ -67,7 +67,7 @@ impl<'a, Colliders> TypedSimdCompositeShape for QueryPipelineAsCompositeShape<'a where // TODO ECS: make everything optional but the shape? Colliders: - ComponentSet + ComponentSet + ComponentSet, + ComponentSet + ComponentSet + ComponentSet, { type PartShape = dyn Shape; type PartId = ColliderHandle; @@ -77,10 +77,10 @@ where shape_id: Self::PartId, mut f: impl FnMut(Option<&Isometry>, &Self::PartShape), ) { - let co_groups: Option<&ColliderGroups> = self.colliders.get(shape_id.0); + let co_flags: Option<&ColliderFlags> = self.colliders.get(shape_id.0); - if let Some(co_groups) = co_groups { - if co_groups.collision_groups.test(self.query_groups) + if let Some(co_flags) = co_flags { + if co_flags.collision_groups.test(self.query_groups) && self.filter.map(|f| f(shape_id)).unwrap_or(true) { let (co_pos, co_shape): (&ColliderPosition, &ColliderShape) = @@ -384,7 +384,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, Real)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -420,7 +420,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, RayIntersection)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -463,16 +463,16 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, mut callback: impl FnMut(ColliderHandle, RayIntersection) -> bool, ) where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { let mut leaf_callback = &mut |handle: &ColliderHandle| { let co_shape: Option<&ColliderShape> = colliders.get(handle.0); if let Some(co_shape) = co_shape { - let (co_groups, co_pos): (&ColliderGroups, &ColliderPosition) = + let (co_flags, co_pos): (&ColliderFlags, &ColliderPosition) = colliders.index_bundle(handle.0); - if co_groups.collision_groups.test(query_groups) + if co_flags.collision_groups.test(query_groups) && filter.map(|f| f(*handle)).unwrap_or(true) { if let Some(hit) = co_shape.cast_ray_and_get_normal(co_pos, ray, max_toi, solid) @@ -509,7 +509,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -550,7 +550,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, PointProjection)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -583,7 +583,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, mut callback: impl FnMut(ColliderHandle) -> bool, ) where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -591,10 +591,10 @@ impl QueryPipeline { let co_shape: Option<&ColliderShape> = colliders.get(handle.0); if let Some(co_shape) = co_shape { - let (co_groups, co_pos): (&ColliderGroups, &ColliderPosition) = + let (co_flags, co_pos): (&ColliderFlags, &ColliderPosition) = colliders.index_bundle(handle.0); - if co_groups.collision_groups.test(query_groups) + if co_flags.collision_groups.test(query_groups) && filter.map(|f| f(*handle)).unwrap_or(true) && co_shape.contains_point(co_pos, point) { @@ -635,7 +635,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, PointProjection, FeatureId)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -685,7 +685,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, TOI)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -733,7 +733,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, ) -> Option<(ColliderHandle, TOI)> where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -774,7 +774,7 @@ impl QueryPipeline { filter: Option<&dyn Fn(ColliderHandle) -> bool>, mut callback: impl FnMut(ColliderHandle) -> bool, ) where - Colliders: ComponentSet + Colliders: ComponentSet + ComponentSet + ComponentSet, { @@ -785,10 +785,10 @@ impl QueryPipeline { let co_shape: Option<&ColliderShape> = colliders.get(handle.0); if let Some(co_shape) = co_shape { - let (co_groups, co_pos): (&ColliderGroups, &ColliderPosition) = + let (co_flags, co_pos): (&ColliderFlags, &ColliderPosition) = colliders.index_bundle(handle.0); - if co_groups.collision_groups.test(query_groups) + if co_flags.collision_groups.test(query_groups) && filter.map(|f| f(*handle)).unwrap_or(true) { let pos12 = inv_shape_pos * co_pos.as_ref(); -- cgit