Enforce f32 calculations
This commit is contained in:
parent
9c38252fad
commit
f8d029b18c
1 changed files with 17 additions and 12 deletions
|
@ -18,8 +18,8 @@ pub struct CameraControl {
|
|||
|
||||
impl CameraControl {
|
||||
const SCALE: f32 = 0.3;
|
||||
const MIN_PITCH: i32 = 10;
|
||||
const MAX_PITCH: i32 = 80;
|
||||
const MIN_PITCH: f32 = 10.0;
|
||||
const MAX_PITCH: f32 = 80.0;
|
||||
|
||||
pub fn new(view: &mut View) -> Result<Self> {
|
||||
let me = Self {
|
||||
|
@ -81,12 +81,17 @@ impl CameraControl {
|
|||
self.mouse_position_start = None;
|
||||
}
|
||||
|
||||
pub fn stick_movement(&mut self, stick: Vector2<f32>, view: &mut View) -> Result<()> {
|
||||
self.rotation = Deg(((self.rotation.0 + stick.x) as u32 % 360) as f32);
|
||||
pub fn stick_movement(
|
||||
&mut self,
|
||||
stick: Vector2<f32>,
|
||||
factors: Vector2<f32>,
|
||||
view: &mut View,
|
||||
) -> Result<()> {
|
||||
self.rotation = Deg((self.rotation.0 + (stick.x * factors.x)) % 360.0);
|
||||
self.arc = Deg(clamp(
|
||||
self.arc.0 + stick.y,
|
||||
CameraControl::MIN_PITCH as f32,
|
||||
CameraControl::MAX_PITCH as f32,
|
||||
self.arc.0 + (stick.y * factors.y),
|
||||
CameraControl::MIN_PITCH,
|
||||
CameraControl::MAX_PITCH,
|
||||
));
|
||||
|
||||
self.set_camera_offset(view)
|
||||
|
@ -96,15 +101,15 @@ impl CameraControl {
|
|||
self.mouse_position = (x, y);
|
||||
|
||||
if let Some((start_x, start_y)) = self.mouse_position_start {
|
||||
let x_diff = ((start_x as i32 - x as i32) as f32 * CameraControl::SCALE) as i32;
|
||||
let y_diff = ((start_y as i32 - y as i32) as f32 * CameraControl::SCALE) as i32;
|
||||
let x_diff = (start_x as i32 - x as i32) as f32 * CameraControl::SCALE;
|
||||
let y_diff = (start_y as i32 - y as i32) as f32 * CameraControl::SCALE;
|
||||
|
||||
self.rotation = Deg(((self.rotation_start.0 as i32 + x_diff) % 360) as f32);
|
||||
self.rotation = Deg((self.rotation_start.0 + x_diff) % 360.0);
|
||||
self.arc = Deg(clamp(
|
||||
self.arc_start.0 as i32 - y_diff,
|
||||
self.arc_start.0 - y_diff,
|
||||
CameraControl::MIN_PITCH,
|
||||
CameraControl::MAX_PITCH,
|
||||
) as f32);
|
||||
));
|
||||
|
||||
self.set_camera_offset(view)?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue