pub mod shape;
use std::{collections::HashSet, hash::Hash};
use parry2d_f64::query::ContactManifold;
use vek::Vec2;
use crate::math::Iso;
use self::shape::Shape;
pub struct CollisionState<K> {
pub manifolds: Vec<ContactManifold<(), ()>>,
pub substep_collisions: Vec<(K, K, CollisionResponse)>,
pub step_collisions: HashSet<(K, K)>,
}
impl<K> CollisionState<K> {
pub fn new() -> Self {
let manifolds = Vec::with_capacity(16);
let substep_collisions = Vec::new();
let step_collisions = HashSet::new();
Self {
manifolds,
substep_collisions,
step_collisions,
}
}
pub fn clear_substep(&mut self) {
self.substep_collisions.clear();
}
pub fn clear_step(&mut self) {
self.step_collisions.clear();
}
pub fn detect(
&mut self,
a_data: K,
a_shape: &Shape,
a_pos: Iso,
b_data: K,
b_shape: &Shape,
b_pos: Iso,
) where
K: Clone + Hash + Eq,
{
a_shape.push_collisions(a_pos, a_data, b_shape, b_pos, b_data, self);
}
}
impl<K> Default for CollisionState<K> {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CollisionResponse {
pub local_contact_1: Vec2<f64>,
pub local_contact_2: Vec2<f64>,
pub normal: Vec2<f64>,
pub penetration: f64,
}