Correctly clamp
This commit is contained in:
parent
bf2e0b1d9f
commit
9c38252fad
1 changed files with 11 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cgmath::{vec3, Deg, Matrix4, Vector2, Vector3};
|
use cgmath::{num_traits::clamp, vec3, Deg, Matrix4, Vector2, Vector3};
|
||||||
|
|
||||||
pub struct CameraControl {
|
pub struct CameraControl {
|
||||||
zoom_levels: Vec<f32>,
|
zoom_levels: Vec<f32>,
|
||||||
|
@ -83,9 +83,11 @@ impl CameraControl {
|
||||||
|
|
||||||
pub fn stick_movement(&mut self, stick: Vector2<f32>, view: &mut View) -> Result<()> {
|
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);
|
self.rotation = Deg(((self.rotation.0 + stick.x) as u32 % 360) as f32);
|
||||||
self.arc = Deg((self.arc.0 as i32 + stick.y as i32)
|
self.arc = Deg(clamp(
|
||||||
.min(CameraControl::MAX_PITCH)
|
self.arc.0 + stick.y,
|
||||||
.max(CameraControl::MIN_PITCH) as f32);
|
CameraControl::MIN_PITCH as f32,
|
||||||
|
CameraControl::MAX_PITCH as f32,
|
||||||
|
));
|
||||||
|
|
||||||
self.set_camera_offset(view)
|
self.set_camera_offset(view)
|
||||||
}
|
}
|
||||||
|
@ -98,9 +100,11 @@ impl CameraControl {
|
||||||
let y_diff = ((start_y as i32 - y as i32) as f32 * CameraControl::SCALE) as i32;
|
let y_diff = ((start_y as i32 - y as i32) as f32 * CameraControl::SCALE) as i32;
|
||||||
|
|
||||||
self.rotation = Deg(((self.rotation_start.0 as i32 + x_diff) % 360) as f32);
|
self.rotation = Deg(((self.rotation_start.0 as i32 + x_diff) % 360) as f32);
|
||||||
self.arc = Deg((self.arc_start.0 as i32 - y_diff)
|
self.arc = Deg(clamp(
|
||||||
.min(CameraControl::MAX_PITCH)
|
self.arc_start.0 as i32 - y_diff,
|
||||||
.max(CameraControl::MIN_PITCH) as f32);
|
CameraControl::MIN_PITCH,
|
||||||
|
CameraControl::MAX_PITCH,
|
||||||
|
) as f32);
|
||||||
|
|
||||||
self.set_camera_offset(view)?;
|
self.set_camera_offset(view)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue