From bf51afcf1d7820e204391284566fc85789a3d475 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 2 Nov 2023 17:16:55 -0700 Subject: [PATCH] fix normal code --- src/physics.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/physics.rs b/src/physics.rs index 0ff44c9..30d0751 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -1,6 +1,6 @@ use crate::instruction::{InstructionEmitter,InstructionConsumer,TimedInstruction}; use crate::integer::{Time,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64,Ratio64Vec2}; -use crate::model_physics::{PhysicsMesh,TransformedMesh}; +use crate::model_physics::{PhysicsMesh,TransformedMesh,MeshQuery}; #[derive(Debug)] pub enum PhysicsInstruction { @@ -741,15 +741,17 @@ impl TouchingState{ fn constrain_velocity(&self,models:&PhysicsModels,velocity:&mut Planar64Vec3){ //TODO: trey push solve for contact in &self.contacts{ - let n=contact.normal(models); - velocity-=n.dot(velocity)/n.length(); + let (n,_)=models.mesh(contact.model_id).face_nd(contact.face_id); + let d=n.dot(*velocity); + *velocity-=n*(d/n.dot(n)); } } fn constrain_acceleration(&self,models:&PhysicsModels,acceleration:&mut Planar64Vec3){ //TODO: trey push solve for contact in &self.contacts{ - let n=contact.normal(models); - acceleration-=n.dot(acceleration)/n.length(); + let n=models.mesh(contact.model_id).face_nd(contact.face_id).0; + let d=n.dot(*acceleration); + *acceleration-=n*(d/n.dot(n)); } } fn get_move_state(&self,mut a:Planar64Vec3)->(MoveState,Planar64Vec3){ @@ -1199,12 +1201,12 @@ impl crate::instruction::InstructionConsumer for PhysicsStat //ladder walkstate let mut target_velocity=self.style.get_ladder_target_velocity(&self.camera,self.controls,&self.next_mouse,self.time); self.touching.constrain_velocity(&self.models,&mut target_velocity); - let (walk_state,mut a)=WalkState::ladder(&self.touching,&self.body,&self.style,&self.models,target_velocity,&c.normal(&self.models)); + let (walk_state,mut a)=WalkState::ladder(&self.touching,&self.body,&self.style,&self.models,target_velocity,&self.models.mesh(c.model_id).face_nd(c.face_id).0); self.move_state=MoveState::Ladder(walk_state); self.touching.constrain_acceleration(&self.models,&mut a); self.body.acceleration=a; } - None=>if self.style.surf_slope.map_or(true,|s|sif self.style.surf_slope.map_or(true,|s|s