diff --git a/engine/physics/src/body.rs b/engine/physics/src/body.rs index 102b607..e3fd5b8 100644 --- a/engine/physics/src/body.rs +++ b/engine/physics/src/body.rs @@ -31,6 +31,14 @@ impl Body time, } } + pub const fn relative_to<'a>(&'a self,body0:&'a Body)->VirtualBody<'a,T>{ + //(p0,v0,a0,t0) + //(p1,v1,a1,t1) + VirtualBody{ + body0, + body1:self, + } + } pub fn extrapolated_position(&self,time:Time)->Planar64Vec3{ let dt=time-self.time; self.position @@ -137,14 +145,6 @@ pub struct VirtualBody<'a,T>{ impl VirtualBody<'_,T> where Time:Copy, { - pub const fn relative<'a>(body0:&'a Body,body1:&'a Body)->VirtualBody<'a,T>{ - //(p0,v0,a0,t0) - //(p1,v1,a1,t1) - VirtualBody{ - body0, - body1, - } - } pub fn extrapolated_position(&self,time:Time)->Planar64Vec3{ self.body1.extrapolated_position(time)-self.body0.extrapolated_position(time) } diff --git a/engine/physics/src/physics.rs b/engine/physics/src/physics.rs index 1e8463e..99fcb70 100644 --- a/engine/physics/src/physics.rs +++ b/engine/physics/src/physics.rs @@ -791,7 +791,7 @@ impl TouchingState{ crate::push_solve::push_solve(&contacts,acceleration) } fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,start_time:Time){ - // let relative_body=crate::body::VirtualBody::relative(&Body::ZERO,body).body(time); + // let relative_body=body.relative_to(&Body::ZERO); let relative_body=body; for contact in &self.contacts{ //detect face slide off @@ -1140,7 +1140,7 @@ impl PhysicsData{ state.body.grow_aabb(&mut aabb,state.time,collector.time()); aabb.inflate(data.hitbox_mesh.halfsize); //relative to moving platforms - //let relative_body=&VirtualBody::relative(&Body::default(),&state.body).body(state.time); + //let relative_body=state.body.relative_to(&Body::ZERO); let relative_body=&state.body; data.bvh.the_tester(&aabb,&mut |&convex_mesh_id|{ //no checks are needed because of the time limits. @@ -1203,7 +1203,7 @@ fn recalculate_touching( aabb.grow(body.position); aabb.inflate(hitbox_mesh.halfsize); //relative to moving platforms - //let relative_body=&VirtualBody::relative(&Body::default(),&state.body).body(state.time); + //let relative_body=state.body.relative_to(&Body::ZERO); bvh.the_tester(&aabb,&mut |&convex_mesh_id|{ //no checks are needed because of the time limits. let model_mesh=models.mesh(convex_mesh_id); @@ -1954,111 +1954,111 @@ mod test{ } #[test] fn test_collision_parabola_edge_east_from_west(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(3,3,0), int3(100,-1,0), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_south_from_north(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,3,3), int3(0,-1,100), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_west_from_east(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(-3,3,0), int3(-100,-1,0), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_north_from_south(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,3,-3), int3(0,-1,-100), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_north_from_ne(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,6,-7)>>1, int3(-10,-1,1), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_north_from_nw(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,6,-7)>>1, int3(10,-1,1), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_east_from_se(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(7,6,0)>>1, int3(-1,-1,-10), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_east_from_ne(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(7,6,0)>>1, int3(-1,-1,10), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_south_from_se(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,6,7)>>1, int3(-10,-1,-1), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_south_from_sw(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(0,6,7)>>1, int3(10,-1,-1), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_west_from_se(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(-7,6,0)>>1, int3(1,-1,-10), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_parabola_edge_west_from_ne(){ - test_collision(VirtualBody::relative(&Body::ZERO,&Body::new( + test_collision(Body::new( int3(-7,6,0)>>1, int3(1,-1,10), int3(0,-1,0), Time::ZERO - )).body(Time::from_secs(-1)),Some(Time::from_secs(0))); + ).relative_to(&Body::ZERO).body(Time::from_secs(-1)),Some(Time::from_secs(0))); } #[test] fn test_collision_oblique(){