use crate::core::NULL_INDEX;
use crate::distance::SimplexCache;
use crate::manifold::{Manifold, SatCache};
use crate::math_functions::{Quat, Transform, Vec3, QUAT_IDENTITY, TRANSFORM_IDENTITY, VEC3_ZERO};
pub mod contact_flags {
pub const TOUCHING: u32 = 0x0000_0001;
pub const HIT_EVENT: u32 = 0x0000_0002;
pub const ENABLE_CONTACT_EVENTS: u32 = 0x0000_0004;
pub const STATIC_FLAG: u32 = 0x0000_0008;
pub const RECYCLE: u32 = 0x0000_0010;
pub const SIM_TOUCHING: u32 = 0x0001_0000;
pub const SIM_DISJOINT: u32 = 0x0002_0000;
pub const SIM_STARTED_TOUCHING: u32 = 0x0004_0000;
pub const SIM_STOPPED_TOUCHING: u32 = 0x0008_0000;
pub const SIM_ENABLE_HIT_EVENT: u32 = 0x0010_0000;
pub const SIM_ENABLE_PRE_SOLVE_EVENTS: u32 = 0x0020_0000;
pub const SIM_MESH_CONTACT: u32 = 0x0040_0000;
pub const RELATIVE_TRANSFORM_VALID: u32 = 0x0080_0000;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ContactCache {
Sat(SatCache),
Simplex(SimplexCache),
}
impl Default for ContactCache {
fn default() -> Self {
ContactCache::Sat(SatCache::default())
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TriangleCache {
pub triangle_index: i32,
pub cache: ContactCache,
}
impl Default for TriangleCache {
fn default() -> Self {
TriangleCache {
triangle_index: NULL_INDEX,
cache: ContactCache::default(),
}
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MeshContact {
pub triangle_cache: Vec<TriangleCache>,
pub query_bounds: crate::math_functions::Aabb,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ConvexContact {
pub cache: ContactCache,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ContactGeometry {
Convex(ConvexContact),
Mesh(MeshContact),
}
impl Default for ContactGeometry {
fn default() -> Self {
ContactGeometry::Convex(ConvexContact::default())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ContactEdge {
pub body_id: i32,
pub prev_key: i32,
pub next_key: i32,
}
impl Default for ContactEdge {
fn default() -> Self {
ContactEdge {
body_id: NULL_INDEX,
prev_key: NULL_INDEX,
next_key: NULL_INDEX,
}
}
}
#[derive(Debug, Clone)]
pub struct Contact {
pub set_index: i32,
pub color_index: i32,
pub local_index: i32,
pub edges: [ContactEdge; 2],
pub shape_id_a: i32,
pub shape_id_b: i32,
pub child_index: i32,
pub island_id: i32,
pub island_index: i32,
pub contact_id: i32,
pub body_sim_index_a: i32,
pub body_sim_index_b: i32,
pub flags: u32,
pub manifolds: Vec<Manifold>,
pub cached_rotation_a: Quat,
pub cached_rotation_b: Quat,
pub cached_relative_pose: Transform,
pub friction: f32,
pub restitution: f32,
pub rolling_resistance: f32,
pub tangent_velocity: Vec3,
pub geometry: ContactGeometry,
pub generation: u32,
}
impl Contact {
pub fn manifold_count(&self) -> i32 {
self.manifolds.len() as i32
}
}
impl Default for Contact {
fn default() -> Self {
Contact {
set_index: NULL_INDEX,
color_index: NULL_INDEX,
local_index: NULL_INDEX,
edges: [ContactEdge::default(); 2],
shape_id_a: NULL_INDEX,
shape_id_b: NULL_INDEX,
child_index: 0,
island_id: NULL_INDEX,
island_index: NULL_INDEX,
contact_id: NULL_INDEX,
body_sim_index_a: NULL_INDEX,
body_sim_index_b: NULL_INDEX,
flags: 0,
manifolds: Vec::new(),
cached_rotation_a: QUAT_IDENTITY,
cached_rotation_b: QUAT_IDENTITY,
cached_relative_pose: TRANSFORM_IDENTITY,
friction: 0.0,
restitution: 0.0,
rolling_resistance: 0.0,
tangent_velocity: VEC3_ZERO,
geometry: ContactGeometry::default(),
generation: 0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ContactSpec {
pub contact_id: i32,
pub manifold_start: i32,
pub manifold_count: u16,
}
impl Default for ContactSpec {
fn default() -> Self {
ContactSpec {
contact_id: NULL_INDEX,
manifold_start: 0,
manifold_count: 0,
}
}
}
mod collide;
mod lifecycle;
mod mesh_cache;
mod mesh_contact;
mod mesh_cull;
mod update;
pub use collide::*;
pub use lifecycle::*;
pub use mesh_contact::{apply_mesh_hit_flags, compute_mesh_manifolds};
pub use update::*;