#[cfg(feature = "box-triangle-gjk")]
mod gjk_query;
#[cfg(not(feature = "box-triangle-gjk"))]
mod sat_query;
#[cfg(feature = "box-triangle-gjk")]
pub(crate) use gjk_query::closest_points as box_sweep_closest_points;
use glam::{Affine3A, Vec3A};
#[cfg(not(feature = "box-triangle-gjk"))]
pub(crate) use sat_query::closest_points as box_sweep_closest_points;
use crate::bullet::collision::shapes::{
box_shape::BoxShape, collision_shape::CollisionShapes, compound_shape::CompoundShape,
};
const MAXIMUM_DISTANCE_SQUARED: f32 = 1.0e18;
pub(crate) struct CarToiBoxShape {
shape: CollisionShapes,
}
impl CarToiBoxShape {
pub(crate) fn new(half_extents_with_margin: Vec3A) -> Self {
let child = BoxShape::new(half_extents_with_margin);
Self {
shape: CollisionShapes::Compound(CompoundShape::new(child, Affine3A::IDENTITY)),
}
}
pub(crate) const fn margin(&self) -> f32 {
self.shape.get_margin()
}
#[must_use]
pub(crate) fn angular_motion_disc(&self) -> f32 {
let child = &self.compound().child_shape;
let margin = child.get_margin();
let implicit = child.get_half_extents();
let ex = implicit.x + margin;
let ey = implicit.y + margin;
let ez = implicit.z + margin;
let dx = ex + ex;
let dy = ey + ey;
let dz = ez + ez;
((dx * dx + dy * dy) + dz * dz).sqrt() * 0.5
}
fn compound(&self) -> &CompoundShape {
let CollisionShapes::Compound(compound) = &self.shape else {
unreachable!()
};
compound
}
}
pub(crate) struct CarToiContact {
pub(crate) distance: f32,
pub(crate) normal: Vec3A,
}