1use crate::core::NULL_INDEX;
10use crate::distance::SimplexCache;
11use crate::manifold::{Manifold, SatCache};
12use crate::math_functions::{Quat, Transform, Vec3, QUAT_IDENTITY, TRANSFORM_IDENTITY, VEC3_ZERO};
13
14pub mod contact_flags {
16 pub const TOUCHING: u32 = 0x0000_0001;
18 pub const HIT_EVENT: u32 = 0x0000_0002;
20 pub const ENABLE_CONTACT_EVENTS: u32 = 0x0000_0004;
22 pub const STATIC_FLAG: u32 = 0x0000_0008;
24 pub const RECYCLE: u32 = 0x0000_0010;
25
26 pub const SIM_TOUCHING: u32 = 0x0001_0000;
28 pub const SIM_DISJOINT: u32 = 0x0002_0000;
30 pub const SIM_STARTED_TOUCHING: u32 = 0x0004_0000;
32 pub const SIM_STOPPED_TOUCHING: u32 = 0x0008_0000;
34 pub const SIM_ENABLE_HIT_EVENT: u32 = 0x0010_0000;
36 pub const SIM_ENABLE_PRE_SOLVE_EVENTS: u32 = 0x0020_0000;
38 pub const SIM_MESH_CONTACT: u32 = 0x0040_0000;
40 pub const RELATIVE_TRANSFORM_VALID: u32 = 0x0080_0000;
42}
43
44#[derive(Debug, Clone, Copy, PartialEq)]
46pub enum ContactCache {
47 Sat(SatCache),
48 Simplex(SimplexCache),
49}
50
51impl Default for ContactCache {
52 fn default() -> Self {
53 ContactCache::Sat(SatCache::default())
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq)]
59pub struct TriangleCache {
60 pub triangle_index: i32,
61 pub cache: ContactCache,
62}
63
64impl Default for TriangleCache {
65 fn default() -> Self {
66 TriangleCache {
67 triangle_index: NULL_INDEX,
68 cache: ContactCache::default(),
69 }
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Default)]
75pub struct MeshContact {
76 pub triangle_cache: Vec<TriangleCache>,
77 pub query_bounds: crate::math_functions::Aabb,
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Default)]
82pub struct ConvexContact {
83 pub cache: ContactCache,
84}
85
86#[derive(Debug, Clone, PartialEq)]
88pub enum ContactGeometry {
89 Convex(ConvexContact),
90 Mesh(MeshContact),
91}
92
93impl Default for ContactGeometry {
94 fn default() -> Self {
95 ContactGeometry::Convex(ConvexContact::default())
96 }
97}
98
99#[derive(Debug, Clone, Copy, PartialEq, Eq)]
102pub struct ContactEdge {
103 pub body_id: i32,
104 pub prev_key: i32,
105 pub next_key: i32,
106}
107
108impl Default for ContactEdge {
109 fn default() -> Self {
110 ContactEdge {
111 body_id: NULL_INDEX,
112 prev_key: NULL_INDEX,
113 next_key: NULL_INDEX,
114 }
115 }
116}
117
118#[derive(Debug, Clone)]
120pub struct Contact {
121 pub set_index: i32,
123
124 pub color_index: i32,
127
128 pub local_index: i32,
130
131 pub edges: [ContactEdge; 2],
132 pub shape_id_a: i32,
133 pub shape_id_b: i32,
134 pub child_index: i32,
135
136 pub island_id: i32,
138
139 pub island_index: i32,
142
143 pub contact_id: i32,
145
146 pub body_sim_index_a: i32,
148 pub body_sim_index_b: i32,
149
150 pub flags: u32,
152
153 pub manifolds: Vec<Manifold>,
154
155 pub cached_rotation_a: Quat,
157 pub cached_rotation_b: Quat,
158 pub cached_relative_pose: Transform,
159
160 pub friction: f32,
162 pub restitution: f32,
163 pub rolling_resistance: f32,
164 pub tangent_velocity: Vec3,
165
166 pub geometry: ContactGeometry,
168
169 pub generation: u32,
172}
173
174impl Contact {
175 pub fn manifold_count(&self) -> i32 {
177 self.manifolds.len() as i32
178 }
179}
180
181impl Default for Contact {
182 fn default() -> Self {
183 Contact {
184 set_index: NULL_INDEX,
185 color_index: NULL_INDEX,
186 local_index: NULL_INDEX,
187 edges: [ContactEdge::default(); 2],
188 shape_id_a: NULL_INDEX,
189 shape_id_b: NULL_INDEX,
190 child_index: 0,
191 island_id: NULL_INDEX,
192 island_index: NULL_INDEX,
193 contact_id: NULL_INDEX,
194 body_sim_index_a: NULL_INDEX,
195 body_sim_index_b: NULL_INDEX,
196 flags: 0,
197 manifolds: Vec::new(),
198 cached_rotation_a: QUAT_IDENTITY,
199 cached_rotation_b: QUAT_IDENTITY,
200 cached_relative_pose: TRANSFORM_IDENTITY,
201 friction: 0.0,
202 restitution: 0.0,
203 rolling_resistance: 0.0,
204 tangent_velocity: VEC3_ZERO,
205 geometry: ContactGeometry::default(),
206 generation: 0,
207 }
208 }
209}
210
211#[derive(Debug, Clone, Copy, PartialEq, Eq)]
213pub struct ContactSpec {
214 pub contact_id: i32,
215 pub manifold_start: i32,
217 pub manifold_count: u16,
218}
219
220impl Default for ContactSpec {
221 fn default() -> Self {
222 ContactSpec {
223 contact_id: NULL_INDEX,
224 manifold_start: 0,
225 manifold_count: 0,
226 }
227 }
228}
229
230mod collide;
231mod lifecycle;
232mod mesh_cache;
233mod mesh_contact;
234mod mesh_cull;
235mod update;
236
237pub use collide::*;
238pub use lifecycle::*;
239pub use mesh_contact::{apply_mesh_hit_flags, compute_mesh_manifolds};
240pub use update::*;