Externalize the proximity code (renamed intersection).

This commit is contained in:
Crozet Sébastien
2020-12-17 13:23:00 +01:00
parent e231bacec6
commit 29717c2887
22 changed files with 144 additions and 1051 deletions

View File

@@ -64,7 +64,7 @@ impl CollisionPipeline {
contact_pair_filter,
events,
);
narrow_phase.compute_proximities(
narrow_phase.compute_intersections(
prediction_distance,
bodies,
colliders,

View File

@@ -1,14 +1,14 @@
use crate::geometry::{ContactEvent, ProximityEvent};
use crate::geometry::{ContactEvent, IntersectionEvent};
use crossbeam::channel::Sender;
/// Trait implemented by structures responsible for handling events generated by the physics engine.
///
/// Implementors of this trait will typically collect these events for future processing.
pub trait EventHandler: Send + Sync {
/// Handle a proximity event.
/// Handle an intersection event.
///
/// A proximity event is emitted when the state of proximity between two colliders changes.
fn handle_proximity_event(&self, event: ProximityEvent);
/// A intersection event is emitted when the state of intersection between two colliders changes.
fn handle_intersection_event(&self, event: IntersectionEvent);
/// Handle a contact event.
///
/// A contact event is emitted when two collider start or stop touching, independently from the
@@ -17,32 +17,32 @@ pub trait EventHandler: Send + Sync {
}
impl EventHandler for () {
fn handle_proximity_event(&self, _event: ProximityEvent) {}
fn handle_intersection_event(&self, _event: IntersectionEvent) {}
fn handle_contact_event(&self, _event: ContactEvent) {}
}
/// A physics event handler that collects events into a crossbeam channel.
pub struct ChannelEventCollector {
proximity_event_sender: Sender<ProximityEvent>,
intersection_event_sender: Sender<IntersectionEvent>,
contact_event_sender: Sender<ContactEvent>,
}
impl ChannelEventCollector {
/// Initialize a new physics event handler from crossbeam channel senders.
pub fn new(
proximity_event_sender: Sender<ProximityEvent>,
intersection_event_sender: Sender<IntersectionEvent>,
contact_event_sender: Sender<ContactEvent>,
) -> Self {
Self {
proximity_event_sender,
intersection_event_sender,
contact_event_sender,
}
}
}
impl EventHandler for ChannelEventCollector {
fn handle_proximity_event(&self, event: ProximityEvent) {
let _ = self.proximity_event_sender.send(event);
fn handle_intersection_event(&self, event: IntersectionEvent) {
let _ = self.intersection_event_sender.send(event);
}
fn handle_contact_event(&self, event: ContactEvent) {

View File

@@ -118,7 +118,7 @@ impl PhysicsPipeline {
contact_pair_filter,
events,
);
narrow_phase.compute_proximities(
narrow_phase.compute_intersections(
integration_parameters.prediction_distance,
bodies,
colliders,