From 526666651aba468a25add2ab8be28d3386724cd3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 16 Oct 2023 23:20:38 -0700 Subject: [PATCH] implement simulate_move_rotation --- src/integer.rs | 17 +++++++++++++++++ src/physics.rs | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/src/integer.rs b/src/integer.rs index 54652c5..686eac2 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -808,6 +808,23 @@ impl Planar64Mat3{ } } #[inline] + pub fn from_rotation_yx(yaw:Angle32,pitch:Angle32)->Self{ + let xtheta=yaw.0 as f64*ANGLE32_TO_FLOAT64_RADIANS; + let (xs,xc)=xtheta.sin_cos(); + let (xc,xs)=(xc*PLANAR64_ONE_FLOAT64,xs*PLANAR64_ONE_FLOAT64); + let ytheta=pitch.0 as f64*ANGLE32_TO_FLOAT64_RADIANS; + let (ys,yc)=ytheta.sin_cos(); + let (yc,ys)=(yc*PLANAR64_ONE_FLOAT64,ys*PLANAR64_ONE_FLOAT64); + //TODO: fix this rounding towards 0 + let (xc,xs):(i64,i64)=(unsafe{xc.to_int_unchecked()},unsafe{xs.to_int_unchecked()}); + let (yc,ys):(i64,i64)=(unsafe{yc.to_int_unchecked()},unsafe{ys.to_int_unchecked()}); + Self::from_cols( + Planar64Vec3(glam::i64vec3(xc,0,-xs)), + Planar64Vec3(glam::i64vec3(((xs as i128*ys as i128)>>32) as i64,yc,((xc as i128*ys as i128)>>32) as i64)), + Planar64Vec3(glam::i64vec3(((xs as i128*yc as i128)>>32) as i64,-ys,((xc as i128*yc as i128)>>32) as i64)), + ) + } + #[inline] pub fn from_rotation_y(angle:Angle32)->Self{ let theta=angle.0 as f64*ANGLE32_TO_FLOAT64_RADIANS; let (s,c)=theta.sin_cos(); diff --git a/src/physics.rs b/src/physics.rs index fd494d1..d32c084 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -182,6 +182,14 @@ impl PhysicsCamera { .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))