use crate::model_physics::{PhysicsMesh,TransformedMesh,MeshQuery}; use strafesnet_common::bvh; use strafesnet_common::aabb; use strafesnet_common::instruction::{self,InstructionEmitter,InstructionConsumer,TimedInstruction}; use strafesnet_common::integer::{self,Time,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64,Ratio64Vec2}; #[derive(Debug)] pub enum PhysicsInstruction { CollisionStart(Collision), CollisionEnd(Collision), StrafeTick, ReachWalkTargetVelocity, // Water, // Spawn( // Option, // bool,//true = Trigger; false = teleport // bool,//true = Force // ) //InputInstructions conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it) Input(PhysicsInputInstruction), } #[derive(Debug)] pub enum PhysicsInputInstruction { ReplaceMouse(MouseState,MouseState), SetNextMouse(MouseState), SetMoveRight(bool), SetMoveUp(bool), SetMoveBack(bool), SetMoveLeft(bool), SetMoveDown(bool), SetMoveForward(bool), SetJump(bool), SetZoom(bool), Reset, Idle, //Idle: there were no input events, but the simulation is safe to advance to this timestep //for interpolation / networking / playback reasons, most playback heads will always want //to be 1 instruction ahead to generate the next state for interpolation. } #[derive(Clone,Hash,Default)] pub struct Body{ pub position:Planar64Vec3,//I64 where 2^32 = 1 u pub velocity:Planar64Vec3,//I64 where 2^32 = 1 u/s pub acceleration:Planar64Vec3,//I64 where 2^32 = 1 u/s/s pub time:Time,//nanoseconds x xxxxD! } impl std::ops::Neg for Body{ type Output=Self; fn neg(self)->Self::Output{ Self{ position:self.position, velocity:-self.velocity, acceleration:self.acceleration, time:-self.time, } } } //hey dumbass just use a delta #[derive(Clone,Debug)] pub struct MouseState { pub pos: glam::IVec2, pub time:Time, } impl Default for MouseState{ fn default() -> Self { Self { time:Time::ZERO, pos:glam::IVec2::ZERO, } } } impl MouseState { pub fn lerp(&self,target:&MouseState,time:Time)->glam::IVec2 { let m0=self.pos.as_i64vec2(); let m1=target.pos.as_i64vec2(); //these are deltas let t1t=(target.time-time).nanos(); let tt0=(time-self.time).nanos(); let dt=(target.time-self.time).nanos(); ((m0*t1t+m1*tt0)/dt).as_ivec2() } } enum JumpDirection{ Exactly(Planar64Vec3), FromContactNormal, } enum WalkEnum{ Reached, Transient(WalkTarget), } struct WalkTarget{ velocity:Planar64Vec3, time:Time, } struct WalkState{ jump_direction:JumpDirection, contact:ContactCollision, state:WalkEnum, } impl WalkEnum{ //args going crazy //(walk_enum,body.acceleration)=with_target_velocity(); fn with_target_velocity(body:&Body,style:&StyleModifiers,velocity:Planar64Vec3,normal:&Planar64Vec3,speed:Planar64,normal_accel:Planar64)->(WalkEnum,Planar64Vec3){ let mut target_diff=velocity-body.velocity; //remove normal component target_diff-=normal.clone()*(normal.dot(target_diff)/normal.dot(normal.clone())); if target_diff==Planar64Vec3::ZERO{ (WalkEnum::Reached,Planar64Vec3::ZERO) }else{ //normal friction acceleration is clippedAcceleration.dot(normal)*friction let diff_len=target_diff.length(); let friction=if diff_len(Self,Planar64Vec3){ let (walk_enum,a)=WalkEnum::with_target_velocity(body,style,velocity,&Planar64Vec3::Y,style.walk_speed,-normal.dot(gravity)); (Self{ state:walk_enum, contact, jump_direction:JumpDirection::Exactly(Planar64Vec3::Y), },a) } fn ladder(body:&Body,style:&StyleModifiers,gravity:Planar64Vec3,velocity:Planar64Vec3,contact:ContactCollision,normal:&Planar64Vec3)->(Self,Planar64Vec3){ let (walk_enum,a)=WalkEnum::with_target_velocity(body,style,velocity,normal,style.ladder_speed,style.ladder_accel); (Self{ state:walk_enum, contact, jump_direction:JumpDirection::FromContactNormal, },a) } } struct Modes{ modes:Vec, mode_from_mode_id:std::collections::HashMap::, } impl Modes{ fn clear(&mut self){ self.modes.clear(); self.mode_from_mode_id.clear(); } fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{ self.modes.get(*self.mode_from_mode_id.get(&mode_id)?) } fn insert(&mut self,temp_map_mode_id:u32,mode:crate::model::ModeDescription){ let mode_id=self.modes.len(); self.mode_from_mode_id.insert(temp_map_mode_id,mode_id); self.modes.push(mode); } } impl Default for Modes{ fn default() -> Self { Self{ modes:Vec::new(), mode_from_mode_id:std::collections::HashMap::new(), } } } #[derive(Default)] struct PhysicsModels{ meshes:Vec, models:Vec, //separate models into Contacting and Intersecting? //wrap model id with ContactingModelId and IntersectingModelId //attributes can be split into contacting and intersecting (this also saves a bit of memory) //can go even further and deduplicate General attributes separately, reconstructing it when queried attributes:Vec, model_id_from_wormhole_id:std::collections::HashMap::, } impl PhysicsModels{ fn clear(&mut self){ self.meshes.clear(); self.models.clear(); self.attributes.clear(); self.model_id_from_wormhole_id.clear(); } fn aabb_list(&self)->Vec{ self.models.iter().map(|model|{ let mut aabb=aabb::Aabb::default(); for pos in self.meshes[model.mesh_id].verts(){ aabb.grow(model.transform.transform_point3(pos)); } aabb }).collect() } //TODO: "statically" verify the maps don't refer to any nonexistant data, if they do delete the references. //then I can make these getter functions unchecked. fn mesh(&self,model_id:usize)->TransformedMesh{ TransformedMesh::new( &self.meshes[self.models[model_id].mesh_id], &self.models[model_id].transform, &self.models[model_id].normal_transform, self.models[model_id].transform_det, ) } fn model(&self,model_id:usize)->&PhysicsModel{ &self.models[model_id] } fn attr(&self,model_id:usize)->&PhysicsCollisionAttributes{ &self.attributes[self.models[model_id].attr_id] } fn get_wormhole_model(&self,wormhole_id:u32)->Option<&PhysicsModel>{ self.models.get(*self.model_id_from_wormhole_id.get(&wormhole_id)?) } fn push_mesh(&mut self,mesh:PhysicsMesh){ self.meshes.push(mesh); } fn push_model(&mut self,model:PhysicsModel)->usize{ let model_id=self.models.len(); self.models.push(model); model_id } fn push_attr(&mut self,attr:PhysicsCollisionAttributes)->usize{ let attr_id=self.attributes.len(); self.attributes.push(attr); attr_id } } #[derive(Clone)] pub struct PhysicsCamera{ //punch: Planar64Vec3, //punch_velocity: Planar64Vec3, sensitivity:Ratio64Vec2,//dots to Angle32 ratios mouse:MouseState,//last seen absolute mouse pos clamped_mouse_pos:glam::IVec2,//angles are calculated from this cumulative value angle_pitch_lower_limit:Angle32, angle_pitch_upper_limit:Angle32, //angle limits could be an enum + struct that defines whether it's limited and selects clamp or wrap depending // enum AngleLimit{ // Unlimited, // Limited{lower:Angle32,upper:Angle32}, // } //pitch_limit:AngleLimit, //yaw_limit:AngleLimit, } impl PhysicsCamera { pub fn move_mouse(&mut self,mouse_pos:glam::IVec2){ let mut unclamped_mouse_pos=self.clamped_mouse_pos+mouse_pos-self.mouse.pos; unclamped_mouse_pos.y=unclamped_mouse_pos.y.clamp( self.sensitivity.y.rhs_div_int(self.angle_pitch_lower_limit.get() as i64) as i32, self.sensitivity.y.rhs_div_int(self.angle_pitch_upper_limit.get() as i64) as i32, ); self.clamped_mouse_pos=unclamped_mouse_pos; } pub fn simulate_move_angles(&self,mouse_pos:glam::IVec2)->glam::Vec2 { let a=-self.sensitivity.mul_int((mouse_pos-self.mouse.pos+self.clamped_mouse_pos).as_i64vec2()); let ax=Angle32::wrap_from_i64(a.x); let ay=Angle32::clamp_from_i64(a.y) //clamp to actual vertical cam limit .clamp(self.angle_pitch_lower_limit,self.angle_pitch_upper_limit); return glam::vec2(ax.into(),ay.into()); } fn simulate_move_rotation(&self,mouse_pos:glam::IVec2)->Planar64Mat3{ let a=-self.sensitivity.mul_int((mouse_pos-self.mouse.pos+self.clamped_mouse_pos).as_i64vec2()); let ax=Angle32::wrap_from_i64(a.x); let ay=Angle32::clamp_from_i64(a.y) //clamp to actual vertical cam limit .clamp(self.angle_pitch_lower_limit,self.angle_pitch_upper_limit); Planar64Mat3::from_rotation_yx(ax,ay) } fn simulate_move_rotation_y(&self,mouse_pos_x:i32)->Planar64Mat3{ let ax=-self.sensitivity.x.mul_int((mouse_pos_x-self.mouse.pos.x+self.clamped_mouse_pos.x) as i64); Planar64Mat3::from_rotation_y(Angle32::wrap_from_i64(ax)) } } impl std::default::Default for PhysicsCamera{ fn default()->Self{ Self{ sensitivity:Ratio64Vec2::ONE*200_000, mouse:MouseState::default(),//t=0 does not cause divide by zero because it's immediately replaced clamped_mouse_pos:glam::IVec2::ZERO, angle_pitch_lower_limit:-Angle32::FRAC_PI_2, angle_pitch_upper_limit:Angle32::FRAC_PI_2, } } } pub struct GameMechanicsState{ stage_id:u32, jump_counts:std::collections::HashMap,//model_id -> jump count next_ordered_checkpoint_id:u32,//which OrderedCheckpoint model_id you must pass next (if 0 you haven't passed OrderedCheckpoint0) unordered_checkpoints:std::collections::HashSet,//hashset of UnorderedCheckpoint model ids } impl std::default::Default for GameMechanicsState{ fn default()->Self{ Self{ stage_id:0, next_ordered_checkpoint_id:0, unordered_checkpoints:std::collections::HashSet::new(), jump_counts:std::collections::HashMap::new(), } } } struct WorldState{} enum JumpCalculation{ Capped,//roblox Energy,//new Linear,//source } enum JumpImpulse{ FromTime(Time),//jump time is invariant across mass and gravity changes FromHeight(Planar64),//jump height is invariant across mass and gravity changes FromDeltaV(Planar64),//jump velocity is invariant across mass and gravity changes FromEnergy(Planar64),// :) } //Jumping acts on dot(walks_state.normal,body.velocity) //Capped means it increases the dot to the cap //Energy means it adds energy //Linear means it linearly adds on enum EnableStrafe{ Always, MaskAny(u32),//hsw, shsw MaskAll(u32), //Function(Boxbool>), } struct StrafeSettings{ enable:EnableStrafe, air_accel_limit:Option, tick_rate:Ratio64, } struct Hitbox{ halfsize:Planar64Vec3, mesh:PhysicsMesh, transform:integer::Planar64Affine3, normal_transform:Planar64Mat3, transform_det:Planar64, } impl Hitbox{ fn new(mesh:PhysicsMesh,transform:integer::Planar64Affine3)->Self{ //calculate extents let mut aabb=aabb::Aabb::default(); for vert in mesh.verts(){ aabb.grow(transform.transform_point3(vert)); } Self{ halfsize:aabb.size()/2, mesh, transform, normal_transform:transform.matrix3.inverse_times_det().transpose(), transform_det:transform.matrix3.determinant(), } } fn from_mesh_scale(mesh:PhysicsMesh,scale:Planar64Vec3)->Self{ let matrix3=Planar64Mat3::from_diagonal(scale); Self{ halfsize:scale, mesh, normal_transform:matrix3.inverse_times_det().transpose(), transform:integer::Planar64Affine3::new(matrix3,Planar64Vec3::ZERO), transform_det:matrix3.determinant(),//scale.x*scale.y*scale.z but whatever } } fn from_mesh_scale_offset(mesh:PhysicsMesh,scale:Planar64Vec3,offset:Planar64Vec3)->Self{ let matrix3=Planar64Mat3::from_diagonal(scale); Self{ halfsize:scale, mesh, normal_transform:matrix3.inverse_times_det().transpose(), transform:integer::Planar64Affine3::new(matrix3,offset), transform_det:matrix3.determinant(), } } fn roblox()->Self{ Self::from_mesh_scale(PhysicsMesh::from(&crate::primitives::unit_cylinder()),Planar64Vec3::int(2,5,2)/2) } fn source()->Self{ Self::from_mesh_scale(PhysicsMesh::from(&crate::primitives::unit_cube()),Planar64Vec3::raw(33<<28,73<<28,33<<28)/2) } #[inline] fn transformed_mesh(&self)->TransformedMesh{ TransformedMesh::new(&self.mesh,&self.transform,&self.normal_transform,self.transform_det) } } struct StyleModifiers{ controls_used:u32,//controls which are allowed to pass into gameplay controls_mask:u32,//controls which are masked from control state (e.g. jump in scroll style) strafe:Option, jump_impulse:JumpImpulse, jump_calculation:JumpCalculation, static_friction:Planar64, kinetic_friction:Planar64, walk_speed:Planar64, walk_accel:Planar64, ladder_speed:Planar64, ladder_accel:Planar64, ladder_dot:Planar64, swim_speed:Planar64, mass:Planar64, mv:Planar64, surf_slope:Option, rocket_force:Option, gravity:Planar64Vec3, hitbox:Hitbox, camera_offset:Planar64Vec3, } impl std::default::Default for StyleModifiers{ fn default()->Self{ Self::roblox_bhop() } } impl StyleModifiers{ const CONTROL_MOVEFORWARD:u32=0b00000001; const CONTROL_MOVEBACK:u32=0b00000010; const CONTROL_MOVERIGHT:u32=0b00000100; const CONTROL_MOVELEFT:u32=0b00001000; const CONTROL_MOVEUP:u32=0b00010000; const CONTROL_MOVEDOWN:u32=0b00100000; const CONTROL_JUMP:u32=0b01000000; const CONTROL_ZOOM:u32=0b10000000; const RIGHT_DIR:Planar64Vec3=Planar64Vec3::X; const UP_DIR:Planar64Vec3=Planar64Vec3::Y; const FORWARD_DIR:Planar64Vec3=Planar64Vec3::NEG_Z; fn neo()->Self{ Self{ controls_used:!0, controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), strafe:Some(StrafeSettings{ enable:EnableStrafe::Always, air_accel_limit:None, tick_rate:Ratio64::new(64,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump_impulse:JumpImpulse::FromEnergy(Planar64::int(512)), jump_calculation:JumpCalculation::Energy, gravity:Planar64Vec3::int(0,-80,0), static_friction:Planar64::int(2), kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static mass:Planar64::int(1), mv:Planar64::int(3), rocket_force:None, walk_speed:Planar64::int(16), walk_accel:Planar64::int(80), ladder_speed:Planar64::int(16), ladder_accel:Planar64::int(160), ladder_dot:(Planar64::int(1)/2).sqrt(), swim_speed:Planar64::int(12), surf_slope:Some(Planar64::raw(7)/8), hitbox:Hitbox::roblox(), camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 } } fn roblox_bhop()->Self{ Self{ controls_used:!0, controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), strafe:Some(StrafeSettings{ enable:EnableStrafe::Always, air_accel_limit:None, tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)), jump_calculation:JumpCalculation::Capped, gravity:Planar64Vec3::int(0,-100,0), static_friction:Planar64::int(2), kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static mass:Planar64::int(1), mv:Planar64::int(27)/10, rocket_force:None, walk_speed:Planar64::int(18), walk_accel:Planar64::int(90), ladder_speed:Planar64::int(18), ladder_accel:Planar64::int(180), ladder_dot:(Planar64::int(1)/2).sqrt(), swim_speed:Planar64::int(12), surf_slope:Some(Planar64::raw(3787805118)),// normal.y=0.75 hitbox:Hitbox::roblox(), camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 } } fn roblox_surf()->Self{ Self{ controls_used:!0, controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), strafe:Some(StrafeSettings{ enable:EnableStrafe::Always, air_accel_limit:None, tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)), jump_calculation:JumpCalculation::Capped, gravity:Planar64Vec3::int(0,-50,0), static_friction:Planar64::int(2), kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static mass:Planar64::int(1), mv:Planar64::int(27)/10, rocket_force:None, walk_speed:Planar64::int(18), walk_accel:Planar64::int(90), ladder_speed:Planar64::int(18), ladder_accel:Planar64::int(180), ladder_dot:(Planar64::int(1)/2).sqrt(), swim_speed:Planar64::int(12), surf_slope:Some(Planar64::raw(3787805118)),// normal.y=0.75 hitbox:Hitbox::roblox(), camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 } } fn source_bhop()->Self{ Self{ controls_used:!0, controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), strafe:Some(StrafeSettings{ enable:EnableStrafe::Always, air_accel_limit:Some(Planar64::raw(150<<28)*100), tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)), jump_calculation:JumpCalculation::Linear, gravity:Planar64Vec3::raw(0,-800<<28,0), static_friction:Planar64::int(2),//? kinetic_friction:Planar64::int(3),//? mass:Planar64::int(1), mv:Planar64::raw(30<<28), rocket_force:None, walk_speed:Planar64::int(18),//? walk_accel:Planar64::int(90),//? ladder_speed:Planar64::int(18),//? ladder_accel:Planar64::int(180),//? ladder_dot:(Planar64::int(1)/2).sqrt(),//? swim_speed:Planar64::int(12),//? surf_slope:Some(Planar64::raw(3787805118)),// normal.y=0.75 hitbox:Hitbox::source(), camera_offset:Planar64Vec3::raw(0,(64<<28)-(73<<27),0), } } fn source_surf()->Self{ Self{ controls_used:!0, controls_mask:!0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), strafe:Some(StrafeSettings{ enable:EnableStrafe::Always, air_accel_limit:Some(Planar64::raw(150<<28)*66), tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(), }), jump_impulse:JumpImpulse::FromHeight(Planar64::raw(52<<28)), jump_calculation:JumpCalculation::Linear, gravity:Planar64Vec3::raw(0,-800<<28,0), static_friction:Planar64::int(2),//? kinetic_friction:Planar64::int(3),//? mass:Planar64::int(1), mv:Planar64::raw(30<<28), rocket_force:None, walk_speed:Planar64::int(18),//? walk_accel:Planar64::int(90),//? ladder_speed:Planar64::int(18),//? ladder_accel:Planar64::int(180),//? ladder_dot:(Planar64::int(1)/2).sqrt(),//? swim_speed:Planar64::int(12),//? surf_slope:Some(Planar64::raw(3787805118)),// normal.y=0.75 hitbox:Hitbox::source(), camera_offset:Planar64Vec3::raw(0,(64<<28)-(73<<27),0), } } fn roblox_rocket()->Self{ Self{ controls_used:!0, controls_mask:!0, strafe:None, jump_impulse:JumpImpulse::FromTime(Time::from_micros(715_588)), jump_calculation:JumpCalculation::Capped, gravity:Planar64Vec3::int(0,-100,0), static_friction:Planar64::int(2), kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static mass:Planar64::int(1), mv:Planar64::int(27)/10, rocket_force:Some(Planar64::int(200)), walk_speed:Planar64::int(18), walk_accel:Planar64::int(90), ladder_speed:Planar64::int(18), ladder_accel:Planar64::int(180), ladder_dot:(Planar64::int(1)/2).sqrt(), swim_speed:Planar64::int(12), surf_slope:Some(Planar64::raw(3787805118)),// normal.y=0.75 hitbox:Hitbox::roblox(), camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 } } fn get_control(&self,control:u32,controls:u32)->bool{ controls&self.controls_mask&control==control } fn allow_strafe(&self,controls:u32)->bool{ //disable strafing according to strafe settings match &self.strafe{ Some(StrafeSettings{enable:EnableStrafe::Always,air_accel_limit:_,tick_rate:_})=>true, &Some(StrafeSettings{enable:EnableStrafe::MaskAny(mask),air_accel_limit:_,tick_rate:_})=>mask&controls!=0, &Some(StrafeSettings{enable:EnableStrafe::MaskAll(mask),air_accel_limit:_,tick_rate:_})=>mask&controls==mask, None=>false, } } fn get_control_dir(&self,controls:u32)->Planar64Vec3{ //don't get fancy just do it let mut control_dir:Planar64Vec3 = Planar64Vec3::ZERO; //Apply mask after held check so you can require non-allowed keys to be held for some reason let controls=controls&self.controls_mask; if controls & Self::CONTROL_MOVEFORWARD == Self::CONTROL_MOVEFORWARD { control_dir+=Self::FORWARD_DIR; } if controls & Self::CONTROL_MOVEBACK == Self::CONTROL_MOVEBACK { control_dir-=Self::FORWARD_DIR; } if controls & Self::CONTROL_MOVELEFT == Self::CONTROL_MOVELEFT { control_dir-=Self::RIGHT_DIR; } if controls & Self::CONTROL_MOVERIGHT == Self::CONTROL_MOVERIGHT { control_dir+=Self::RIGHT_DIR; } if controls & Self::CONTROL_MOVEUP == Self::CONTROL_MOVEUP { control_dir+=Self::UP_DIR; } if controls & Self::CONTROL_MOVEDOWN == Self::CONTROL_MOVEDOWN { control_dir-=Self::UP_DIR; } return control_dir } //fn get_jump_time(&self)->Planar64 //fn get_jump_height(&self)->Planar64 //fn get_jump_energy(&self)->Planar64 fn get_jump_deltav(&self)->Planar64{ match &self.jump_impulse{ &JumpImpulse::FromTime(time)=>self.gravity.length()*(time/2), &JumpImpulse::FromHeight(height)=>(self.gravity.length()*height*2).sqrt(), &JumpImpulse::FromDeltaV(deltav)=>deltav, &JumpImpulse::FromEnergy(energy)=>(energy*2/self.mass).sqrt(), } } fn get_walk_target_velocity(&self,camera:&PhysicsCamera,controls:u32,next_mouse:&MouseState,time:Time,normal:&Planar64Vec3)->Planar64Vec3{ let mut control_dir=self.get_control_dir(controls); if control_dir==Planar64Vec3::ZERO{ return control_dir; } let camera_mat=camera.simulate_move_rotation_y(camera.mouse.lerp(&next_mouse,time).x); control_dir=camera_mat*control_dir; let n=normal.length(); let m=control_dir.length(); let d=normal.dot(control_dir)/m; if dPlanar64Vec3{ let mut control_dir=self.get_control_dir(controls); if control_dir==Planar64Vec3::ZERO{ return control_dir; } let camera_mat=camera.simulate_move_rotation(camera.mouse.lerp(&next_mouse,time)); control_dir=camera_mat*control_dir; let n=normal.length(); let m=control_dir.length(); let mut d=normal.dot(control_dir)/m; if d< -self.ladder_dot*n{ control_dir=Planar64Vec3::Y*m; d=normal.y(); }else if self.ladder_dot*nPlanar64Vec3{ let camera_mat=camera.simulate_move_rotation(camera.mouse.lerp(&next_mouse,time)); camera_mat*self.get_control_dir(controls) } #[inline] fn mesh(&self)->TransformedMesh{ self.hitbox.transformed_mesh() } } enum MoveState{ Air, Walk(WalkState), Water, Ladder(WalkState), } pub struct PhysicsState{ time:Time, pub body:Body, world:WorldState,//currently there is only one state the world can be in game:GameMechanicsState, style:StyleModifiers, touching:TouchingState, //camera must exist in state because wormholes modify the camera, also camera punch camera:PhysicsCamera, pub next_mouse:MouseState,//Where is the mouse headed next controls:u32, move_state:MoveState, models:PhysicsModels, bvh:bvh::BvhNode, modes:Modes, //the spawn point is where you spawn when you load into the map. //This is not the same as Reset which teleports you to Spawn0 spawn_point:Planar64Vec3, //lmao lets go start_time:Option