Skip to content

Commit

Permalink
Fix angle clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurBrussee committed Dec 3, 2024
1 parent b51fe5f commit 8c04445
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/brush-viewer/src/orbit_controls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::f32;
use std::{f32::consts::PI, ops::Range};
use std::ops::Range;

use glam::{Affine3A, Quat, Vec2, Vec3A};

Expand Down Expand Up @@ -82,9 +82,11 @@ impl OrbitControls {
let delta_x = rotate_velocity.x * std::f32::consts::PI * 2.0 / window.x;
let delta_y = rotate_velocity.y * std::f32::consts::PI / window.y;

self.rotation = Quat::from_rotation_y(yaw + delta_x)
* Quat::from_rotation_x(pitch - delta_y)
* Quat::from_rotation_z(roll);
let yaw = Self::clamp_smooth(yaw + delta_x, self.yaw_range.clone());
let pitch = Self::clamp_smooth(pitch - delta_y, self.pitch_range.clone());

self.rotation =
Quat::from_rotation_y(yaw) * Quat::from_rotation_x(pitch) * Quat::from_rotation_z(roll);

let scaled_pan = pan_velocity * Vec2::new(1.0 / window.x, 1.0 / window.y);

Expand Down

0 comments on commit 8c04445

Please sign in to comment.