From 101c92cba4b3058ed7f12129a5f8a889cb4b7a89 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 11 Oct 2023 21:37:40 -0700 Subject: [PATCH] clarify new as int --- src/integer.rs | 11 +++++++++-- src/physics.rs | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/integer.rs b/src/integer.rs index c08508d..b7d5852 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -214,7 +214,7 @@ pub struct Unit64Mat3{ pub struct Planar64(i64); impl Planar64{ pub const ONE:Self=Self(2<<32); - pub fn new(num:i32)->Self{ + pub fn int(num:i32)->Self{ Self(Self::ONE.0*num as i64) } pub fn from_ratio(num:i64,den:std::num::NonZeroU64)->Self{ @@ -254,6 +254,13 @@ impl std::ops::Div for Planar64{ Planar64(self.0/rhs) } } +impl std::ops::Div for Planar64{ + type Output=Planar64; + #[inline] + fn div(self, rhs: Planar64) -> Self::Output { + Planar64((((self.0 as i128)<<64)/rhs.0 as i128) as i64) + } +} ///[-1.0,1.0] = [-2^32,2^32] @@ -268,7 +275,7 @@ impl Planar64Vec3{ pub const NEG_X:Self=Planar64Vec3(glam::I64Vec3::NEG_X); pub const NEG_Y:Self=Planar64Vec3(glam::I64Vec3::NEG_Y); pub const NEG_Z:Self=Planar64Vec3(glam::I64Vec3::NEG_Z); - pub fn new(x:i32,y:i32,z:i32)->Self{ + pub fn int(x:i32,y:i32,z:i32)->Self{ Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32)) } #[inline] diff --git a/src/physics.rs b/src/physics.rs index 34fc155..759c17e 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -219,12 +219,12 @@ impl std::default::Default for StyleModifiers{ controls_mask: !0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_held: 0, strafe_tick_rate:Ratio64::ONE.rhs_div_ratio(100), - gravity: Planar64Vec3::new(0,100,0), - friction: Planar64::new(12)/10, - walk_accel: Planar64::new(90), - mv: Planar64::new(27)/10, - walkspeed: Planar64::new(18), - hitbox_halfsize: Planar64Vec3::new(2,5,2)/2, + gravity: Planar64Vec3::int(0,100,0), + friction: Planar64::int(12)/10, + walk_accel: Planar64::int(90), + mv: Planar64::int(27)/10, + walkspeed: Planar64::int(18), + hitbox_halfsize: Planar64Vec3::int(2,5,2)/2, } } } @@ -416,8 +416,8 @@ impl Body { impl Default for PhysicsState{ fn default() -> Self { Self{ - spawn_point:Planar64Vec3::new(0,50,0), - body: Body::with_pva(Planar64Vec3::new(0,50,0),Planar64Vec3::new(0,0,0),Planar64Vec3::new(0,-100,0)), + spawn_point:Planar64Vec3::int(0,50,0), + body: Body::with_pva(Planar64Vec3::int(0,50,0),Planar64Vec3::int(0,0,0),Planar64Vec3::int(0,-100,0)), time: Time::ZERO, style:StyleModifiers::default(), grounded: false, @@ -426,7 +426,7 @@ impl Default for PhysicsState{ models: Vec::new(), bvh:crate::bvh::BvhNode::default(), walk: WalkState::new(), - camera: PhysicsCamera::from_offset(Planar64Vec3::new(0,2,0)),//4.5-2.5=2 + camera: PhysicsCamera::from_offset(Planar64Vec3::int(0,2,0)),//4.5-2.5=2 next_mouse: MouseState::default(), controls: 0, world:WorldState{}, @@ -643,7 +643,7 @@ impl PhysicsState { } fn jump(&mut self){ self.grounded=false;//do I need this? - let mut v=self.body.velocity+Planar64Vec3::new(0,715588,0)/20000;//0.715588/2.0*100.0 + let mut v=self.body.velocity+Planar64Vec3::int(0,715588,0)/20000;//0.715588/2.0*100.0 self.contact_constrain_velocity(&mut v); self.body.velocity=v; }