45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/*
|
|
* 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());
|
|
}
|
|
} |