From 4b13530e4acf84062848287d3105b078d1e5d8fa Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 30 Mar 2024 19:14:59 +0100 Subject: [PATCH] implement rotation key "r" --- README.md | 1 + src/camera.rs | 16 +++++++++++++--- src/settings.rs | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 83316a7..e6e623b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Key features: - t: toggle music (NOTE: currently no music is included in the git repo) - m: mute sound effects - q: enter/exit vehicle +- r: rotate (hold r while moving the mouse) - f: toggle 3rd person view - TAB: toggle augmented reality overlay (HUD, low-light amplifier) diff --git a/src/camera.rs b/src/camera.rs index 561b3ff..638a3ed 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -224,9 +224,19 @@ fn apply_input_to_player( if mouse_delta != Vec2::ZERO { // Apply look update - let pitch = (mouse_delta.y * RADIANS_PER_DOT * settings.mouse_sensitivity).clamp(-PI / 2., PI / 2.); - let yaw = mouse_delta.x * RADIANS_PER_DOT * settings.mouse_sensitivity; - player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, 0.0, -yaw, pitch).normalize(); + let mouse_y_movement = (mouse_delta.y * RADIANS_PER_DOT * settings.mouse_sensitivity).clamp(-PI / 2., PI / 2.); + let mouse_x_movement = -mouse_delta.x * RADIANS_PER_DOT * settings.mouse_sensitivity; + let (pitch, yaw, rot); + if key_input.pressed(settings.key_rotate) { + pitch = 0.0; + yaw = 0.0; + rot = mouse_x_movement; + } else { + pitch = mouse_y_movement; + yaw = mouse_x_movement; + rot = 0.0; + } + player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, rot, yaw, pitch).normalize(); } if let Ok(sink) = thruster_sound_controller.get_single() { diff --git a/src/settings.rs b/src/settings.rs index 6a9e6d3..9cd01aa 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -27,6 +27,7 @@ pub struct Settings { pub key_interact: KeyCode, pub key_vehicle: KeyCode, pub key_camera: KeyCode, + pub key_rotate: KeyCode, pub key_reply1: KeyCode, pub key_reply2: KeyCode, pub key_reply3: KeyCode, @@ -76,6 +77,7 @@ impl Default for Settings { key_interact: KeyCode::KeyE, key_vehicle: KeyCode::KeyQ, key_camera: KeyCode::KeyF, + key_rotate: KeyCode::KeyR, key_reply1: KeyCode::Digit1, key_reply2: KeyCode::Digit2, key_reply3: KeyCode::Digit3,