From 561b0e08f695bd3630734dbab83c2aaebdad9608 Mon Sep 17 00:00:00 2001 From: Lioncache Date: Mon, 8 Dec 2025 19:22:47 -0500 Subject: [PATCH] CCamera: Allow toggleable camera movement speed In a lot of 3D scene editors, it's quite common to have a default speed that the camera can move at, plus a quicker one when shift (or some other kind of keybind is held. We can replicate this here as a fixed increment, but in the future this could also potentially be a configurable UI setting. Just makes the viewport expectations a little more natural like Blender or 3DS Max. --- src/Core/Render/CCamera.cpp | 11 ++++++++++- src/Core/Render/CCamera.h | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Core/Render/CCamera.cpp b/src/Core/Render/CCamera.cpp index aae5e445..9be7b547 100644 --- a/src/Core/Render/CCamera.cpp +++ b/src/Core/Render/CCamera.cpp @@ -3,6 +3,9 @@ #include #include +const float CCamera::default_move_speed = 1.0f; +const float CCamera::default_look_speed = 1.0f; + CCamera::CCamera() : mYaw(-Math::skHalfPi) { @@ -70,7 +73,13 @@ void CCamera::Snap(CVector3f Position) void CCamera::ProcessKeyInput(FKeyInputs KeyFlags, double DeltaTime) { - float FDeltaTime = (float) DeltaTime; + const auto FDeltaTime = static_cast(DeltaTime); + + // Generally the camera moves at a fixed rate without any modifier + // key held down. However in a lot of editors, it's a little more intuitive + // to allow holding down e.g. Shift for a toggleable speed. + const auto is_shift_pressed = (KeyFlags & EKeyInput::Shift) != 0; + mMoveSpeed = is_shift_pressed ? 2.0f : default_move_speed; if (KeyFlags & EKeyInput::W) Zoom(FDeltaTime * 25.f); if (KeyFlags & EKeyInput::S) Zoom(-FDeltaTime * 25.f); diff --git a/src/Core/Render/CCamera.h b/src/Core/Render/CCamera.h index 4fc995c3..438edee1 100644 --- a/src/Core/Render/CCamera.h +++ b/src/Core/Render/CCamera.h @@ -26,6 +26,9 @@ enum class ECameraMoveMode * const function). */ class CCamera { + static const float default_move_speed; + static const float default_look_speed; + ECameraMoveMode mMode{ECameraMoveMode::Free}; mutable CVector3f mPosition; mutable CVector3f mDirection; @@ -37,8 +40,8 @@ class CCamera float mPitch = 0.0f; CVector3f mOrbitTarget; mutable float mOrbitDistance = 0.0f; - float mMoveSpeed = 1.0f; - float mLookSpeed = 1.0f; + float mMoveSpeed = default_move_speed; + float mLookSpeed = default_look_speed; mutable CMatrix4f mViewMatrix; mutable CMatrix4f mProjectionMatrix;