Skip to main content

concinnity_physics/
events.rs

1// concinnity-physics/src/events.rs
2//
3// What a step reports back: the ray hits a query answers, the sensor regions
4// something crossed, and the contacts strong enough to be worth hearing about.
5// All of it resolved to plain handles and vectors while the step still has
6// both sides of the pair in hand.
7
8use crate::BodyHandle;
9
10/// One raycast hit: the surface point, its outward normal, and the distance
11/// from the ray origin.
12#[derive(Debug, Clone, Copy)]
13pub struct RayHit {
14    /// World-space surface point the ray hit.
15    pub point: [f32; 3],
16    /// Unit-length normal.
17    pub normal: [f32; 3],
18    /// Distance from the ray origin to the hit.
19    pub distance: f32,
20}
21
22/// One boundary crossing of a sensor region recorded during a step: something
23/// began or stopped overlapping the sensor tagged `tag`.
24#[derive(Debug, Clone, Copy)]
25pub struct SensorCrossing {
26    /// The caller's tag for the crossed sensor.
27    pub tag: u64,
28    /// The crossing body, `None` when it left the simulation this step.
29    pub other: Option<BodyHandle>,
30    /// `true` on the way in, `false` on the way out.
31    pub entered: bool,
32}
33
34/// One contact strong enough to pass the simulation's force threshold.
35#[derive(Debug, Clone, Copy)]
36pub struct ContactHit {
37    /// One side of the contact.
38    pub a: BodyHandle,
39    /// The other side of the contact.
40    pub b: BodyHandle,
41    /// Deepest contact point, in world space.
42    pub point: [f32; 3],
43    /// Unit-length normal, pointing from `a` toward `b`.
44    pub normal: [f32; 3],
45    /// Total contact impulse magnitude.
46    pub impulse: f32,
47}