strafe-client-jed/src/face_crawler.rs

62 lines
2.0 KiB
Rust
Raw Normal View History

2023-10-26 04:31:53 +00:00
use crate::physics::Body;
2023-10-26 23:18:32 +00:00
use crate::model_physics::{VirtualMesh,FEV,FaceId};
2023-10-27 02:38:37 +00:00
use crate::integer::{Time,Planar64,Planar64Vec3};
use crate::zeroes::zeroes2;
2023-10-26 04:31:53 +00:00
2023-10-26 04:22:28 +00:00
struct State{
fev:FEV,
2023-10-27 02:38:34 +00:00
time:Time,
2023-10-26 04:22:28 +00:00
}
enum Transition{
Miss,
2023-10-27 02:38:34 +00:00
Next(FEV,Time),
2023-10-26 04:22:28 +00:00
Hit(FaceId,Time),
}
2023-10-26 04:31:53 +00:00
impl State{
2023-10-26 22:51:47 +00:00
fn next_transition(&self,mesh:&VirtualMesh,body:&Body,time_limit:Time)->Transition{
2023-10-26 04:31:53 +00:00
//conflicting derivative means it crosses in the wrong direction.
2023-10-26 22:51:47 +00:00
//if the transition time is equal to an already tested transition, do not replace the current best.
match &self.fev{
2023-10-26 04:31:53 +00:00
FEV::Face(face_id)=>{
2023-10-26 22:51:47 +00:00
//test own face collision time, ignoring edges with zero or conflicting derivative
2023-10-26 04:31:53 +00:00
//test each edge collision time, ignoring edges with zero or conflicting derivative
2023-10-26 22:51:47 +00:00
//if face: Transition::Hit(Face,Time)
//if edge: Transition::NextState(State{time,fev:FEV::Edge(edge_id)})
//if none:
Transition::Miss
2023-10-26 04:31:53 +00:00
},
FEV::Edge(edge_id)=>{
//test each face collision time, ignoring faces with zero or conflicting derivative
//test each vertex collision time, ignoring vertices with zero or conflicting derivative
2023-10-26 22:51:47 +00:00
//if face: Transition::NextState(State{time,fev:FEV::Face(face_id)})
//if vert: Transition::NextState(State{time,fev:FEV::Vertex(vertex_id)})
//if none:
Transition::Miss
2023-10-26 04:31:53 +00:00
},
FEV::Vertex(vertex_id)=>{
//test each edge collision time, ignoring edges with zero or conflicting derivative
2023-10-26 22:51:47 +00:00
//if some: Transition::NextState(State{time,fev:FEV::Edge(edge_id)})
//if none:
Transition::Miss
2023-10-26 04:31:53 +00:00
},
}
}
}
2023-10-26 23:18:32 +00:00
pub fn predict_collision(mesh:&VirtualMesh,relative_body:&Body,time_limit:Time)->Option<(FaceId,Time)>{
let mut state=State{
fev:mesh.closest_fev(relative_body.position),
2023-10-27 02:38:37 +00:00
time:relative_body.time,
2023-10-26 23:18:32 +00:00
};
//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,
2023-10-27 02:38:37 +00:00
Transition::Next(fev,time)=>(state.fev,state.time)=(fev,time),
Transition::Hit(face,time)=>return Some((face,time)),
2023-10-26 04:31:53 +00:00
}
}
}