mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-17 17:05:37 +00:00
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:
@@ -3,6 +3,9 @@
|
|||||||
#include <Common/Math/CQuaternion.h>
|
#include <Common/Math/CQuaternion.h>
|
||||||
#include <Common/Math/MathUtil.h>
|
#include <Common/Math/MathUtil.h>
|
||||||
|
|
||||||
|
const float CCamera::default_move_speed = 1.0f;
|
||||||
|
const float CCamera::default_look_speed = 1.0f;
|
||||||
|
|
||||||
CCamera::CCamera()
|
CCamera::CCamera()
|
||||||
: mYaw(-Math::skHalfPi)
|
: mYaw(-Math::skHalfPi)
|
||||||
{
|
{
|
||||||
@@ -70,7 +73,13 @@ void CCamera::Snap(CVector3f Position)
|
|||||||
|
|
||||||
void CCamera::ProcessKeyInput(FKeyInputs KeyFlags, double DeltaTime)
|
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::W) Zoom(FDeltaTime * 25.f);
|
||||||
if (KeyFlags & EKeyInput::S) Zoom(-FDeltaTime * 25.f);
|
if (KeyFlags & EKeyInput::S) Zoom(-FDeltaTime * 25.f);
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ enum class ECameraMoveMode
|
|||||||
* const function). */
|
* const function). */
|
||||||
class CCamera
|
class CCamera
|
||||||
{
|
{
|
||||||
|
static const float default_move_speed;
|
||||||
|
static const float default_look_speed;
|
||||||
|
|
||||||
ECameraMoveMode mMode{ECameraMoveMode::Free};
|
ECameraMoveMode mMode{ECameraMoveMode::Free};
|
||||||
mutable CVector3f mPosition;
|
mutable CVector3f mPosition;
|
||||||
mutable CVector3f mDirection;
|
mutable CVector3f mDirection;
|
||||||
@@ -37,8 +40,8 @@ class CCamera
|
|||||||
float mPitch = 0.0f;
|
float mPitch = 0.0f;
|
||||||
CVector3f mOrbitTarget;
|
CVector3f mOrbitTarget;
|
||||||
mutable float mOrbitDistance = 0.0f;
|
mutable float mOrbitDistance = 0.0f;
|
||||||
float mMoveSpeed = 1.0f;
|
float mMoveSpeed = default_move_speed;
|
||||||
float mLookSpeed = 1.0f;
|
float mLookSpeed = default_look_speed;
|
||||||
|
|
||||||
mutable CMatrix4f mViewMatrix;
|
mutable CMatrix4f mViewMatrix;
|
||||||
mutable CMatrix4f mProjectionMatrix;
|
mutable CMatrix4f mProjectionMatrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user