|
|
|
@@ -4,6 +4,7 @@ use crate::physics::{Time,Body};
|
|
|
|
|
|
|
|
|
|
|
|
use core::ops::Bound;
|
|
|
|
use core::ops::Bound;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Transition<M:MeshQuery>{
|
|
|
|
enum Transition<M:MeshQuery>{
|
|
|
|
Miss,
|
|
|
|
Miss,
|
|
|
|
Next(FEV<M>,GigaTime),
|
|
|
|
Next(FEV<M>,GigaTime),
|
|
|
|
@@ -76,6 +77,8 @@ impl<F:Copy,M:MeshQuery<Normal=Vector3<F>,Offset=Fixed<4,128>>> FEV<M>
|
|
|
|
M::Face:Copy,
|
|
|
|
M::Face:Copy,
|
|
|
|
M::Edge:Copy,
|
|
|
|
M::Edge:Copy,
|
|
|
|
M::Vert:Copy,
|
|
|
|
M::Vert:Copy,
|
|
|
|
|
|
|
|
M:std::fmt::Debug,
|
|
|
|
|
|
|
|
F:std::fmt::Display,
|
|
|
|
F:core::ops::Mul<Fixed<1,32>,Output=Fixed<4,128>>,
|
|
|
|
F:core::ops::Mul<Fixed<1,32>,Output=Fixed<4,128>>,
|
|
|
|
<F as core::ops::Mul<Fixed<1,32>>>::Output:core::iter::Sum,
|
|
|
|
<F as core::ops::Mul<Fixed<1,32>>>::Output:core::iter::Sum,
|
|
|
|
M::Offset:core::ops::Sub<<F as std::ops::Mul<Fixed<1,32>>>::Output>,
|
|
|
|
M::Offset:core::ops::Sub<<F as std::ops::Mul<Fixed<1,32>>>::Output>,
|
|
|
|
@@ -90,10 +93,15 @@ impl<F:Copy,M:MeshQuery<Normal=Vector3<F>,Offset=Fixed<4,128>>> FEV<M>
|
|
|
|
//n=face.normal d=face.dot
|
|
|
|
//n=face.normal d=face.dot
|
|
|
|
//n.a t^2+n.v t+n.p-d==0
|
|
|
|
//n.a t^2+n.v t+n.p-d==0
|
|
|
|
let (n,d)=mesh.face_nd(face_id);
|
|
|
|
let (n,d)=mesh.face_nd(face_id);
|
|
|
|
|
|
|
|
println!("Face n={} d={}",n,d);
|
|
|
|
//TODO: use higher precision d value?
|
|
|
|
//TODO: use higher precision d value?
|
|
|
|
//use the mesh transform translation instead of baking it into the d value.
|
|
|
|
//use the mesh transform translation instead of baking it into the d value.
|
|
|
|
for dt in Fixed::<4,128>::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
|
|
|
|
for dt in Fixed::<4,128>::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
|
|
|
|
if low(&lower_bound,&dt)&&upp(&dt,&upper_bound)&&n.dot(body.extrapolated_velocity_ratio_dt(dt)).is_negative(){
|
|
|
|
let low=low(&lower_bound,&dt);
|
|
|
|
|
|
|
|
let upp=upp(&dt,&upper_bound);
|
|
|
|
|
|
|
|
let into=n.dot(body.extrapolated_velocity_ratio_dt(dt)).is_negative();
|
|
|
|
|
|
|
|
println!("dt={} low={low} upp={upp} into={into}",dt.divide());
|
|
|
|
|
|
|
|
if low&&upp&&into{
|
|
|
|
upper_bound=Bound::Included(dt);
|
|
|
|
upper_bound=Bound::Included(dt);
|
|
|
|
best_transition=Transition::Hit(face_id,dt);
|
|
|
|
best_transition=Transition::Hit(face_id,dt);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@@ -127,10 +135,16 @@ impl<F:Copy,M:MeshQuery<Normal=Vector3<F>,Offset=Fixed<4,128>>> FEV<M>
|
|
|
|
let face_n=mesh.face_nd(edge_face_id).0;
|
|
|
|
let face_n=mesh.face_nd(edge_face_id).0;
|
|
|
|
//edge_n gets parity from the order of edge_faces
|
|
|
|
//edge_n gets parity from the order of edge_faces
|
|
|
|
let n=face_n.cross(edge_n)*((i as i64)*2-1);
|
|
|
|
let n=face_n.cross(edge_n)*((i as i64)*2-1);
|
|
|
|
|
|
|
|
let d=n.dot(delta_pos).wrap_4();
|
|
|
|
|
|
|
|
println!("Edge Face={:?} boundary_n={} boundary_d={}",edge_face_id,n,d>>1);
|
|
|
|
//WARNING yada yada d *2
|
|
|
|
//WARNING yada yada d *2
|
|
|
|
//wrap for speed
|
|
|
|
//wrap for speed
|
|
|
|
for dt in Fixed::<4,128>::zeroes2(n.dot(delta_pos).wrap_4(),n.dot(body.velocity).wrap_4()*2,n.dot(body.acceleration).wrap_4()){
|
|
|
|
for dt in Fixed::<4,128>::zeroes2(d,n.dot(body.velocity).wrap_4()*2,n.dot(body.acceleration).wrap_4()){
|
|
|
|
if low(&lower_bound,&dt)&&upp(&dt,&upper_bound)&&n.dot(body.extrapolated_velocity_ratio_dt(dt)).is_negative(){
|
|
|
|
let low=low(&lower_bound,&dt);
|
|
|
|
|
|
|
|
let upp=upp(&dt,&upper_bound);
|
|
|
|
|
|
|
|
let into=n.dot(body.extrapolated_velocity_ratio_dt(dt)).is_negative();
|
|
|
|
|
|
|
|
println!("dt={} low={low} upp={upp} into={into}",dt.divide());
|
|
|
|
|
|
|
|
if low&&upp&&into{
|
|
|
|
upper_bound=Bound::Included(dt);
|
|
|
|
upper_bound=Bound::Included(dt);
|
|
|
|
best_transition=Transition::Next(FEV::Face(edge_face_id),dt);
|
|
|
|
best_transition=Transition::Next(FEV::Face(edge_face_id),dt);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@@ -174,8 +188,11 @@ impl<F:Copy,M:MeshQuery<Normal=Vector3<F>,Offset=Fixed<4,128>>> FEV<M>
|
|
|
|
pub fn crawl(mut self,mesh:&M,relative_body:&Body,lower_bound:Bound<&Time>,upper_bound:Bound<&Time>)->CrawlResult<M>{
|
|
|
|
pub fn crawl(mut self,mesh:&M,relative_body:&Body,lower_bound:Bound<&Time>,upper_bound:Bound<&Time>)->CrawlResult<M>{
|
|
|
|
let mut lower_bound=lower_bound.map(|&t|into_giga_time(t,relative_body.time));
|
|
|
|
let mut lower_bound=lower_bound.map(|&t|into_giga_time(t,relative_body.time));
|
|
|
|
let upper_bound=upper_bound.map(|&t|into_giga_time(t,relative_body.time));
|
|
|
|
let upper_bound=upper_bound.map(|&t|into_giga_time(t,relative_body.time));
|
|
|
|
|
|
|
|
println!("crawl begin={self:?}");
|
|
|
|
for _ in 0..20{
|
|
|
|
for _ in 0..20{
|
|
|
|
match self.next_transition(mesh,relative_body,lower_bound,upper_bound){
|
|
|
|
let transition=self.next_transition(mesh,relative_body,lower_bound,upper_bound);
|
|
|
|
|
|
|
|
println!("transition={transition:?}");
|
|
|
|
|
|
|
|
match transition{
|
|
|
|
Transition::Miss=>return CrawlResult::Miss(self),
|
|
|
|
Transition::Miss=>return CrawlResult::Miss(self),
|
|
|
|
Transition::Next(next_fev,next_time)=>(self,lower_bound)=(next_fev,Bound::Included(next_time)),
|
|
|
|
Transition::Next(next_fev,next_time)=>(self,lower_bound)=(next_fev,Bound::Included(next_time)),
|
|
|
|
Transition::Hit(face,time)=>return CrawlResult::Hit(face,time),
|
|
|
|
Transition::Hit(face,time)=>return CrawlResult::Hit(face,time),
|
|
|
|
|