tentative push solve implementation

This commit is contained in:
Quaternions 2024-08-22 13:41:41 -07:00
parent e5e7ccaa3f
commit 2c77a36083

View File

@ -763,23 +763,31 @@ impl TouchingState{
a a
} }
fn constrain_velocity(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,velocity:&mut Planar64Vec3){ fn constrain_velocity(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,velocity:&mut Planar64Vec3){
//TODO: trey push solve let contacts=self.contacts.iter().map(|contact|{
for contact in &self.contacts{
let n=contact_normal(models,hitbox_mesh,contact); let n=contact_normal(models,hitbox_mesh,contact);
let d=n.dot128(*velocity); crate::push_solve::Contact{
if d<0{ position:Planar64Vec3::ZERO,
*velocity-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64); velocity:n,
normal:n,
} }
}).collect();
match crate::push_solve::push_solve(&contacts,*velocity){
Some(new_velocity)=>*velocity=new_velocity,
None=>println!("Algorithm silently failing :)"),
} }
} }
fn constrain_acceleration(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,acceleration:&mut Planar64Vec3){ fn constrain_acceleration(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,acceleration:&mut Planar64Vec3){
//TODO: trey push solve let contacts=self.contacts.iter().map(|contact|{
for contact in &self.contacts{
let n=contact_normal(models,hitbox_mesh,contact); let n=contact_normal(models,hitbox_mesh,contact);
let d=n.dot128(*acceleration); crate::push_solve::Contact{
if d<0{ position:Planar64Vec3::ZERO,
*acceleration-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64); velocity:n,
normal:n,
} }
}).collect();
match crate::push_solve::push_solve(&contacts,*acceleration){
Some(new_acceleration)=>*acceleration=new_acceleration,
None=>println!("Algorithm silently failing :)"),
} }
} }
fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector<PhysicsInternalInstruction>,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,time:Time){ fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector<PhysicsInternalInstruction>,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,time:Time){