This commit is contained in:
Quaternions 2024-09-10 14:41:47 -07:00
parent 18fdbb9a99
commit e845ce246a
2 changed files with 79 additions and 72 deletions

View File

@ -1,6 +1,6 @@
const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16 const VALVE_SCALE:Planar64=Planar64::raw(1<<28);// 1/16
use crate::integer::{Time,Ratio64,Planar64,Planar64Vec3,WideMul,WideDot}; use crate::integer::{int,int3,Time,Ratio64,Planar64,Planar64Vec3};
use crate::controls_bitflag::Controls; use crate::controls_bitflag::Controls;
#[derive(Clone,Debug)] #[derive(Clone,Debug)]
@ -69,10 +69,10 @@ impl JumpImpulse{
&JumpImpulse::Height(height)=>{ &JumpImpulse::Height(height)=>{
//height==-v.y*v.y/(2*g.y); //height==-v.y*v.y/(2*g.y);
//use energy to determine max height //use energy to determine max height
let g=gravity.wide_length(); let g=gravity.length_squared().sqrt().halve_precision();
let v_g=gravity.wide_dot(velocity); let v_g=gravity.dot(velocity);
//do it backwards //do it backwards
velocity-gravity.with_length(((v_g.wide_mul(v_g)+g.wide_mul(height).wide_mul(2)).sqrt()+v_g).ratio(g)) velocity-(*gravity*((v_g*v_g+g*height*(fixed_wide::fixed::Fixed::<2,64>::ONE*2)).sqrt().halve_precision()+v_g)/g).divide()
}, },
&JumpImpulse::Linear(jump_speed)=>velocity+jump_dir.with_length(jump_speed), &JumpImpulse::Linear(jump_speed)=>velocity+jump_dir.with_length(jump_speed),
&JumpImpulse::Energy(energy)=>{ &JumpImpulse::Energy(energy)=>{
@ -317,14 +317,14 @@ impl WalkSettings{
} }
let m=control_dir.length(); let m=control_dir.length();
let n=normal.length(); let n=normal.length();
let nm=n.wide_mul(m); let nm=n*m;
let d=normal.wide_dot(control_dir); let d=normal.dot(control_dir);
if d<nm{ if d<nm{
let cr=normal.cross(control_dir); let cr=normal.cross(control_dir);
if cr==Planar64Vec3::ZERO{ if cr==Planar64Vec3::ZERO{
Planar64Vec3::ZERO Planar64Vec3::ZERO
}else{ }else{
(cr.wide_cross(normal).wide_mul(self.accelerate.topspeed)/(n.wide_mul((nm*nm-d*d).sqrt()))).narrow() (cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt()))
} }
}else{ }else{
Planar64Vec3::ZERO Planar64Vec3::ZERO
@ -360,10 +360,10 @@ impl LadderSettings{
let mut d=normal.dot(control_dir)/m; let mut d=normal.dot(control_dir)/m;
if d< -self.dot*n{ if d< -self.dot*n{
control_dir=Planar64Vec3::Y*m; control_dir=Planar64Vec3::Y*m;
d=normal.y(); d=normal.y;
}else if self.dot*n<d{ }else if self.dot*n<d{
control_dir=Planar64Vec3::NEG_Y*m; control_dir=Planar64Vec3::NEG_Y*m;
d=-normal.y(); d=-normal.y;
} }
//n=d if you are standing on top of a ladder and press E. //n=d if you are standing on top of a ladder and press E.
//two fixes: //two fixes:
@ -400,13 +400,13 @@ pub struct Hitbox{
impl Hitbox{ impl Hitbox{
pub fn roblox()->Self{ pub fn roblox()->Self{
Self{ Self{
halfsize:Planar64Vec3::int(2,5,2)/2, halfsize:int3(2,5,2)/2,
mesh:HitboxMesh::Cylinder, mesh:HitboxMesh::Cylinder,
} }
} }
pub fn source()->Self{ pub fn source()->Self{
Self{ Self{
halfsize:Planar64Vec3::int(33,73,33)/2*VALVE_SCALE, halfsize:int3(33,73,33)/2*VALVE_SCALE,
mesh:HitboxMesh::Box, mesh:HitboxMesh::Box,
} }
} }
@ -424,38 +424,38 @@ impl StyleModifiers{
strafe:Some(StrafeSettings{ strafe:Some(StrafeSettings{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:None, air_accel_limit:None,
mv:Planar64::int(3), mv:int(3),
tick_rate:Ratio64::new(64,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(64,Time::ONE_SECOND.nanos() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Energy(Planar64::int(512)), impulse:JumpImpulse::Energy(int(512)),
calculation:JumpCalculation::JumpThenBoost, calculation:JumpCalculation::JumpThenBoost,
limit_minimum:false, limit_minimum:false,
}), }),
gravity:Planar64Vec3::int(0,-80,0), gravity:int3(0,-80,0),
mass:Planar64::int(1), mass:int(1),
rocket:None, rocket:None,
walk:Some(WalkSettings{ walk:Some(WalkSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(16), topspeed:int(16),
accel:Planar64::int(80), accel:int(80),
}, },
static_friction:Planar64::int(2), static_friction:int(2),
kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static kinetic_friction:int(3),//unrealistic: kinetic friction is typically lower than static
surf_dot:Planar64::int(3)/4, surf_dot:int(3)/4,
}), }),
ladder:Some(LadderSettings{ ladder:Some(LadderSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(16), topspeed:int(16),
accel:Planar64::int(160), accel:int(160),
}, },
dot:(Planar64::int(1)/2).sqrt(), dot:(int(1)/2).sqrt(),
}), }),
swim:Some(PropulsionSettings{ swim:Some(PropulsionSettings{
magnitude:Planar64::int(12), magnitude:int(12),
}), }),
hitbox:Hitbox::roblox(), hitbox:Hitbox::roblox(),
camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 camera_offset:int3(0,2,0),//4.5-2.5=2
} }
} }
@ -466,7 +466,7 @@ impl StyleModifiers{
strafe:Some(StrafeSettings{ strafe:Some(StrafeSettings{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:None, air_accel_limit:None,
mv:Planar64::int(27)/10, mv:int(27)/10,
tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
@ -474,35 +474,35 @@ impl StyleModifiers{
calculation:JumpCalculation::Max, calculation:JumpCalculation::Max,
limit_minimum:true, limit_minimum:true,
}), }),
gravity:Planar64Vec3::int(0,-100,0), gravity:int3(0,-100,0),
mass:Planar64::int(1), mass:int(1),
rocket:None, rocket:None,
walk:Some(WalkSettings{ walk:Some(WalkSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18), topspeed:int(18),
accel:Planar64::int(90), accel:int(90),
}, },
static_friction:Planar64::int(2), static_friction:int(2),
kinetic_friction:Planar64::int(3),//unrealistic: kinetic friction is typically lower than static kinetic_friction:int(3),//unrealistic: kinetic friction is typically lower than static
surf_dot:Planar64::int(3)/4,// normal.y=0.75 surf_dot:int(3)/4,// normal.y=0.75
}), }),
ladder:Some(LadderSettings{ ladder:Some(LadderSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18), topspeed:int(18),
accel:Planar64::int(180), accel:int(180),
}, },
dot:(Planar64::int(1)/2).sqrt(), dot:(int(1)/2).sqrt(),
}), }),
swim:Some(PropulsionSettings{ swim:Some(PropulsionSettings{
magnitude:Planar64::int(12), magnitude:int(12),
}), }),
hitbox:Hitbox::roblox(), hitbox:Hitbox::roblox(),
camera_offset:Planar64Vec3::int(0,2,0),//4.5-2.5=2 camera_offset:int3(0,2,0),//4.5-2.5=2
} }
} }
pub fn roblox_surf()->Self{ pub fn roblox_surf()->Self{
Self{ Self{
gravity:Planar64Vec3::int(0,-50,0), gravity:int3(0,-50,0),
..Self::roblox_bhop() ..Self::roblox_bhop()
} }
} }
@ -510,7 +510,7 @@ impl StyleModifiers{
Self{ Self{
strafe:None, strafe:None,
rocket:Some(PropulsionSettings{ rocket:Some(PropulsionSettings{
magnitude:Planar64::int(200), magnitude:int(200),
}), }),
..Self::roblox_bhop() ..Self::roblox_bhop()
} }
@ -527,34 +527,34 @@ impl StyleModifiers{
tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(100,Time::ONE_SECOND.nanos() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Height(Planar64::int(52)*VALVE_SCALE), impulse:JumpImpulse::Height(int(52)*VALVE_SCALE),
calculation:JumpCalculation::JumpThenBoost, calculation:JumpCalculation::JumpThenBoost,
limit_minimum:true, limit_minimum:true,
}), }),
gravity:Planar64Vec3::int(0,-800,0)*VALVE_SCALE, gravity:int3(0,-800,0)*VALVE_SCALE,
mass:Planar64::int(1), mass:int(1),
rocket:None, rocket:None,
walk:Some(WalkSettings{ walk:Some(WalkSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18),//? topspeed:int(18),//?
accel:Planar64::int(90),//? accel:int(90),//?
}, },
static_friction:Planar64::int(2),//? static_friction:int(2),//?
kinetic_friction:Planar64::int(3),//? kinetic_friction:int(3),//?
surf_dot:Planar64::int(3)/4,// normal.y=0.75 surf_dot:int(3)/4,// normal.y=0.75
}), }),
ladder:Some(LadderSettings{ ladder:Some(LadderSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18),//? topspeed:int(18),//?
accel:Planar64::int(180),//? accel:int(180),//?
}, },
dot:(Planar64::int(1)/2).sqrt(),//? dot:(int(1)/2).sqrt(),//?
}), }),
swim:Some(PropulsionSettings{ swim:Some(PropulsionSettings{
magnitude:Planar64::int(12),//? magnitude:int(12),//?
}), }),
hitbox:Hitbox::source(), hitbox:Hitbox::source(),
camera_offset:(Planar64Vec3::int(0,64,0)-Planar64Vec3::int(0,73,0)/2)*VALVE_SCALE, camera_offset:(int3(0,64,0)-int3(0,73,0)/2)*VALVE_SCALE,
} }
} }
pub fn source_surf()->Self{ pub fn source_surf()->Self{
@ -563,39 +563,39 @@ impl StyleModifiers{
controls_mask_state:Controls::all(), controls_mask_state:Controls::all(),
strafe:Some(StrafeSettings{ strafe:Some(StrafeSettings{
enable:ControlsActivation::full_2d(), enable:ControlsActivation::full_2d(),
air_accel_limit:Some(Planar64::int(150)*66*VALVE_SCALE), air_accel_limit:Some(int(150)*66*VALVE_SCALE),
mv:Planar64::int(30)*VALVE_SCALE, mv:int(30)*VALVE_SCALE,
tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(), tick_rate:Ratio64::new(66,Time::ONE_SECOND.nanos() as u64).unwrap(),
}), }),
jump:Some(JumpSettings{ jump:Some(JumpSettings{
impulse:JumpImpulse::Height(Planar64::int(52)*VALVE_SCALE), impulse:JumpImpulse::Height(int(52)*VALVE_SCALE),
calculation:JumpCalculation::JumpThenBoost, calculation:JumpCalculation::JumpThenBoost,
limit_minimum:true, limit_minimum:true,
}), }),
gravity:Planar64Vec3::int(0,-800,0)*VALVE_SCALE, gravity:int3(0,-800,0)*VALVE_SCALE,
mass:Planar64::int(1), mass:int(1),
rocket:None, rocket:None,
walk:Some(WalkSettings{ walk:Some(WalkSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18),//? topspeed:int(18),//?
accel:Planar64::int(90),//? accel:int(90),//?
}, },
static_friction:Planar64::int(2),//? static_friction:int(2),//?
kinetic_friction:Planar64::int(3),//? kinetic_friction:int(3),//?
surf_dot:Planar64::int(3)/4,// normal.y=0.75 surf_dot:int(3)/4,// normal.y=0.75
}), }),
ladder:Some(LadderSettings{ ladder:Some(LadderSettings{
accelerate:AccelerateSettings{ accelerate:AccelerateSettings{
topspeed:Planar64::int(18),//? topspeed:int(18),//?
accel:Planar64::int(180),//? accel:int(180),//?
}, },
dot:(Planar64::int(1)/2).sqrt(),//? dot:(int(1)/2).sqrt(),//?
}), }),
swim:Some(PropulsionSettings{ swim:Some(PropulsionSettings{
magnitude:Planar64::int(12),//? magnitude:int(12),//?
}), }),
hitbox:Hitbox::source(), hitbox:Hitbox::source(),
camera_offset:(Planar64Vec3::int(0,64,0)-Planar64Vec3::int(0,73,0)/2)*VALVE_SCALE, camera_offset:(int3(0,64,0)-int3(0,73,0)/2)*VALVE_SCALE,
} }
} }
} }

View File

@ -42,7 +42,7 @@ impl Time{
impl From<Planar64> for Time{ impl From<Planar64> for Time{
#[inline] #[inline]
fn from(value:Planar64)->Self{ fn from(value:Planar64)->Self{
Time(value.wide_mul(Planar64::raw(1_000_000_000)) as i64) Time((value*Planar64::raw(1_000_000_000)).to_bits().to_bits().digits()[0] as i64)
} }
} }
impl std::fmt::Display for Time{ impl std::fmt::Display for Time{
@ -432,10 +432,17 @@ pub type Planar64Vec3=linear_ops::types::Vector3<Planar64>;
pub type Planar64Mat3=linear_ops::types::Matrix3<Planar64>; pub type Planar64Mat3=linear_ops::types::Matrix3<Planar64>;
pub type Planar64Affine3=linear_ops::types::Matrix4x3<Planar64>; pub type Planar64Affine3=linear_ops::types::Matrix4x3<Planar64>;
pub fn int(value:i32)->Planar64{
Planar64::from(value)
}
pub fn int3(x:i32,y:i32,z:i32)->Planar64Vec3{
Planar64Vec3::new([Planar64::from(x),Planar64::from(y),Planar64::from(z)])
}
#[test] #[test]
fn test_sqrt(){ fn test_sqrt(){
let r=Planar64::int(400); let r=int(400);
assert_eq!(1717986918400,r.get()); assert_eq!(r,Planar64::raw(1717986918400));
let s=r.sqrt(); let s=r.sqrt();
assert_eq!(85899345920,s.get()); assert_eq!(s,Planar64::raw(85899345920));
} }