Add controller stick camera rotation

This commit is contained in:
hodasemi 2024-09-01 08:51:15 +02:00
parent 246234574d
commit bf2e0b1d9f

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use anyhow::Result;
use cgmath::{vec3, Deg, Matrix4, Vector3};
use cgmath::{vec3, Deg, Matrix4, Vector2, Vector3};
pub struct CameraControl {
zoom_levels: Vec<f32>,
@ -81,6 +81,15 @@ 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);
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<()> {
self.mouse_position = (x, y);