/* * 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 "Scene/SequenceAnimationController.hpp" namespace OpenVulkano::Scene { SequenceAnimationController::SequenceAnimationController() { // m_animationController.m_completionEvent += EventHandler(this, &SequenceAnimationController::OnCurrentFrameFinished); m_completionEvent += EventHandler(this, &SequenceAnimationController::OnCurrentFrameFinished); } void SequenceAnimationController::AdvanceToNextStep() { if(m_steps.empty()) return; if(m_currentStep < m_steps.size() - 1) { ++m_currentStep; SetPoses(GetTargetPose(), m_steps[m_currentStep].first); SetDuration(m_steps[m_currentStep-1].second); SimpleAnimationController::Reset(); } else { if(m_loop) { m_currentStep = 0; SetPoses(GetTargetPose(), m_steps[m_currentStep].first); // We don't set the duration because transition from the last step to the first // requires to use duration of the last step SimpleAnimationController::Reset(); } else { m_sequenceCompletionEvent.NotifyAll(this); } } } void SequenceAnimationController::Tick() { SimpleAnimationController::Tick(); } void SequenceAnimationController::Restart() { m_currentStep = 0; if(!m_steps.empty()) { SetPoses(GetTargetPose(), m_steps[m_currentStep].first); SetDuration(m_steps.back().second); } SimpleAnimationController::Reset(); } void SequenceAnimationController::AddAnimationStep(const Math::PoseF &pose, double duration) { m_steps.emplace_back(pose, duration); if(m_steps.size() == 2) { m_currentStep = 1; SetPoses(m_steps[0].first, m_steps[1].first); SetDuration(m_steps[0].second); Reset(); } } void SequenceAnimationController::OnCurrentFrameFinished(SimpleAnimationController *animationController) { AdvanceToNextStep(); } }