From d0b7c4fefc21fd92bb2ee3d01925c4b4bd66a5e0 Mon Sep 17 00:00:00 2001 From: Ryo Kawaguchi Date: Sat, 9 Sep 2023 18:01:35 +0900 Subject: [PATCH] Adjust the conversion from mouse events to viewport change --- crates/viewer/src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/viewer/src/main.rs b/crates/viewer/src/main.rs index 20e9ac1f..ae530dbd 100644 --- a/crates/viewer/src/main.rs +++ b/crates/viewer/src/main.rs @@ -28,12 +28,13 @@ mod camera; mod edge_drawer; mod surface_drawer; -// Multipliers to convert mouse position deltas to a more sane camera perspective change. +// Multipliers to convert mouse position deltas to a more intuitve camera perspective change. const ZOOM_MULTIPLIER: f32 = 5.0; -const TOUCHPAD_ZOOM_MULTIPLIER: f32 = 2.0; -const ROTATE_MULTIPLIER: f32 = 5.0; -const TOUCHPAD_ROTATE_MULTIPLIER: f32 = 0.05; -const PAN_MULTIPLIER: f32 = 100.0; +const TOUCHPAD_ZOOM_MULTIPLIER: f32 = 0.5; +const ROTATE_MULTIPLIER: f32 = -5.0; +const TOUCHPAD_ROTATE_MULTIPLIER: f32 = -0.05; +const PAN_MULTIPLIER: f32 = 150.0; +const TOUCHPAD_PAN_MULTIPLIER: f32 = 100.0; #[derive(Default)] struct MouseState { @@ -213,9 +214,13 @@ impl GameApp for ViewerApp { self.mouse_state.input(*button, *state) }, WindowEvent::MouseWheel { delta: PixelDelta(delta), .. } => { + // winit can not distinguish mouse wheel and touchpad pan events unfortunately. + // Because of that, we assign pan operation to MouseWheel events. For mice, you + // need to instead use mouse move while holding down the right button. let delta_x = delta.x as f32 / self.client_rect.x; let delta_y = delta.y as f32 / self.client_rect.y; - self.camera.pan(delta_x * PAN_MULTIPLIER, delta_y * PAN_MULTIPLIER); + self.camera + .pan(delta_x * TOUCHPAD_PAN_MULTIPLIER, delta_y * TOUCHPAD_PAN_MULTIPLIER); }, WindowEvent::TouchpadMagnify { delta, .. } => { self.camera.zoom(*delta as f32 * TOUCHPAD_ZOOM_MULTIPLIER);