rework predict_collision_end
This commit is contained in:
parent
3a0b3900ec
commit
ad7abbdf1c
233
src/body.rs
233
src/body.rs
@ -20,8 +20,6 @@ pub struct Body {
|
|||||||
velocity: glam::Vec3,//I64 where 2^32 = 1 u/s
|
velocity: glam::Vec3,//I64 where 2^32 = 1 u/s
|
||||||
acceleration: glam::Vec3,//I64 where 2^32 = 1 u/s/s
|
acceleration: glam::Vec3,//I64 where 2^32 = 1 u/s/s
|
||||||
time: TIME,//nanoseconds x xxxxD!
|
time: TIME,//nanoseconds x xxxxD!
|
||||||
//origin_time = timestamp of position and velocity
|
|
||||||
//processed_time = starting time for new events. prevents colliding with the analytic euqation in the past
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum MoveRestriction {
|
pub enum MoveRestriction {
|
||||||
@ -260,7 +258,7 @@ impl Model {
|
|||||||
|
|
||||||
//need non-face (full model) variant for CanCollide false objects
|
//need non-face (full model) variant for CanCollide false objects
|
||||||
//OR have a separate list from contacts for model intersection
|
//OR have a separate list from contacts for model intersection
|
||||||
#[derive(Eq, Hash, PartialEq)]
|
#[derive(Clone,Eq,Hash,PartialEq)]
|
||||||
pub struct RelativeCollision {
|
pub struct RelativeCollision {
|
||||||
face: TreyMeshFace,//just an id
|
face: TreyMeshFace,//just an id
|
||||||
model: u32,//using id to avoid lifetimes
|
model: u32,//using id to avoid lifetimes
|
||||||
@ -303,9 +301,9 @@ impl Body {
|
|||||||
|
|
||||||
impl PhysicsState {
|
impl PhysicsState {
|
||||||
//tickless gaming
|
//tickless gaming
|
||||||
pub fn run(&mut self, time: TIME){
|
pub fn run(&mut self, time_limit:TIME){
|
||||||
//prepare is ommitted - everything is done via instructions.
|
//prepare is ommitted - everything is done via instructions.
|
||||||
while let Some(instruction) = self.next_instruction(time) {//collect
|
while let Some(instruction) = self.next_instruction(time_limit) {//collect
|
||||||
//advance
|
//advance
|
||||||
//self.advance_time(instruction.time);
|
//self.advance_time(instruction.time);
|
||||||
//process
|
//process
|
||||||
@ -369,229 +367,256 @@ impl PhysicsState {
|
|||||||
}
|
}
|
||||||
aabb
|
aabb
|
||||||
}
|
}
|
||||||
fn predict_collision_end(&self,model:&Model,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
|
fn predict_collision_end(&self,time:TIME,time_limit:TIME,collision_data:&RelativeCollision) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//must treat cancollide false objects differently: you may not exit through the same face you entered.
|
//must treat cancollide false objects differently: you may not exit through the same face you entered.
|
||||||
//RelativeCollsion must reference the full model instead of a particular face
|
//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
|
//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
|
//find best t
|
||||||
let mut best_delta_time=time_limit-self.body.time;
|
let mut best_time=time_limit;
|
||||||
let mut best_face:Option<TreyMeshFace>=None;
|
let mut exit_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=model.mesh();
|
let mesh1=self.models_cringe_clone.get(collision_data.model as usize).unwrap().mesh();
|
||||||
let (p,v,a)=(self.body.position,-self.body.velocity,self.body.acceleration);
|
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
for t in zeroes2(mesh0.max.x-mesh1.min.x, v.x, a.x) {
|
match collision_data.face {
|
||||||
|
AabbFace::Top|AabbFace::Back|AabbFace::Bottom|AabbFace::Front=>{
|
||||||
|
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,a.x) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<(-v.x+a.x*t){
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Left);
|
exit_face=Some(TreyMeshFace::Left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for t in zeroes2(mesh0.min.x-mesh1.max.x,v.x,a.x) {
|
||||||
for t in zeroes2(mesh0.min.x-mesh1.max.x, v.x, a.x) {
|
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&(-v.x+a.x*t)<0f32{
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Right);
|
exit_face=Some(TreyMeshFace::Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Left=>{
|
||||||
|
//generate event if v.x<0||a.x<0
|
||||||
|
if -v.x<0f32{
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Left);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Right=>{
|
||||||
|
//generate event if 0<v.x||0<a.x
|
||||||
|
if 0f32<(-v.x){
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Right);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
//collect y
|
//collect y
|
||||||
for t in zeroes2(mesh0.max.y-mesh1.min.y, v.y, a.y) {
|
match collision_data.face {
|
||||||
|
AabbFace::Left|AabbFace::Back|AabbFace::Right|AabbFace::Front=>{
|
||||||
|
for t in zeroes2(mesh0.max.y-mesh1.min.y,v.y,a.y) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<(-v.y+a.y*t){
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Bottom);
|
exit_face=Some(TreyMeshFace::Bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for t in zeroes2(mesh0.min.y-mesh1.max.y,v.y,a.y) {
|
||||||
for t in zeroes2(mesh0.min.y-mesh1.max.y, v.y, a.y) {
|
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&(-v.y+a.y*t)<0f32{
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Top);
|
exit_face=Some(TreyMeshFace::Top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Bottom=>{
|
||||||
|
//generate event if v.y<0||a.y<0
|
||||||
|
if -v.y<0f32{
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Bottom);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Top=>{
|
||||||
|
//generate event if 0<v.y||0<a.y
|
||||||
|
if 0f32<(-v.y){
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Top);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
//collect z
|
//collect z
|
||||||
for t in zeroes2(mesh0.max.z-mesh1.min.z, v.z, a.z) {
|
match collision_data.face {
|
||||||
|
AabbFace::Left|AabbFace::Bottom|AabbFace::Right|AabbFace::Top=>{
|
||||||
|
for t in zeroes2(mesh0.max.z-mesh1.min.z,v.z,a.z) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<(-v.z+a.z*t){
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Front);
|
exit_face=Some(TreyMeshFace::Front);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for t in zeroes2(mesh0.min.z-mesh1.max.z,v.z,a.z) {
|
||||||
for t in zeroes2(mesh0.min.z-mesh1.max.z, v.z, a.z) {
|
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((-t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((-t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&(-v.z+a.z*t)<0f32{
|
if time<=t_time&&t_time<best_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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Back);
|
exit_face=Some(TreyMeshFace::Back);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Front=>{
|
||||||
|
//generate event if v.z<0||a.z<0
|
||||||
|
if -v.z<0f32{
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Front);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
AabbFace::Back=>{
|
||||||
|
//generate event if 0<v.z||0<a.z
|
||||||
|
if 0f32<(-v.z){
|
||||||
|
best_time=time;
|
||||||
|
exit_face=Some(TreyMeshFace::Back);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
//generate instruction
|
//generate instruction
|
||||||
if let Some(face) = best_face{
|
if let Some(face) = exit_face{
|
||||||
return Some(TimedInstruction {
|
return Some(TimedInstruction {
|
||||||
time: self.body.time+best_delta_time,
|
time: best_time,
|
||||||
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
|
instruction: PhysicsInstruction::CollisionEnd(collision_data.clone())
|
||||||
face,
|
|
||||||
model: model_id
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn predict_collision_start(&self,model:&Model,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
|
fn predict_collision_start(&self,time:TIME,time_limit:TIME,model_id:u32) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//find best t
|
//find best t
|
||||||
let mut best_delta_time=time_limit-self.body.time;
|
let mut best_time=time_limit;
|
||||||
let mut best_face:Option<TreyMeshFace>=None;
|
let mut best_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=model.mesh();
|
let mesh1=self.models_cringe_clone.get(model_id as usize).unwrap().mesh();
|
||||||
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
for t in zeroes2(mesh0.max.x-mesh1.min.x, v.x, a.x) {
|
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,a.x) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<v.x+a.x*t{
|
if time<=t_time&&t_time<best_time&&0f32<v.x+a.x*t{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Left);
|
best_face=Some(TreyMeshFace::Left);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for t in zeroes2(mesh0.min.x-mesh1.max.x, v.x, a.x) {
|
for t in zeroes2(mesh0.min.x-mesh1.max.x,v.x,a.x) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&v.x+a.x*t<0f32{
|
if time<=t_time&&t_time<best_time&&v.x+a.x*t<0f32{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Right);
|
best_face=Some(TreyMeshFace::Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//collect y
|
//collect y
|
||||||
for t in zeroes2(mesh0.max.y-mesh1.min.y, v.y, a.y) {
|
for t in zeroes2(mesh0.max.y-mesh1.min.y,v.y,a.y) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<v.y+a.y*t{
|
if time<=t_time&&t_time<best_time&&0f32<v.y+a.y*t{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Bottom);
|
best_face=Some(TreyMeshFace::Bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for t in zeroes2(mesh0.min.y-mesh1.max.y, v.y, a.y) {
|
for t in zeroes2(mesh0.min.y-mesh1.max.y,v.y,a.y) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&v.y+a.y*t<0f32{
|
if time<=t_time&&t_time<best_time&&v.y+a.y*t<0f32{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Top);
|
best_face=Some(TreyMeshFace::Top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//collect z
|
//collect z
|
||||||
for t in zeroes2(mesh0.max.z-mesh1.min.z, v.z, a.z) {
|
for t in zeroes2(mesh0.max.z-mesh1.min.z,v.z,a.z) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&0f32<v.z+a.z*t{
|
if time<=t_time&&t_time<best_time&&0f32<v.z+a.z*t{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Front);
|
best_face=Some(TreyMeshFace::Front);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for t in zeroes2(mesh0.min.z-mesh1.max.z, v.z, a.z) {
|
for t in zeroes2(mesh0.min.z-mesh1.max.z,v.z,a.z) {
|
||||||
//negative t = back in time
|
//negative t = back in time
|
||||||
//must be moving towards surface to collide
|
//must be moving towards surface to collide
|
||||||
//must beat the current soonest collision time
|
//must beat the current soonest collision time
|
||||||
//must be moving towards surface
|
//must be moving towards surface
|
||||||
let t_time=((t as f64)*1_000_000_000f64) as TIME;
|
let t_time=self.body.time+((t as f64)*1_000_000_000f64) as TIME;
|
||||||
if 0<=t_time&&t_time<best_delta_time&&v.z+a.z*t<0f32{
|
if time<=t_time&&t_time<best_time&&v.z+a.z*t<0f32{
|
||||||
let dp=self.body.extrapolated_position(self.body.time+t_time)-p;
|
let dp=self.body.extrapolated_position(t_time)-p;
|
||||||
//faces must be overlapping
|
//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 {
|
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
|
//collect valid t
|
||||||
best_delta_time=t_time;
|
best_time=t_time;
|
||||||
best_face=Some(TreyMeshFace::Back);
|
best_face=Some(TreyMeshFace::Back);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,7 +624,7 @@ impl PhysicsState {
|
|||||||
//generate instruction
|
//generate instruction
|
||||||
if let Some(face) = best_face{
|
if let Some(face) = best_face{
|
||||||
return Some(TimedInstruction {
|
return Some(TimedInstruction {
|
||||||
time: self.body.time+best_delta_time,
|
time: best_time,
|
||||||
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
|
instruction: PhysicsInstruction::CollisionStart(RelativeCollision {
|
||||||
face,
|
face,
|
||||||
model: model_id
|
model: model_id
|
||||||
@ -625,11 +650,11 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
|||||||
}
|
}
|
||||||
//check for collision stop instructions with curent contacts
|
//check for collision stop instructions with curent contacts
|
||||||
for collision_data in self.contacts.iter() {
|
for collision_data in self.contacts.iter() {
|
||||||
collector.collect(self.predict_collision_end(self.models_cringe_clone.get(collision_data.model as usize).unwrap(),time_limit,collision_data.model));
|
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
||||||
}
|
}
|
||||||
//check for collision start instructions (against every part in the game with no optimization!!)
|
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||||
for (i,model) in self.models_cringe_clone.iter().enumerate() {
|
for i in 0..self.models_cringe_clone.len() {
|
||||||
collector.collect(self.predict_collision_start(model,time_limit,i as u32));
|
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
||||||
}
|
}
|
||||||
if self.grounded {
|
if self.grounded {
|
||||||
//walk maintenance
|
//walk maintenance
|
||||||
|
@ -4,7 +4,7 @@ pub struct TimedInstruction<I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait InstructionEmitter<I> {
|
pub trait InstructionEmitter<I> {
|
||||||
fn next_instruction(&self, time:crate::body::TIME) -> Option<TimedInstruction<I>>;
|
fn next_instruction(&self, time_limit:crate::body::TIME) -> Option<TimedInstruction<I>>;
|
||||||
}
|
}
|
||||||
pub trait InstructionConsumer<I> {
|
pub trait InstructionConsumer<I> {
|
||||||
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
|
||||||
|
Loading…
Reference in New Issue
Block a user