Add controller stick camera rotation
This commit is contained in:
parent
246234574d
commit
bf2e0b1d9f
1 changed files with 10 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cgmath::{vec3, Deg, Matrix4, Vector3};
|
use cgmath::{vec3, Deg, Matrix4, Vector2, Vector3};
|
||||||
|
|
||||||
pub struct CameraControl {
|
pub struct CameraControl {
|
||||||
zoom_levels: Vec<f32>,
|
zoom_levels: Vec<f32>,
|
||||||
|
@ -81,6 +81,15 @@ impl CameraControl {
|
||||||
self.mouse_position_start = None;
|
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);
|
||||||
|
self.arc = Deg((self.arc.0 as i32 + stick.y as i32)
|
||||||
|
.min(CameraControl::MAX_PITCH)
|
||||||
|
.max(CameraControl::MIN_PITCH) as f32);
|
||||||
|
|
||||||
|
self.set_camera_offset(view)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mouse_move(&mut self, x: u32, y: u32, view: &mut View) -> Result<()> {
|
pub fn mouse_move(&mut self, x: u32, y: u32, view: &mut View) -> Result<()> {
|
||||||
self.mouse_position = (x, y);
|
self.mouse_position = (x, y);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue