use crate::distance::ShapeProxy;
use crate::hull::MAX_POLYGON_VERTICES;
use crate::math_functions::{Plane, Vec2, VEC2_ZERO};
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct RayCastInput {
pub origin: Vec2,
pub translation: Vec2,
pub max_fraction: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ShapeCastInput {
pub proxy: ShapeProxy,
pub translation: Vec2,
pub max_fraction: f32,
pub can_encroach: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct CastOutput {
pub normal: Vec2,
pub point: Vec2,
pub fraction: f32,
pub iterations: i32,
pub hit: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct MassData {
pub mass: f32,
pub center: Vec2,
pub rotational_inertia: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Circle {
pub center: Vec2,
pub radius: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Capsule {
pub center1: Vec2,
pub center2: Vec2,
pub radius: f32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Polygon {
pub vertices: [Vec2; MAX_POLYGON_VERTICES],
pub normals: [Vec2; MAX_POLYGON_VERTICES],
pub centroid: Vec2,
pub radius: f32,
pub count: i32,
}
impl Default for Polygon {
fn default() -> Self {
Polygon {
vertices: [VEC2_ZERO; MAX_POLYGON_VERTICES],
normals: [VEC2_ZERO; MAX_POLYGON_VERTICES],
centroid: VEC2_ZERO,
radius: 0.0,
count: 0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Segment {
pub point1: Vec2,
pub point2: Vec2,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ChainSegment {
pub ghost1: Vec2,
pub segment: Segment,
pub ghost2: Vec2,
pub chain_id: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShapeType {
Circle,
Capsule,
Segment,
Polygon,
ChainSegment,
}
pub const SHAPE_TYPE_COUNT: usize = 5;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ShapeGeometry {
Circle(Circle),
Capsule(Capsule),
Segment(Segment),
Polygon(Polygon),
ChainSegment(ChainSegment),
}
impl ShapeGeometry {
pub fn shape_type(&self) -> ShapeType {
match self {
ShapeGeometry::Circle(_) => ShapeType::Circle,
ShapeGeometry::Capsule(_) => ShapeType::Capsule,
ShapeGeometry::Segment(_) => ShapeType::Segment,
ShapeGeometry::Polygon(_) => ShapeType::Polygon,
ShapeGeometry::ChainSegment(_) => ShapeType::ChainSegment,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ManifoldPoint {
pub anchor_a: Vec2,
pub anchor_b: Vec2,
pub separation: f32,
pub base_separation: f32,
pub normal_impulse: f32,
pub tangent_impulse: f32,
pub total_normal_impulse: f32,
pub normal_velocity: f32,
pub id: u16,
pub persisted: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Manifold {
pub normal: Vec2,
pub rolling_impulse: f32,
pub points: [ManifoldPoint; 2],
pub point_count: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct LocalManifoldPoint {
pub point: Vec2,
pub separation: f32,
pub id: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct LocalManifold {
pub normal: Vec2,
pub points: [LocalManifoldPoint; 2],
pub point_count: i32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlaneResult {
pub plane: Plane,
pub point: Vec2,
pub hit: bool,
}
impl Default for PlaneResult {
fn default() -> Self {
PlaneResult {
plane: Plane {
normal: VEC2_ZERO,
offset: 0.0,
},
point: VEC2_ZERO,
hit: false,
}
}
}