Skip to main content

CollisionManager

Struct CollisionManager 

Source
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>

Source

pub fn new() -> Self

Creates a new collision manager.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new collision manager with the capacity of expected colliders specified.

Source

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.

Source

pub fn replace_collider(&mut self, id: ColliderId, collider: C)

Replaces the existing collider at the specified id by a new collider.

Source

pub fn remove_collider(&mut self, id: ColliderId)

Removes an existing collider, so the id is usable for a new collider again.

Source

pub fn collider(&self, id: ColliderId) -> &C

Get the collider at the specified id.

Source

pub fn collider_mut(&mut self, id: ColliderId) -> &mut C

Get the collider at the specified id as mutable.

Source

pub fn check_collision(&self, check_collider: &C) -> bool

Checks if there is a collision at a specific position.

Source

pub fn find_collision(&self, check_collider: &C) -> Option<I>

Checks for a collision with collider and returns some index if found.

Source

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.

Source

pub fn compute_inner_collisions( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
where C::Vector: Copy + Neg<Output = C::Vector>,

Computes the internal collisions between all colliders. Returns a map for each collider index to its collision infos.

Source

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>

Source

pub fn compute_inner_collisions_spatial( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
where C::Vector: Copy + Neg<Output = C::Vector>, C::Cell: Hash + Eq,

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.

Source

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>

Source

pub fn compute_inner_collisions_bvh<V: BoundingVolume>( &self, ) -> HashMap<ColliderId, Vec<IndexedCollisionInfo<C::Vector, I>>>
where C: Bounded<V>, C::Vector: Copy + Neg<Output = C::Vector>,

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.

Source

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.

Trait Implementations§

Source§

impl<C: Collider, I: Copy> Default for CollisionManager<C, I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C, I> Freeze for CollisionManager<C, I>

§

impl<C, I> RefUnwindSafe for CollisionManager<C, I>

§

impl<C, I> Send for CollisionManager<C, I>
where I: Send, C: Send,

§

impl<C, I> Sync for CollisionManager<C, I>
where I: Sync, C: Sync,

§

impl<C, I> Unpin for CollisionManager<C, I>
where I: Unpin, C: Unpin,

§

impl<C, I> UnsafeUnpin for CollisionManager<C, I>

§

impl<C, I> UnwindSafe for CollisionManager<C, I>
where I: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.