clarify new as int

This commit is contained in:
Quaternions 2023-10-11 21:37:40 -07:00
parent 54ec21c490
commit 101c92cba4
2 changed files with 19 additions and 12 deletions

View File

@ -214,7 +214,7 @@ pub struct Unit64Mat3{
pub struct Planar64(i64); pub struct Planar64(i64);
impl Planar64{ impl Planar64{
pub const ONE:Self=Self(2<<32); 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) Self(Self::ONE.0*num as i64)
} }
pub fn from_ratio(num:i64,den:std::num::NonZeroU64)->Self{ pub fn from_ratio(num:i64,den:std::num::NonZeroU64)->Self{
@ -254,6 +254,13 @@ impl std::ops::Div<i64> for Planar64{
Planar64(self.0/rhs) Planar64(self.0/rhs)
} }
} }
impl std::ops::Div<Planar64> 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] ///[-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_X:Self=Planar64Vec3(glam::I64Vec3::NEG_X);
pub const NEG_Y:Self=Planar64Vec3(glam::I64Vec3::NEG_Y); pub const NEG_Y:Self=Planar64Vec3(glam::I64Vec3::NEG_Y);
pub const NEG_Z:Self=Planar64Vec3(glam::I64Vec3::NEG_Z); 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)) Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32))
} }
#[inline] #[inline]

View File

@ -219,12 +219,12 @@ impl std::default::Default for StyleModifiers{
controls_mask: !0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN), controls_mask: !0,//&!(Self::CONTROL_MOVEUP|Self::CONTROL_MOVEDOWN),
controls_held: 0, controls_held: 0,
strafe_tick_rate:Ratio64::ONE.rhs_div_ratio(100), strafe_tick_rate:Ratio64::ONE.rhs_div_ratio(100),
gravity: Planar64Vec3::new(0,100,0), gravity: Planar64Vec3::int(0,100,0),
friction: Planar64::new(12)/10, friction: Planar64::int(12)/10,
walk_accel: Planar64::new(90), walk_accel: Planar64::int(90),
mv: Planar64::new(27)/10, mv: Planar64::int(27)/10,
walkspeed: Planar64::new(18), walkspeed: Planar64::int(18),
hitbox_halfsize: Planar64Vec3::new(2,5,2)/2, hitbox_halfsize: Planar64Vec3::int(2,5,2)/2,
} }
} }
} }
@ -416,8 +416,8 @@ impl Body {
impl Default for PhysicsState{ impl Default for PhysicsState{
fn default() -> Self { fn default() -> Self {
Self{ Self{
spawn_point:Planar64Vec3::new(0,50,0), spawn_point:Planar64Vec3::int(0,50,0),
body: Body::with_pva(Planar64Vec3::new(0,50,0),Planar64Vec3::new(0,0,0),Planar64Vec3::new(0,-100,0)), body: Body::with_pva(Planar64Vec3::int(0,50,0),Planar64Vec3::int(0,0,0),Planar64Vec3::int(0,-100,0)),
time: Time::ZERO, time: Time::ZERO,
style:StyleModifiers::default(), style:StyleModifiers::default(),
grounded: false, grounded: false,
@ -426,7 +426,7 @@ impl Default for PhysicsState{
models: Vec::new(), models: Vec::new(),
bvh:crate::bvh::BvhNode::default(), bvh:crate::bvh::BvhNode::default(),
walk: WalkState::new(), 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(), next_mouse: MouseState::default(),
controls: 0, controls: 0,
world:WorldState{}, world:WorldState{},
@ -643,7 +643,7 @@ impl PhysicsState {
} }
fn jump(&mut self){ fn jump(&mut self){
self.grounded=false;//do I need this? 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.contact_constrain_velocity(&mut v);
self.body.velocity=v; self.body.velocity=v;
} }