SimpleAnimationController, MovingCubeApp

This commit is contained in:
Vladyslav Baranovskyi
2024-06-05 21:51:04 +03:00
parent 463f632432
commit 7111e46954
5 changed files with 193 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <utility>
#include "SimpleAnimationController.hpp"
#include "Base/FrameMetadata.hpp"
namespace OpenVulkano::Scene
{
SimpleAnimationController::SimpleAnimationController(OpenVulkano::Scene::Node *node, OpenVulkano::Math::Pose<float> initialPose, OpenVulkano::Math::Pose<float> targetPose, float duration)
{
m_node = node;
m_initialPose = initialPose;
m_targetPose = targetPose;
m_duration = duration;
m_event += EventHandler(this, &SimpleAnimationController::OnAnimationCompleted);
}
void SimpleAnimationController::OnAnimationCompleted()
{
std::swap(m_targetPose, m_initialPose);
m_elapsed = 0;
}
void SimpleAnimationController::Tick()
{
if(!m_node || m_duration <= 0)
return;
m_elapsed += OpenVulkano::CURRENT_FRAME.frameTime;
float progress = m_elapsed / m_duration;
if(progress >= 1.0)
{
progress = 1;
m_event.NotifyAll();
}
OpenVulkano::Math::Pose<float> currentPose = m_initialPose.Interpolate(m_targetPose, progress);
m_node->SetMatrix(currentPose.ToMatrix());
}
}