pub struct CollisionManager<C: Collider, I> { /* private fields */ }Expand description
The collision manager, which manages collisions. Can contain multiple colliders.
Implementations§
Source§impl<C: Collider, I: Copy> CollisionManager<C, I>
impl<C: Collider, I: Copy> CollisionManager<C, I>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new collision manager with the capacity of expected colliders specified.
Sourcepub fn insert_collider(&mut self, collider: C, index: I) -> ColliderId
pub fn insert_collider(&mut self, collider: C, index: I) -> ColliderId
Inserts a new collider and returns its ColliderId.
An object index needs to be specified.
Sourcepub fn replace_collider(&mut self, id: ColliderId, collider: C)
pub fn replace_collider(&mut self, id: ColliderId, collider: C)
Replaces the existing collider at the specified id by a new collider.
Sourcepub fn remove_collider(&mut self, id: ColliderId)
pub fn remove_collider(&mut self, id: ColliderId)
Removes an existing collider, so the id is usable for a new collider again.
Sourcepub fn collider(&self, id: ColliderId) -> &C
pub fn collider(&self, id: ColliderId) -> &C
Get the collider at the specified id.
Sourcepub fn collider_mut(&mut self, id: ColliderId) -> &mut C
pub fn collider_mut(&mut self, id: ColliderId) -> &mut C
Get the collider at the specified id as mutable.
Sourcepub fn check_collision(&self, check_collider: &C) -> bool
pub fn check_collision(&self, check_collider: &C) -> bool
Checks if there is a collision at a specific position.
Sourcepub fn find_collision(&self, check_collider: &C) -> Option<I>
pub fn find_collision(&self, check_collider: &C) -> Option<I>
Checks for a collision with collider and returns some index if found.
Sourcepub fn find_collisions<'a>(
&'a self,
check_collider: &'a C,
) -> impl DoubleEndedIterator<Item = I> + 'a
pub fn find_collisions<'a>( &'a self, check_collider: &'a C, ) -> impl DoubleEndedIterator<Item = I> + 'a
Finds all collisions with colliders and returns their indices.
Sourcepub fn compute_inner_collisions(
&self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
Computes the internal collisions between all colliders. Returns a map for each collider index to its collision infos.
Sourcepub fn compute_collisions_with(
&self,
other: &Self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_collisions_with( &self, other: &Self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
Computes the collisions between all colliders with the colliders of another collision manager. Returns a map for each collider index to its collision infos.
Source§impl<C: Collider + SpatialPartition, I: Copy> CollisionManager<C, I>
impl<C: Collider + SpatialPartition, I: Copy> CollisionManager<C, I>
Sourcepub fn compute_inner_collisions_spatial(
&self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions_spatial( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
Computes internal collisions using spatial partitioning. Only checks pairs that share at least one cell, reducing O(n²) to O(n×k).
The cell map is rebuilt from scratch on every call, so this is best suited to layers whose colliders move between calls. For a static layer queried repeatedly, building the acceleration structure once would be cheaper, but that is not yet provided.
Sourcepub fn compute_collisions_with_spatial(
&self,
other: &Self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_collisions_with_spatial( &self, other: &Self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
Computes collisions with another manager using spatial partitioning. Only checks pairs that share at least one cell, reducing O(n²) to O(n×k).
The other manager’s cell map is rebuilt on every call. When the same static layer is queried repeatedly, building its acceleration structure once would be cheaper, but that is not yet provided.
Source§impl<C: Collider, I: Copy> CollisionManager<C, I>
impl<C: Collider, I: Copy> CollisionManager<C, I>
Sourcepub fn compute_inner_collisions_bvh<V: BoundingVolume>(
&self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions_bvh<V: BoundingVolume>( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
Computes internal collisions using a bounding volume hierarchy.
Skips pairs whose bounding volumes don’t overlap, reducing O(n²) to O(n log n).
The type parameter V selects which bounding volume to use.
The BVH is rebuilt on every call, so this fits layers whose colliders move between calls. For a static layer queried repeatedly, building the BVH once would be cheaper, but that is not yet provided.
Sourcepub fn compute_collisions_with_bvh<V: BoundingVolume>(
&self,
other: &Self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>where
C: Bounded<V>,
pub fn compute_collisions_with_bvh<V: BoundingVolume>(
&self,
other: &Self,
) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>where
C: Bounded<V>,
Computes collisions with another manager using bounding volume hierarchies.
Builds a BVH for each manager and traverses them together,
skipping subtree pairs whose volumes don’t overlap.
The type parameter V selects which bounding volume to use.
Both BVHs are rebuilt on every call. When the same static layer is queried repeatedly, building its BVH once would be cheaper, but that is not yet provided.