Skip to content

Commit

Permalink
get zoom working
Browse files Browse the repository at this point in the history
  • Loading branch information
mkovaxx committed Nov 26, 2023
1 parent 9f1acf3 commit 9f0ccbf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/viewer/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ impl OrbitCamera {
}

/// Zoom in or out, while looking at the same target.
pub fn zoom(&mut self, zoom_delta: f32) {}
pub fn zoom(&mut self, zoom_delta: f32) {
self.radius = f32::max(self.radius * f32::exp(zoom_delta), f32::EPSILON);
}

/// Orbit around the target while keeping the distance.
pub fn rotate(&mut self, rotator: Quat) {
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ impl GameApp for ViewerApp {
self.camera.pan(TOUCHPAD_PAN_MULTIPLIER * camera_space_delta);
},
WindowEvent::TouchpadMagnify { delta, .. } => {
self.camera.zoom(*delta as f32 * TOUCHPAD_ZOOM_MULTIPLIER);
let zoom_delta = *delta as f32 * TOUCHPAD_ZOOM_MULTIPLIER;
self.camera.zoom(-zoom_delta);
},
WindowEvent::KeyboardInput {
input: KeyboardInput { virtual_keycode: Some(keycode), .. },
Expand Down

0 comments on commit 9f0ccbf

Please sign in to comment.