SimpleAnimationController, MovingCubeApp
This commit is contained in:
45
openVulkanoCpp/Scene/SimpleAnimationController.cpp
Normal file
45
openVulkanoCpp/Scene/SimpleAnimationController.cpp
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user