Compare commits

...

6 Commits

Author SHA1 Message Date
91f8652ece fix fix 2023-10-26 20:24:43 -07:00
0ec0d24302 the goober 2023-10-26 20:20:12 -07:00
f7ee18076a iter wrong code but it has no red squiggle 2023-10-26 20:16:45 -07:00
ee7df7787a stack :( 2023-10-26 20:01:26 -07:00
db5f4e1da3 fix usage 2023-10-26 20:01:26 -07:00
01a8efe4d4 return fixed length array and len to avoid heap allocation 2023-10-26 19:51:14 -07:00
2 changed files with 40 additions and 27 deletions

View File

@ -975,7 +975,8 @@ impl PhysicsState {
//collect x //collect x
match collision_data.face { match collision_data.face {
TreyMeshFace::Top|TreyMeshFace::Back|TreyMeshFace::Bottom|TreyMeshFace::Front=>{ TreyMeshFace::Top|TreyMeshFace::Back|TreyMeshFace::Bottom|TreyMeshFace::Front=>{
for t in zeroes2(mesh0.max.x()-mesh1.min.x(),v.x(),a.x()/2) { let (roots,nroots)=zeroes2(mesh0.max.x()-mesh1.min.x(),v.x(),a.x()/2);
for &t in &roots[0..nroots]{
//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
@ -988,7 +989,8 @@ impl PhysicsState {
break; break;
} }
} }
for t in zeroes2(mesh0.min.x()-mesh1.max.x(),v.x(),a.x()/2) { let (roots,nroots)=zeroes2(mesh0.min.x()-mesh1.max.x(),v.x(),a.x()/2);
for &t in &roots[0..nroots]{
//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
@ -1020,7 +1022,8 @@ impl PhysicsState {
//collect y //collect y
match collision_data.face { match collision_data.face {
TreyMeshFace::Left|TreyMeshFace::Back|TreyMeshFace::Right|TreyMeshFace::Front=>{ TreyMeshFace::Left|TreyMeshFace::Back|TreyMeshFace::Right|TreyMeshFace::Front=>{
for t in zeroes2(mesh0.max.y()-mesh1.min.y(),v.y(),a.y()/2) { let (roots,nroots)=zeroes2(mesh0.max.y()-mesh1.min.y(),v.y(),a.y()/2);
for &t in &roots[0..nroots]{
//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
@ -1033,7 +1036,8 @@ impl PhysicsState {
break; break;
} }
} }
for t in zeroes2(mesh0.min.y()-mesh1.max.y(),v.y(),a.y()/2) { let (roots,nroots)=zeroes2(mesh0.min.y()-mesh1.max.y(),v.y(),a.y()/2);
for &t in &roots[0..nroots]{
//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
@ -1065,7 +1069,8 @@ impl PhysicsState {
//collect z //collect z
match collision_data.face { match collision_data.face {
TreyMeshFace::Left|TreyMeshFace::Bottom|TreyMeshFace::Right|TreyMeshFace::Top=>{ TreyMeshFace::Left|TreyMeshFace::Bottom|TreyMeshFace::Right|TreyMeshFace::Top=>{
for t in zeroes2(mesh0.max.z()-mesh1.min.z(),v.z(),a.z()/2) { let (roots,nroots)=zeroes2(mesh0.max.z()-mesh1.min.z(),v.z(),a.z()/2);
for &t in &roots[0..nroots]{
//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
@ -1078,7 +1083,8 @@ impl PhysicsState {
break; break;
} }
} }
for t in zeroes2(mesh0.min.z()-mesh1.max.z(),v.z(),a.z()/2) { let (roots,nroots)=zeroes2(mesh0.min.z()-mesh1.max.z(),v.z(),a.z()/2);
for &t in &roots[0..nroots]{
//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
@ -1124,7 +1130,8 @@ impl PhysicsState {
let mut best_time=time_limit; let mut best_time=time_limit;
let mut best_face:Option<TreyMeshFace>=None; let mut best_face:Option<TreyMeshFace>=None;
//collect x //collect x
for t in zeroes2(mesh0.max.x()-mesh1.min.x(),v.x(),a.x()/2) { let (roots,nroots)=zeroes2(mesh0.max.x()-mesh1.min.x(),v.x(),a.x()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface
@ -1140,7 +1147,8 @@ impl PhysicsState {
} }
} }
} }
for t in zeroes2(mesh0.min.x()-mesh1.max.x(),v.x(),a.x()/2) { let (roots,nroots)=zeroes2(mesh0.min.x()-mesh1.max.x(),v.x(),a.x()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface
@ -1157,7 +1165,8 @@ impl PhysicsState {
} }
} }
//collect y //collect y
for t in zeroes2(mesh0.max.y()-mesh1.min.y(),v.y(),a.y()/2) { let (roots,nroots)=zeroes2(mesh0.max.y()-mesh1.min.y(),v.y(),a.y()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface
@ -1173,7 +1182,8 @@ impl PhysicsState {
} }
} }
} }
for t in zeroes2(mesh0.min.y()-mesh1.max.y(),v.y(),a.y()/2) { let (roots,nroots)=zeroes2(mesh0.min.y()-mesh1.max.y(),v.y(),a.y()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface
@ -1190,7 +1200,8 @@ impl PhysicsState {
} }
} }
//collect z //collect z
for t in zeroes2(mesh0.max.z()-mesh1.min.z(),v.z(),a.z()/2) { let (roots,nroots)=zeroes2(mesh0.max.z()-mesh1.min.z(),v.z(),a.z()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface
@ -1206,7 +1217,8 @@ impl PhysicsState {
} }
} }
} }
for t in zeroes2(mesh0.min.z()-mesh1.max.z(),v.z(),a.z()/2) { let (roots,nroots)=zeroes2(mesh0.min.z()-mesh1.max.z(),v.z(),a.z()/2);
for &t in &roots[0..nroots]{
//must collide now or in the future //must collide now or in the future
//must beat the current soonest collision time //must beat the current soonest collision time
//must be moving towards surface //must be moving towards surface

View File

@ -2,9 +2,10 @@
use crate::integer::Planar64; use crate::integer::Planar64;
#[inline] #[inline]
pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64)->([Planar64;2],usize){
if a2==Planar64::ZERO{ if a2==Planar64::ZERO{
return zeroes1(a0, a1); let ([ret],ret_len)=zeroes1(a0,a1);
return ([ret,Planar64::ZERO],ret_len);
} }
let radicand=a1.get() as i128*a1.get() as i128-a2.get() as i128*a0.get() as i128*4; let radicand=a1.get() as i128*a1.get() as i128-a2.get() as i128*a0.get() as i128*4;
if 0<radicand{ if 0<radicand{
@ -12,21 +13,21 @@ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{
let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()}); let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()});
//TODO: one or two newtons //TODO: one or two newtons
if Planar64::ZERO<a2{ if Planar64::ZERO<a2{
return vec![(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)]; ([(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)],2)
}else{ }else{
return vec![(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)]; ([(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)],2)
} }
}else if radicand==0{ }else if radicand==0{
return vec![a1/(a2*-2)]; ([a1/(a2*-2),Planar64::ZERO],1)
}else{ }else{
return vec![]; ([Planar64::ZERO,Planar64::ZERO],0)
} }
} }
#[inline] #[inline]
pub fn zeroes1(a0:Planar64,a1:Planar64) -> Vec<Planar64> { pub fn zeroes1(a0:Planar64,a1:Planar64)->([Planar64;1],usize){
if a1==Planar64::ZERO{ if a1==Planar64::ZERO{
return vec![]; return ([Planar64::ZERO],0);
}else{ }else{
return vec![-a0/a1]; return ([-a0/a1],1);
} }
} }