Rename CameraFreeLook variable to `look`

main
copygirl 1 week ago
parent 92b5fca3bb
commit 69ae279f76
  1. 18
      src/free_camera.rs

@ -40,7 +40,7 @@ pub fn camera_free_look(
camera: Single<(&mut Transform, &mut CameraFreeLook)>, camera: Single<(&mut Transform, &mut CameraFreeLook)>,
) { ) {
let (window, mut cursor) = window.into_inner(); let (window, mut cursor) = window.into_inner();
let (mut transform, mut camera) = camera.into_inner(); let (mut transform, mut look) = camera.into_inner();
if !window.focused || key_input.just_pressed(KeyCode::Escape) { if !window.focused || key_input.just_pressed(KeyCode::Escape) {
cursor.grab_mode = CursorGrabMode::None; cursor.grab_mode = CursorGrabMode::None;
@ -54,19 +54,19 @@ pub fn camera_free_look(
if cursor.grab_mode == CursorGrabMode::Locked { if cursor.grab_mode == CursorGrabMode::Locked {
// Ensure the yaw and pitch are initialized once // Ensure the yaw and pitch are initialized once
// from the camera transform's current rotation. // from the camera transform's current rotation.
if !camera.initialized { if !look.initialized {
(camera.yaw, camera.pitch, _) = transform.rotation.to_euler(EulerRot::YXZ); (look.yaw, look.pitch, _) = transform.rotation.to_euler(EulerRot::YXZ);
camera.initialized = true; look.initialized = true;
} }
// Update the current camera state's internal yaw and pitch. // Update the current camera state's internal yaw and pitch.
let motion = accumulated_mouse_motion.delta * camera.sensitivity; let motion = accumulated_mouse_motion.delta * look.sensitivity;
let (min, max) = camera.pitch_limit.clone().into_inner(); let (min, max) = look.pitch_limit.clone().into_inner();
camera.yaw = (camera.yaw - motion.x).rem_euclid(TAU); // keep within 0°..360° look.yaw = (look.yaw - motion.x).rem_euclid(TAU); // keep within 0°..360°
camera.pitch = (camera.pitch - motion.y).clamp(min, max); look.pitch = (look.pitch - motion.y).clamp(min, max);
// Override the camera transform's rotation. // Override the camera transform's rotation.
transform.rotation = Quat::from_euler(EulerRot::ZYX, 0.0, camera.yaw, camera.pitch); transform.rotation = Quat::from_euler(EulerRot::ZYX, 0.0, look.yaw, look.pitch);
} }
} }

Loading…
Cancel
Save