From 7ce08b0bbec89a935c338ad6e75381640242911f Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 26 Oct 2023 16:18:32 -0700 Subject: [PATCH] move stuff to model_physics --- src/face_crawler.rs | 56 +++++++---------------------- src/main.rs | 1 + src/model_physics.rs | 84 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 45 deletions(-) diff --git a/src/face_crawler.rs b/src/face_crawler.rs index d7a7e80..74b32bd 100644 --- a/src/face_crawler.rs +++ b/src/face_crawler.rs @@ -1,17 +1,7 @@ use crate::physics::Body; +use crate::model_physics::{VirtualMesh,FEV,FaceId}; use crate::integer::{Time,Planar64Vec3}; -struct VertexId(usize); -struct EdgeId(usize); -struct FaceId(usize); - -//Vertex <-> Edge <-> Face -> Collide -enum FEV{ - Face(FaceId), - Edge(EdgeId), - Vertex(VertexId), -} - struct State{ time:Time, fev:FEV, @@ -54,39 +44,17 @@ impl State{ } } -//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) - -struct VirtualMesh<'a>{ - mesh0:&'a PhysicsMesh, - mesh1:&'a PhysicsMesh, -} - -impl VirtualMesh<'_>{ - pub fn minkowski_sum<'a>(mesh0:&PhysicsMesh,mesh1:&PhysicsMesh)->VirtualMesh<'a>{ - Self{ - mesh0, - mesh1, - } - } - fn closest_fev(&self,point:Planar64Vec3)->FEV{ - //put some genius code right here - todo!() - } - pub fn predict_collision(&self,relative_body:&Body,time_limit:Time)->Option<(FaceId,Time)>{ - let mut state=State{ - time:relative_body.time, - fev:self.closest_fev(relative_body.position), - }; - //it would be possible to write down the point of closest approach... - loop{ - match state.next_transition(self,relative_body,time_limit){ - Transition::Miss=>return None, - Transition::NextState(next_state)=>state=next_state, - Transition::Hit(hit_face,hit_time)=>return Some((hit_face,hit_time)), - } +pub fn predict_collision(mesh:&VirtualMesh,relative_body:&Body,time_limit:Time)->Option<(FaceId,Time)>{ + let mut state=State{ + time:relative_body.time, + fev:mesh.closest_fev(relative_body.position), + }; + //it would be possible to write down the point of closest approach... + loop{ + match state.next_transition(mesh,relative_body,time_limit){ + Transition::Miss=>return None, + Transition::NextState(next_state)=>state=next_state, + Transition::Hit(hit_face,hit_time)=>return Some((hit_face,hit_time)), } } } diff --git a/src/main.rs b/src/main.rs index bfa5b43..a942459 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ mod instruction; mod load_roblox; mod face_crawler; mod compat_worker; +mod model_physics; mod model_graphics; mod physics_worker; mod graphics_worker; diff --git a/src/model_physics.rs b/src/model_physics.rs index ab0c014..241467c 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -1 +1,83 @@ -// \ No newline at end of file +use crate::integer::{Planar64,Planar64Vec3}; + +pub struct VertId(usize); +pub struct EdgeId(usize); +pub struct FaceId(usize); + +//Vertex <-> Edge <-> Face -> Collide +pub enum FEV{ + Face(FaceId), + Edge(EdgeId), + Vertex(VertId), +} + +//use Unit32 #[repr(C)] for map files +struct Face{ + normal:Planar64Vec3, + dot:Planar64, +} +struct FaceRefs{ + edges:Vec, + verts:Vec, +} +struct EdgeRefs{ + f0:FaceId,//left + f1:FaceId,//right + v0:VertId,//bottom + v1:VertId,//top + v0f:FaceId,//bottom capping face + v1f:FaceId,//top capping face +} +struct VertRefs{ + faces:Vec, + edges:Vec, +} +pub struct PhysicsMesh{ + faces:Vec, + face_topology:Vec, + edge_topology:Vec, + vert_topology:Vec, +} +impl PhysicsMesh{ + pub fn face_edges(face_id:FaceId)->Vec{ + todo!() + } + pub fn edge_side_faces(edge_id:EdgeId)->[FaceId;2]{ + todo!() + } + pub fn edge_end_faces(edge_id:EdgeId)->[FaceId;2]{ + todo!() + } + pub fn edge_verts(edge_id:EdgeId)->[VertId;2]{ + todo!() + } + pub fn vert_edges(vert_id:VertId)->Vec{ + todo!() + } + pub fn vert_faces(vert_id:VertId)->Vec{ + todo!() + } +} + +//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!() + } +}