From abaf0b293982562c5cbf80df8e65c3c2c4832fd6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 16 Nov 2023 20:08:31 -0800 Subject: [PATCH] debug --- src/face_crawler.rs | 14 +++++++++++++- src/integer.rs | 4 ++-- src/model_physics.rs | 18 +++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/face_crawler.rs b/src/face_crawler.rs index 86dee9c..0db837f 100644 --- a/src/face_crawler.rs +++ b/src/face_crawler.rs @@ -3,6 +3,7 @@ use crate::model_physics::{FEV,MeshQuery,DirectedEdge}; use crate::integer::{Time,Planar64}; use crate::zeroes::zeroes2; +#[derive(Debug)] enum Transition{ Miss, Next(FEV,Time), @@ -20,8 +21,10 @@ enum Transition{ //n=face.normal d=face.dot //n.a t^2+n.v t+n.p-d==0 let (n,d)=mesh.face_nd(face_id); + println!("Face n={} d={}",n,d); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); + println!("dt={} low={} upp={} into={}",t-body.time,time<=t,t{ let n=n.cross(edge_n); let verts=mesh.edge_verts(directed_edge_id.as_undirected()); let d=n.dot(mesh.vert(verts[0])+mesh.vert(verts[1])); + println!("Face Edge n={} d={}",n,d/2); //WARNING: d is moved out of the *2 block because of adding two vertices! for t in zeroes2(n.dot(body.position)*2-d,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); + println!("dt={} low={} upp={} into={}",t-body.time,time<=t,t::Edge(directed_edge_id.as_undirected()),t); @@ -56,9 +61,11 @@ enum Transition{ //edge_n gets parity from the order of edge_faces let n=face_n.cross(edge_n)*((i as i64)*2-1); let d=n.dot(vert_sum); + println!("Edge Face n={} d={}",n,d/2); //WARNING yada yada d *2 for t in zeroes2((n.dot(body.position))*2-d,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); + println!("dt={} low={} upp={} into={}",t-body.time,time<=t,t::Face(edge_face_id),t); @@ -71,8 +78,10 @@ enum Transition{ //vertex normal gets parity from vert index let n=edge_n*(1-2*(i as i64)); let d=n.dot(mesh.vert(vert_id)); + println!("Edge Vert n={} d={}",n,d); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); + println!("dt={} low={} upp={} into={}",t-body.time,time<=t,t::Vert(vert_id),t); @@ -88,8 +97,10 @@ enum Transition{ //edge is directed away from vertex, but we want the dot product to turn out negative let n=-mesh.directed_edge_n(directed_edge_id); let d=n.dot(mesh.vert(vert_id)); + println!("Vert Edge n={} d={}",n,d); for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){ let t=body.time+Time::from(t); + println!("dt={} low={} upp={} into={}",t-body.time,time<=t,t::Edge(directed_edge_id.as_undirected()),t); @@ -106,9 +117,10 @@ pub enum CrawlResult{ Miss(FEV), Hit(F,Time), } -pub fn crawl_fev(mut fev:FEV,mesh:&impl MeshQuery,relative_body:&Body,start_time:Time,time_limit:Time)->CrawlResult{ +pub fn crawl_fev(mut fev:FEV,mesh:&impl MeshQuery,relative_body:&Body,start_time:Time,time_limit:Time)->CrawlResult{ let mut time=start_time; for _ in 0..20{ + println!("@ fev={:?} time={}",fev,time); match next_transition(&fev,time,mesh,relative_body,time_limit){ Transition::Miss=>return CrawlResult::Miss(fev), Transition::Next(next_fev,next_time)=>(fev,time)=(next_fev,next_time), diff --git a/src/integer.rs b/src/integer.rs index e94d026..23c52a9 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -411,7 +411,7 @@ impl TryFrom<[f32;3]> for Unit32Vec3{ */ ///[-1.0,1.0] = [-2^32,2^32] -#[derive(Clone,Copy,Hash,Eq,Ord,PartialEq,PartialOrd)] +#[derive(Clone,Copy,Debug,Hash,Eq,Ord,PartialEq,PartialOrd)] pub struct Planar64(i64); impl Planar64{ pub const ZERO:Self=Self(0); @@ -583,7 +583,7 @@ impl std::ops::Div for Planar64{ ///[-1.0,1.0] = [-2^32,2^32] -#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)] +#[derive(Clone,Copy,Debug,Default,Hash,Eq,PartialEq)] pub struct Planar64Vec3(glam::I64Vec3); impl Planar64Vec3{ pub const ZERO:Self=Planar64Vec3(glam::I64Vec3::ZERO); diff --git a/src/model_physics.rs b/src/model_physics.rs index 9d8b3d9..e8c0658 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -40,6 +40,7 @@ impl DirectedEdge for DirectedEdgeId{ pub struct FaceId(usize); //Vertex <-> Edge <-> Face -> Collide +#[derive(Debug)] pub enum FEV{ Face(F), Edge(E::UndirectedEdge), @@ -47,10 +48,12 @@ pub enum FEV{ } //use Unit32 #[repr(C)] for map files +#[derive(Debug)] struct Face{ normal:Planar64Vec3, dot:Planar64, } +#[derive(Debug)] struct Vert(Planar64Vec3); pub trait MeshQuery{ fn edge_n(&self,edge_id:EDGE::UndirectedEdge)->Planar64Vec3{ @@ -69,18 +72,22 @@ pub trait MeshQuery{ fn vert_edges(&self,vert_id:VERT)->Cow>; fn vert_faces(&self,vert_id:VERT)->Cow>; } +#[derive(Debug)] struct FaceRefs{ edges:Vec, //verts:Vec, } +#[derive(Debug)] struct EdgeRefs{ faces:[FaceId;2],//left, right verts:[VertId;2],//bottom, top } +#[derive(Debug)] struct VertRefs{ faces:Vec, edges:Vec, } +#[derive(Debug)] pub struct PhysicsMesh{ faces:Vec, verts:Vec, @@ -301,11 +308,11 @@ impl MeshQuery for TransformedMesh<'_>{ //(face,vertex) //(edge,edge) //(vertex,face) -#[derive(Clone,Copy)] +#[derive(Clone,Copy,Debug)] pub enum MinkowskiVert{ VertVert(VertId,VertId), } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,Debug)] pub enum MinkowskiEdge{ VertEdge(VertId,EdgeId), EdgeVert(EdgeId,VertId), @@ -320,7 +327,7 @@ impl UndirectedEdge for MinkowskiEdge{ } } } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,Debug)] pub enum MinkowskiDirectedEdge{ VertEdge(VertId,DirectedEdgeId), EdgeVert(DirectedEdgeId,VertId), @@ -341,7 +348,7 @@ impl DirectedEdge for MinkowskiDirectedEdge{ } } } -#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)] +#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)] pub enum MinkowskiFace{ VertFace(VertId,FaceId), EdgeEdge(EdgeId,EdgeId,bool), @@ -477,6 +484,7 @@ impl MinkowskiMesh<'_>{ } pub fn predict_collision_in(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(MinkowskiFace,crate::integer::Time)>{ self.closest_fev_not_inside(relative_body.clone()).map_or(None,|fev|{ + println!("@@@BEGIN REAL CRAWL@@@"); //continue forwards along the body parabola match crate::face_crawler::crawl_fev(fev,self,relative_body,relative_body.time,time_limit){ crate::face_crawler::CrawlResult::Miss(_)=>None, @@ -734,4 +742,4 @@ fn build_me_a_cube(){ let unit_cube=crate::primitives::unit_cube(); let mesh=PhysicsMesh::from(&unit_cube); //println!("mesh={:?}",mesh); -} \ No newline at end of file +}