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) -> usize
pub fn insert_collider(&mut self, collider: C, index: I) -> usize
Inserts a new collider and returns its index. An object index needs to be specified.
Sourcepub fn replace_collider(&mut self, index: usize, collider: C)
pub fn replace_collider(&mut self, index: usize, collider: C)
Replaces the existing collider at the specified index by a new collider.
Sourcepub fn remove_collider(&mut self, index: usize)
pub fn remove_collider(&mut self, index: usize)
Removes an existing collider, so the index is usable for a new collider again.
Sourcepub fn collider_mut(&mut self, index: usize) -> &mut C
pub fn collider_mut(&mut self, index: usize) -> &mut C
Get the collider at the specified index 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<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions( &self, ) -> HashMap<usize, 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<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_collisions_with( &self, other: &Self, ) -> HashMap<usize, 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<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions_spatial( &self, ) -> HashMap<usize, 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).
Sourcepub fn compute_collisions_with_spatial(
&self,
other: &Self,
) -> HashMap<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_collisions_with_spatial( &self, other: &Self, ) -> HashMap<usize, 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).
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<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>
pub fn compute_inner_collisions_bvh<V: BoundingVolume>( &self, ) -> HashMap<usize, 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.
Sourcepub fn compute_collisions_with_bvh<V: BoundingVolume>(
&self,
other: &Self,
) -> HashMap<usize, Vec<IndexedCollisionInfo<C::Vector, I>>>where
C: Bounded<V>,
pub fn compute_collisions_with_bvh<V: BoundingVolume>(
&self,
other: &Self,
) -> HashMap<usize, 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.