whoopsie time deltas

This commit is contained in:
Quaternions 2023-09-18 14:56:52 -07:00
parent e9622a7716
commit 35058436a7

View File

@ -367,7 +367,7 @@ impl PhysicsState {
//RelativeCollsion must reference the full model instead of a particular face
//this is Ctrl+C Ctrl+V of predict_collision_start but with v=-v before the calc and t=-t after the calc
//find best t
let mut best_time=time_limit;
let mut best_delta_time=time_limit-self.body.time;
let mut best_face:Option<TreyMeshFace>=None;
let mesh0=self.mesh();
let mesh1=model.mesh();
@ -379,12 +379,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.x+a.x*-t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.x+a.x*-t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Left);
}
}
@ -395,12 +395,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.x+a.x*-t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.x+a.x*-t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Right);
}
}
@ -412,12 +412,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.y+a.y*-t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.y+a.y*-t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Top);
}
}
@ -428,12 +428,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.y+a.y*-t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.y+a.y*-t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Bottom);
}
}
@ -445,12 +445,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.z+a.z*-t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.z+a.z*-t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Back);
}
}
@ -461,12 +461,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.z+a.z*-t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.z+a.z*-t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Front);
}
}
@ -474,7 +474,7 @@ impl PhysicsState {
//generate instruction
if let Some(face) = best_face{
return Some(TimedInstruction {
time: best_time,
time: self.body.time+best_delta_time,
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
face,
model: model_id
@ -485,7 +485,7 @@ impl PhysicsState {
}
fn predict_collision_start(&self,model:&Model,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
//find best t
let mut best_time=time_limit;
let mut best_delta_time=time_limit-self.body.time;
let mut best_face:Option<TreyMeshFace>=None;
let mesh0=self.mesh();
let mesh1=model.mesh();
@ -497,12 +497,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.x+a.x*t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.x+a.x*t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Left);
}
}
@ -513,12 +513,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.x+a.x*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.x+a.x*t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Right);
}
}
@ -530,12 +530,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.y+a.y*t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.y+a.y*t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Top);
}
}
@ -546,12 +546,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.y+a.y*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.y+a.y*t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x&&mesh1.min.z<mesh0.max.z+dp.z&&mesh0.min.z+dp.z<mesh1.max.z {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Bottom);
}
}
@ -563,12 +563,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&0f32<v.z+a.z*t{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&0f32<v.z+a.z*t{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Back);
}
}
@ -579,12 +579,12 @@ impl PhysicsState {
//must beat the current soonest collision time
//must be moving towards surface
let t_time=((t as f64)*1_000_000_000f64) as TIME;
if 0<=t_time&&t_time<best_time&&v.z+a.z*t<0f32{
let dp=self.body.extrapolated_position(t_time)-p;
if 0<=t_time&&t_time<best_delta_time&&v.z+a.z*t<0f32{
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
//faces must be overlapping
if mesh1.min.y<mesh0.max.y+dp.y&&mesh0.min.y+dp.y<mesh1.max.y&&mesh1.min.x<mesh0.max.x+dp.x&&mesh0.min.x+dp.x<mesh1.max.x {
//collect valid t
best_time=t_time;
best_delta_time=t_time;
best_face=Some(TreyMeshFace::Front);
}
}
@ -592,7 +592,7 @@ impl PhysicsState {
//generate instruction
if let Some(face) = best_face{
return Some(TimedInstruction {
time: best_time,
time: self.body.time+best_delta_time,
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
face,
model: model_id