rapier3d/geometry/
broad_phase.rs

1use crate::dynamics::RigidBodySet;
2use crate::geometry::{BroadPhasePairEvent, ColliderHandle, ColliderSet};
3use crate::prelude::IntegrationParameters;
4use downcast_rs::DowncastSync;
5
6/// Trait implemented by broad-phase algorithms supported by Rapier.
7///
8/// The task of a broad-phase algorithm is to detect potential collision pairs, usually based on
9/// bounding volumes. The pairs must be conservative: it is OK to create a collision pair if
10/// two objects don’t actually touch, but it is incorrect to remove a pair between two objects
11/// that are still touching. In other words, it can have false-positive (though these induce
12/// some computational overhead on the narrow-phase), but cannot have false-negative.
13pub trait BroadPhase: Send + Sync + 'static + DowncastSync {
14    /// Updates the broad-phase.
15    ///
16    /// The results must be output through the `events` struct. The broad-phase algorithm is only
17    /// required to generate new events (i.e. no need to re-send an `AddPair` event if it was already
18    /// sent previously and no `RemovePair` happened since then). Sending redundant events is allowed
19    /// but can result in a slight computational overhead.
20    ///
21    /// The `colliders` set is mutable only to provide access to
22    /// [`collider.set_internal_broad_phase_proxy_index`]. Other properties of the collider should
23    /// **not** be modified during the broad-phase update.
24    ///
25    /// # Parameters
26    /// - `params`: the integration parameters governing the simulation.
27    /// - `colliders`: the set of colliders. Change detection with `collider.needs_broad_phase_update()`
28    ///   can be relied on at this stage.
29    /// - `modified_colliders`: colliders that are know to be modified since the last update.
30    /// - `removed_colliders`: colliders that got removed since the last update. Any associated data
31    ///   in the broad-phase should be removed by this call to `update`.
32    /// - `events`: the broad-phase’s output. They indicate what collision pairs need to be created
33    ///   and what pairs need to be removed. It is OK to create pairs for colliders that don’t
34    ///   actually collide (though this can increase computational overhead in the narrow-phase)
35    ///   but it is important not to indicate removal of a collision pair if the underlying colliders
36    ///   are still touching or closer than `prediction_distance`.
37    fn update(
38        &mut self,
39        params: &IntegrationParameters,
40        colliders: &ColliderSet,
41        bodies: &RigidBodySet,
42        modified_colliders: &[ColliderHandle],
43        removed_colliders: &[ColliderHandle],
44        events: &mut Vec<BroadPhasePairEvent>,
45    );
46}
47
48downcast_rs::impl_downcast!(sync BroadPhase);