From 5f2cf8f32e8db62358373d5705fef4678d01818f Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Wed, 22 Jan 2025 07:00:42 -0800
Subject: [PATCH] physics: change body api

---
 engine/physics/src/body.rs    | 16 +++++------
 engine/physics/src/physics.rs | 54 +++++++++++++++++------------------
 2 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/engine/physics/src/body.rs b/engine/physics/src/body.rs
index 102b607f..e3fd5b89 100644
--- a/engine/physics/src/body.rs
+++ b/engine/physics/src/body.rs
@@ -31,6 +31,14 @@ impl<T> Body<T>
 			time,
 		}
 	}
+	pub const fn relative_to<'a>(&'a self,body0:&'a Body<T>)->VirtualBody<'a,T>{
+		//(p0,v0,a0,t0)
+		//(p1,v1,a1,t1)
+		VirtualBody{
+			body0,
+			body1:self,
+		}
+	}
 	pub fn extrapolated_position(&self,time:Time<T>)->Planar64Vec3{
 		let dt=time-self.time;
 		self.position
@@ -137,14 +145,6 @@ pub struct VirtualBody<'a,T>{
 impl<T> VirtualBody<'_,T>
 	where Time<T>:Copy,
 {
-	pub const fn relative<'a>(body0:&'a Body<T>,body1:&'a Body<T>)->VirtualBody<'a,T>{
-		//(p0,v0,a0,t0)
-		//(p1,v1,a1,t1)
-		VirtualBody{
-			body0,
-			body1,
-		}
-	}
 	pub fn extrapolated_position(&self,time:Time<T>)->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 1e8463ef..99fcb702 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<InternalInstruction,TimeInner>,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(){