FreeLook: update camera and manager to use a delta time for movement (in case we decide to move this somewhere else in the future)

This commit is contained in:
iwubcode 2021-03-17 20:51:35 -05:00
parent f1ce921844
commit 425ee13d35
3 changed files with 21 additions and 20 deletions

View File

@ -222,40 +222,40 @@ void FreeLookController::Update()
g_freelook_camera.Rotate(gyro_motion_quat); g_freelook_camera.Rotate(gyro_motion_quat);
if (m_move_buttons->controls[MoveButtons::Up]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Up]->GetState<bool>())
g_freelook_camera.MoveVertical(-g_freelook_camera.GetSpeed()); g_freelook_camera.MoveVertical(-g_freelook_camera.GetSpeed() * dt);
if (m_move_buttons->controls[MoveButtons::Down]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Down]->GetState<bool>())
g_freelook_camera.MoveVertical(g_freelook_camera.GetSpeed()); g_freelook_camera.MoveVertical(g_freelook_camera.GetSpeed() * dt);
if (m_move_buttons->controls[MoveButtons::Left]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Left]->GetState<bool>())
g_freelook_camera.MoveHorizontal(g_freelook_camera.GetSpeed()); g_freelook_camera.MoveHorizontal(g_freelook_camera.GetSpeed() * dt);
if (m_move_buttons->controls[MoveButtons::Right]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Right]->GetState<bool>())
g_freelook_camera.MoveHorizontal(-g_freelook_camera.GetSpeed()); g_freelook_camera.MoveHorizontal(-g_freelook_camera.GetSpeed() * dt);
if (m_move_buttons->controls[MoveButtons::Forward]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Forward]->GetState<bool>())
g_freelook_camera.MoveForward(g_freelook_camera.GetSpeed()); g_freelook_camera.MoveForward(g_freelook_camera.GetSpeed() * dt);
if (m_move_buttons->controls[MoveButtons::Backward]->GetState<bool>()) if (m_move_buttons->controls[MoveButtons::Backward]->GetState<bool>())
g_freelook_camera.MoveForward(-g_freelook_camera.GetSpeed()); g_freelook_camera.MoveForward(-g_freelook_camera.GetSpeed() * dt);
if (m_fov_buttons->controls[FieldOfViewButtons::IncreaseX]->GetState<bool>()) if (m_fov_buttons->controls[FieldOfViewButtons::IncreaseX]->GetState<bool>())
g_freelook_camera.IncreaseFovX(g_freelook_camera.GetFovStepSize()); g_freelook_camera.IncreaseFovX(g_freelook_camera.GetFovStepSize() * dt);
if (m_fov_buttons->controls[FieldOfViewButtons::DecreaseX]->GetState<bool>()) if (m_fov_buttons->controls[FieldOfViewButtons::DecreaseX]->GetState<bool>())
g_freelook_camera.IncreaseFovX(-1.0f * g_freelook_camera.GetFovStepSize()); g_freelook_camera.IncreaseFovX(-1.0f * g_freelook_camera.GetFovStepSize() * dt);
if (m_fov_buttons->controls[FieldOfViewButtons::IncreaseY]->GetState<bool>()) if (m_fov_buttons->controls[FieldOfViewButtons::IncreaseY]->GetState<bool>())
g_freelook_camera.IncreaseFovY(g_freelook_camera.GetFovStepSize()); g_freelook_camera.IncreaseFovY(g_freelook_camera.GetFovStepSize() * dt);
if (m_fov_buttons->controls[FieldOfViewButtons::DecreaseY]->GetState<bool>()) if (m_fov_buttons->controls[FieldOfViewButtons::DecreaseY]->GetState<bool>())
g_freelook_camera.IncreaseFovY(-1.0f * g_freelook_camera.GetFovStepSize()); g_freelook_camera.IncreaseFovY(-1.0f * g_freelook_camera.GetFovStepSize() * dt);
if (m_speed_buttons->controls[SpeedButtons::Decrease]->GetState<bool>()) if (m_speed_buttons->controls[SpeedButtons::Decrease]->GetState<bool>())
g_freelook_camera.ModifySpeed(1.0f / 1.1f); g_freelook_camera.ModifySpeed(g_freelook_camera.GetSpeed() * -0.9 * dt);
if (m_speed_buttons->controls[SpeedButtons::Increase]->GetState<bool>()) if (m_speed_buttons->controls[SpeedButtons::Increase]->GetState<bool>())
g_freelook_camera.ModifySpeed(1.1f); g_freelook_camera.ModifySpeed(g_freelook_camera.GetSpeed() * 1.1 * dt);
if (m_speed_buttons->controls[SpeedButtons::Reset]->GetState<bool>()) if (m_speed_buttons->controls[SpeedButtons::Reset]->GetState<bool>())
g_freelook_camera.ResetSpeed(); g_freelook_camera.ResetSpeed();

View File

@ -265,18 +265,18 @@ void FreeLookCamera::Rotate(const Common::Quaternion& amt)
void FreeLookCamera::IncreaseFovX(float fov) void FreeLookCamera::IncreaseFovX(float fov)
{ {
m_fov_x += fov; m_fov_x += fov;
m_fov_x = std::clamp(m_fov_x, m_fov_step_size, m_fov_x); m_fov_x = std::clamp(m_fov_x, m_min_fov_multiplier, m_fov_x);
} }
void FreeLookCamera::IncreaseFovY(float fov) void FreeLookCamera::IncreaseFovY(float fov)
{ {
m_fov_y += fov; m_fov_y += fov;
m_fov_y = std::clamp(m_fov_y, m_fov_step_size, m_fov_y); m_fov_y = std::clamp(m_fov_y, m_min_fov_multiplier, m_fov_y);
} }
float FreeLookCamera::GetFovStepSize() const float FreeLookCamera::GetFovStepSize() const
{ {
return m_fov_step_size; return 1.5f;
} }
void FreeLookCamera::Reset() void FreeLookCamera::Reset()
@ -287,14 +287,15 @@ void FreeLookCamera::Reset()
m_dirty = true; m_dirty = true;
} }
void FreeLookCamera::ModifySpeed(float multiplier) void FreeLookCamera::ModifySpeed(float amt)
{ {
m_speed *= multiplier; m_speed += amt;
m_speed = std::clamp(m_speed, 0.0f, m_speed);
} }
void FreeLookCamera::ResetSpeed() void FreeLookCamera::ResetSpeed()
{ {
m_speed = 1.0f; m_speed = 60.0f;
} }
float FreeLookCamera::GetSpeed() const float FreeLookCamera::GetSpeed() const

View File

@ -78,8 +78,8 @@ private:
std::optional<FreeLook::ControlType> m_current_type; std::optional<FreeLook::ControlType> m_current_type;
std::unique_ptr<CameraController> m_camera_controller; std::unique_ptr<CameraController> m_camera_controller;
float m_fov_step_size = 0.025f; float m_min_fov_multiplier = 0.025f;
float m_speed = 1.0f; float m_speed = 60.0f;
}; };
extern FreeLookCamera g_freelook_camera; extern FreeLookCamera g_freelook_camera;