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.
This commit is contained in:
Lioncache
2025-12-08 19:22:47 -05:00
parent 04f73a9687
commit 561b0e08f6
2 changed files with 15 additions and 3 deletions

View File

@@ -3,6 +3,9 @@
#include <Common/Math/CQuaternion.h>
#include <Common/Math/MathUtil.h>
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<float>(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);

View File

@@ -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;