From 8839b8fbb37bbdddfb0028e30b28a3d3c0809635 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 16 Nov 2023 19:57:50 -0800 Subject: [PATCH] fix not moving --- src/model_physics.rs | 32 ++++++++++++++++++-------------- src/physics.rs | 10 +++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/model_physics.rs b/src/model_physics.rs index 8063d30..b0021eb 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -354,22 +354,26 @@ impl MinkowskiMesh<'_>{ MinkowskiVert::VertVert(self.mesh0.farthest_vert(dir),self.mesh1.farthest_vert(-dir)) } pub fn predict_collision_in(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(MinkowskiFace,crate::integer::Time)>{ - let start_vert=FEV::::Vert(self.farthest_vert((-relative_body.clone()).infinity_dir())); - match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,relative_body,relative_body.time){ - crate::face_crawler::CrawlResult::Closest(fev)=>{ - crate::face_crawler::crawl_fev(fev,self,relative_body,relative_body.time,time_limit) - }, - crate::face_crawler::CrawlResult::Hit(_,_)=>None,//already in or passed - } + (-relative_body.clone()).infinity_dir().map_or(None,|dir|{ + let start_vert=FEV::::Vert(self.farthest_vert(dir)); + match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,relative_body,relative_body.time){ + crate::face_crawler::CrawlResult::Closest(fev)=>{ + crate::face_crawler::crawl_fev(fev,self,relative_body,relative_body.time,time_limit) + }, + crate::face_crawler::CrawlResult::Hit(_,_)=>None,//already in or passed + } + }) } pub fn predict_collision_out(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(MinkowskiFace,crate::integer::Time)>{ - let start_vert=FEV::::Vert(self.farthest_vert(relative_body.infinity_dir())); - match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,&-relative_body.clone(),-time_limit){ - crate::face_crawler::CrawlResult::Closest(fev)=>{ - crate::face_crawler::crawl_fev(fev,self,&-relative_body.clone(),-time_limit,-relative_body.time).map(|t|(t.0,-t.1)) - }, - crate::face_crawler::CrawlResult::Hit(face,time)=>Some((face,-time)), - } + relative_body.infinity_dir().map_or(None,|dir|{ + let start_vert=FEV::::Vert(self.farthest_vert(dir)); + match crate::face_crawler::crawl_fev_from_negative_infinity(start_vert,self,&-relative_body.clone(),-time_limit){ + crate::face_crawler::CrawlResult::Closest(fev)=>{ + crate::face_crawler::crawl_fev(fev,self,&-relative_body.clone(),-time_limit,-relative_body.time).map(|t|(t.0,-t.1)) + }, + crate::face_crawler::CrawlResult::Hit(face,time)=>Some((face,-time)), + } + }) } pub fn predict_collision_face_out(&self,relative_body:&crate::physics::Body,time_limit:crate::integer::Time,contact_face_id:MinkowskiFace)->Option<(MinkowskiEdge,crate::integer::Time)>{ //no algorithm needed, there is only one state and two cases (Edge,None) diff --git a/src/physics.rs b/src/physics.rs index 7bd8aa8..d8baefa 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -968,11 +968,15 @@ impl Body{ self.velocity=self.extrapolated_velocity(time); self.time=time; } - pub fn infinity_dir(&self)->Planar64Vec3{ + pub fn infinity_dir(&self)->Option{ if self.acceleration==Planar64Vec3::ZERO{ - self.velocity + if self.velocity==Planar64Vec3::ZERO{ + None + }else{ + Some(self.velocity) + } }else{ - self.acceleration + Some(self.acceleration) } } }