From b773002bdd0f70e87f85e5c0977d12f5cb653e2d Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 2 Sep 2024 07:37:14 +0200 Subject: [PATCH] Fix camera control with stick --- engine/src/scene/general/camera_control.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/engine/src/scene/general/camera_control.rs b/engine/src/scene/general/camera_control.rs index e3e6dd9..17a2bf7 100644 --- a/engine/src/scene/general/camera_control.rs +++ b/engine/src/scene/general/camera_control.rs @@ -10,6 +10,7 @@ pub struct CameraControl { arc: Deg, mouse_position: (u32, u32), + stick_direction: Vector2, rotation_start: Deg, arc_start: Deg, @@ -32,6 +33,7 @@ impl CameraControl { arc: Deg(50.0), mouse_position: (0, 0), + stick_direction: Vector2::zero(), rotation_start: Deg(0.0), arc_start: Deg(0.0), @@ -81,15 +83,14 @@ impl CameraControl { self.mouse_position_start = None; } - pub fn stick_movement( - &mut self, - stick: Vector2, - factors: Vector2, - view: &mut View, - ) -> Result<()> { - self.rotation = Deg((self.rotation.0 + (stick.x * factors.x)) % 360.0); + pub fn stick_direction(&mut self, stick: Vector2) { + self.stick_direction = stick; + } + + pub fn stick_movement(&mut self, factors: Vector2, view: &mut View) -> Result<()> { + self.rotation = Deg((self.rotation.0 + (self.stick_direction.x * factors.x)) % 360.0); self.arc = Deg(clamp( - self.arc.0 - (stick.y * factors.y), + self.arc.0 - (self.stick_direction.y * factors.y), CameraControl::MIN_PITCH, CameraControl::MAX_PITCH, ));