1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use rg3d_core::{
    math::vec3::Vec3,
    pool::Handle,
    visitor::{Visit, VisitResult, Visitor}
};
use crate::{
    rigid_body::RigidBody,
    static_geometry::StaticGeometry
};

#[derive(Debug)]
pub struct Contact {
    pub body: Handle<RigidBody>,
    pub position: Vec3,
    pub normal: Vec3,
    pub triangle_index: u32,
    pub static_geom: Handle<StaticGeometry>
}

impl Default for Contact {
    fn default() -> Self {
        Self {
            body: Handle::NONE,
            position: Vec3::ZERO,
            normal: Vec3::new(0.0, 1.0, 0.0),
            triangle_index: 0,
            static_geom: Handle::NONE,
        }
    }
}

impl Visit for Contact {
    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
        visitor.enter_region(name)?;

        self.body.visit("Body", visitor)?;
        self.position.visit("Position", visitor)?;
        self.normal.visit("Normal", visitor)?;
        self.triangle_index.visit("TriangleIndex", visitor)?;

        visitor.leave_region()
    }
}