Fix camera control with stick

This commit is contained in:
hodasemi 2024-09-02 07:37:14 +02:00
parent ba0d30f6d6
commit b773002bdd

View file

@ -10,6 +10,7 @@ pub struct CameraControl {
arc: Deg<f32>,
mouse_position: (u32, u32),
stick_direction: Vector2<f32>,
rotation_start: Deg<f32>,
arc_start: Deg<f32>,
@ -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<f32>,
factors: Vector2<f32>,
view: &mut View,
) -> Result<()> {
self.rotation = Deg((self.rotation.0 + (stick.x * factors.x)) % 360.0);
pub fn stick_direction(&mut self, stick: Vector2<f32>) {
self.stick_direction = stick;
}
pub fn stick_movement(&mut self, factors: Vector2<f32>, 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,
));