Update MorphableCameraController

This commit is contained in:
Georg Hagen
2025-01-26 19:30:36 +01:00
parent 843aebeafa
commit e9b419cd3c
4 changed files with 53 additions and 25 deletions

View File

@@ -5,9 +5,9 @@
*/
#include "MorphableCameraController.hpp"
#include "Base/FrameMetadata.hpp"
#include "Input/InputManager.hpp"
#include "Input/InputKey.hpp"
#include "Base/FrameMetadata.hpp"
#include "Scene/Camera.hpp"
namespace OpenVulkano::Scene
@@ -18,33 +18,19 @@ namespace OpenVulkano::Scene
, m_currentTime(0.0f)
, m_isMorphing(false)
, m_targetMorphStatePerspective(true)
{
auto input = OpenVulkano::Input::InputManager::GetInstance();
m_actionMorph = input->GetAction("morph");
}
{}
void MorphableCameraController::Init(MorphableCamera* camera)
{
CameraController::Init(camera);
m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P);
}
void MorphableCameraController::Tick()
{
auto input = OpenVulkano::Input::InputManager::GetInstance();
bool isMorphingDown = input->GetButton(m_actionMorph);
if (!m_wasMorphingKeyDown && isMorphingDown)
{
m_isMorphing = true;
m_currentTime = 0.0f;
m_targetMorphStatePerspective = !m_targetMorphStatePerspective;
}
m_wasMorphingKeyDown = isMorphingDown;
if (m_isMorphing)
{
m_currentTime += input->GetTimeScale();
m_currentTime += CURRENT_FRAME.frameTime;
if (m_currentTime > m_animationDuration) m_currentTime = m_animationDuration;
float t = m_currentTime / m_animationDuration;
if (t >= 1.0f)
@@ -52,15 +38,32 @@ namespace OpenVulkano::Scene
t = 1.0f;
m_isMorphing = false;
}
float newState = m_targetMorphStatePerspective ? (1.0f - t) : t;
const float newState = m_targetMorphStatePerspective ? (1.0f - t) : t;
static_cast<MorphableCamera*>(GetCamera())->SetMorphState(newState);
}
}
void MorphableCameraController::SetTargetState(bool toPerspective)
void MorphableCameraController::SetTargetState(const bool toPerspective)
{
if (toPerspective == m_targetMorphStatePerspective) return;
m_targetMorphStatePerspective = toPerspective;
m_isMorphing = true;
}
}
MorphableCameraControllerWithInput::MorphableCameraControllerWithInput(MorphableCamera* camera)
: m_controller(camera)
, m_actionMorph(Input::InputManager::GetInstance()->GetAction("morph"))
{
m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P);
}
void MorphableCameraControllerWithInput::Tick()
{
if (Input::InputManager::GetInstance()->GetButtonDown(m_actionMorph))
{
SetTargetState(!m_controller.IsTargetPerspective());
m_controller.Reset();
}
m_controller.Tick();
}
}