From bbc9a89ad77ef5a74ae7c9407ef9a714e611b200 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 12 Sep 2024 13:49:42 -0700 Subject: [PATCH] physics.rs cleared --- src/physics.rs | 55 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/physics.rs b/src/physics.rs index 85e12fc..798edb1 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -410,7 +410,7 @@ impl HitboxMesh{ let transform=PhysicsMeshTransform::new(transform); let transformed_mesh=TransformedMesh::new(mesh.complete_mesh_view(),&transform); for vert in transformed_mesh.verts(){ - aabb.grow(vert); + aabb.grow(vert.fix_1()); } Self{ halfsize:aabb.size()>>1, @@ -438,7 +438,7 @@ impl StyleHelper for StyleModifiers{ fn get_control_dir(&self,controls:Controls)->Planar64Vec3{ //don't get fancy just do it - let mut control_dir:Planar64Vec3 = vec3::ZERO; + let mut control_dir:Planar64Vec3=vec3::ZERO; //Apply mask after held check so you can require non-allowed keys to be held for some reason let controls=controls.intersection(self.controls_mask); if controls.contains(Controls::MoveForward){ @@ -475,7 +475,10 @@ impl StyleHelper for StyleModifiers{ gameplay_style::HitboxMesh::Box=>PhysicsMesh::unit_cube(), gameplay_style::HitboxMesh::Cylinder=>PhysicsMesh::unit_cylinder(), }; - let transform=mat3::from_diagonal(self.hitbox.halfsize).extend_column(vec3::ZERO); + let transform=integer::Planar64Affine3::new( + mat3::from_diagonal(self.hitbox.halfsize), + vec3::ZERO + ); HitboxMesh::new(mesh,transform) } } @@ -766,9 +769,9 @@ impl TouchingState{ //TODO: trey push solve for contact in &self.contacts{ let n=contact_normal(models,hitbox_mesh,contact); - let d=n.dot128(*velocity); - if d<0{ - *velocity-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64); + let d=n.dot(*velocity); + if d.is_negative(){ + *velocity-=(n*d/n.length_squared()).divide().fix_1(); } } } @@ -776,9 +779,9 @@ impl TouchingState{ //TODO: trey push solve for contact in &self.contacts{ let n=contact_normal(models,hitbox_mesh,contact); - let d=n.dot128(*acceleration); - if d<0{ - *acceleration-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64); + let d=n.dot(*acceleration); + if d.is_negative(){ + *acceleration-=(n*d/n.length_squared()).divide().fix_1(); } } } @@ -855,19 +858,19 @@ impl Body{ //v+a*t==0 //goober code if !self.acceleration.x.is_zero(){ - let t=Time::from(-self.velocity.x/self.acceleration.x); + let t=Time::from(-(self.velocity.x/self.acceleration.x).divide().fix_1()); if t0Result<(),TeleportToSpawnError>{ const EPSILON:Planar64=Planar64::raw((1<<32)/16); let transform=models.get_model_transform(stage.spawn()).ok_or(TeleportToSpawnError::NoModel)?; - let point=transform.vertex.y_axis+Planar64Vec3::new([Planar64::ZERO,style.hitbox.halfsize.y+EPSILON,Planar64::ZERO]); + //TODO: transform.vertex.matrix3.col(1)+transform.vertex.translation + let point=transform.vertex.transform_point3(vec3::Y).fix_1()+Planar64Vec3::new([Planar64::ZERO,style.hitbox.halfsize.y+EPSILON,Planar64::ZERO]); teleport(point,move_state,body,touching,run,mode_state,Some(mode),models,hitbox_mesh,bvh,style,camera,input_state,time); Ok(()) } @@ -1496,7 +1500,7 @@ fn run_teleport_behaviour( } if let Some(&gameplay_attributes::Wormhole{destination_model})=wormhole{ if let (Some(origin),Some(destination))=(models.get_model_transform(model_id),models.get_model_transform(destination_model)){ - let point=body.position-origin.vertex.col(3)+destination.vertex.col(3); + let point=body.position-origin.vertex.translation+destination.vertex.translation; //TODO: camera angles teleport(point,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time); } @@ -1529,7 +1533,7 @@ fn collision_start_contact( Some(gameplay_attributes::ContactingBehaviour::Surf)=>println!("I'm surfing!"), Some(gameplay_attributes::ContactingBehaviour::Cling)=>println!("Unimplemented!"), &Some(gameplay_attributes::ContactingBehaviour::Elastic(elasticity))=>{ - let reflected_velocity=body.velocity+(body.velocity-incident_velocity)*Planar64::raw(elasticity as i64+1); + let reflected_velocity=body.velocity+((body.velocity-incident_velocity)*Planar64::raw(elasticity as i64+1)).fix_1(); set_velocity(body,touching,models,hitbox_mesh,reflected_velocity); }, Some(gameplay_attributes::ContactingBehaviour::Ladder(contacting_ladder))=> @@ -1547,7 +1551,7 @@ fn collision_start_contact( }, Some(gameplay_attributes::ContactingBehaviour::NoJump)=>todo!("nyi"), None=>if let Some(walk_settings)=&style.walk{ - if walk_settings.is_slope_walkable(contact_normal(models,hitbox_mesh,&contact),Planar64Vec3::Y){ + if walk_settings.is_slope_walkable(contact_normal(models,hitbox_mesh,&contact),vec3::Y){ //ground let (gravity,target_velocity)=ground_things(walk_settings,&contact,touching,models,hitbox_mesh,style,camera,input_state); let walk_state=ContactMoveState::ground(walk_settings,body,gravity,target_velocity,contact); @@ -1847,7 +1851,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI //TODO: spawn at the bottom of the start zone plus the hitbox size //TODO: set camera andles to face the same way as the start zone data.models.get_model_transform(mode.get_start().into()).map(|transform| - transform.vertex.col(3) + transform.vertex.translation ) ).unwrap_or(vec3::ZERO); set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time); @@ -1917,7 +1921,7 @@ mod test{ use strafesnet_common::integer::{vec3::{self,int as int3},mat3}; use super::*; fn test_collision_axis_aligned(relative_body:Body,expected_collision_time:Option