strafe-client/src/model_physics.rs

80 lines
1.8 KiB
Rust
Raw Normal View History

2023-10-26 23:18:32 +00:00
use crate::integer::{Planar64,Planar64Vec3};
2023-10-27 02:38:34 +00:00
#[derive(Clone,Copy)]
2023-10-26 23:18:32 +00:00
pub struct VertId(usize);
2023-10-27 02:38:34 +00:00
#[derive(Clone,Copy)]
2023-10-26 23:18:32 +00:00
pub struct EdgeId(usize);
2023-10-27 02:38:34 +00:00
#[derive(Clone,Copy)]
2023-10-26 23:18:32 +00:00
pub struct FaceId(usize);
//Vertex <-> Edge <-> Face -> Collide
pub enum FEV{
Face(FaceId),
Edge(EdgeId),
2023-10-27 02:38:34 +00:00
Vert(VertId),
2023-10-26 23:18:32 +00:00
}
//use Unit32 #[repr(C)] for map files
struct Face{
normal:Planar64Vec3,
dot:Planar64,
}
struct FaceRefs{
2023-10-27 02:38:34 +00:00
edges:Vec<(EdgeId,FaceId)>,
2023-10-26 23:18:32 +00:00
verts:Vec<VertId>,
}
struct EdgeRefs{
2023-10-26 23:28:07 +00:00
faces:[FaceId;2],//left, right
2023-10-27 02:38:34 +00:00
verts:[(VertId,FaceId);2],//bottom, top
2023-10-26 23:18:32 +00:00
}
struct VertRefs{
2023-10-27 02:38:34 +00:00
edges:Vec<(EdgeId,FaceId)>,
2023-10-26 23:18:32 +00:00
}
pub struct PhysicsMesh{
faces:Vec<Face>,
face_topology:Vec<FaceRefs>,
edge_topology:Vec<EdgeRefs>,
vert_topology:Vec<VertRefs>,
}
impl PhysicsMesh{
2023-10-27 02:38:34 +00:00
pub fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){
(self.faces[face_id.0].normal,self.faces[face_id.0].dot)
2023-10-26 23:43:58 +00:00
}
//ideally I never calculate the vertex position, but I have to for the graphical meshes...
2023-10-27 02:38:34 +00:00
pub fn face_edges(&self,face_id:FaceId)->&Vec<(EdgeId,FaceId)>{
2023-10-26 23:28:07 +00:00
&self.face_topology[face_id.0].edges
2023-10-26 23:18:32 +00:00
}
2023-10-26 23:28:07 +00:00
pub fn edge_side_faces(&self,edge_id:EdgeId)->&[FaceId;2]{
&self.edge_topology[edge_id.0].faces
2023-10-26 23:18:32 +00:00
}
2023-10-27 02:38:34 +00:00
pub fn edge_ends(&self,edge_id:EdgeId)->&[(VertId,FaceId);2]{
2023-10-26 23:28:07 +00:00
&self.edge_topology[edge_id.0].verts
2023-10-26 23:18:32 +00:00
}
2023-10-27 02:38:34 +00:00
pub fn vert_edges(&self,vert_id:VertId)->&Vec<(EdgeId,FaceId)>{
2023-10-26 23:28:07 +00:00
&self.vert_topology[vert_id.0].edges
2023-10-26 23:18:32 +00:00
}
}
//Note that a face on a minkowski mesh refers to a pair of fevs on the meshes it's summed from
//(face,vertex)
//(edge,edge)
//(vertex,face)
pub struct VirtualMesh<'a>{
mesh0:&'a PhysicsMesh,
mesh1:&'a PhysicsMesh,
}
impl VirtualMesh<'_>{
pub fn minkowski_sum<'a>(mesh0:&'a PhysicsMesh,mesh1:&'a PhysicsMesh)->VirtualMesh<'a>{
VirtualMesh{
mesh0,
mesh1,
}
}
pub fn closest_fev(&self,point:Planar64Vec3)->FEV{
//put some genius code right here
todo!()
}
}