Summary:
- In MovingCubeApp animations are now allocated on stack - m_sequenceAnimationController now uses SetAnimationPoseResetTime() - Removed OnSequenceAnimationCompleted() - Pose::GetOrientation() now returns by value(without it my code doesn't compile) - GetStep() getter - In if(m_loop) checking for m_resetTime to be zero or last step to be equal to the first - Tick now ticks only if there are at least one element in m_steps - IsFinished() function - AddAnimationSteps() functions that take initializer_lists - Getters in SimpleAnimationController are now const
This commit is contained in:
@@ -10,31 +10,47 @@ namespace OpenVulkano::Scene
|
||||
{
|
||||
SequenceAnimationController::SequenceAnimationController()
|
||||
{
|
||||
// m_animationController.m_completionEvent += EventHandler(this, &SequenceAnimationController::OnCurrentFrameFinished);
|
||||
m_completionEvent += EventHandler(this, &SequenceAnimationController::OnCurrentFrameFinished);
|
||||
m_animationController.m_completionEvent += EventHandler(this, &SequenceAnimationController::OnCurrentFrameFinished);
|
||||
}
|
||||
|
||||
void SequenceAnimationController::AdvanceToNextStep()
|
||||
SequenceAnimationController::PoseDurationPair SequenceAnimationController::GetStep(int index)
|
||||
{
|
||||
if(index >= 0 && index < m_steps.size())
|
||||
return m_steps[index];
|
||||
return PoseDurationPair();
|
||||
}
|
||||
|
||||
void SequenceAnimationController::OnCurrentFrameFinished(SimpleAnimationController *ignored)
|
||||
{
|
||||
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();
|
||||
m_currentStep++;
|
||||
m_animationController.SetPoses(m_animationController.GetTargetPose(), m_steps[m_currentStep].first);
|
||||
m_animationController.SetDuration(m_steps[m_currentStep].second);
|
||||
m_animationController.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();
|
||||
// NOTE(vb): Maybe compare steps with some epsilon value
|
||||
if(m_steps.size() > 1 && ((m_steps.front().first == m_steps.back().first) || m_resetTime == 0))
|
||||
{
|
||||
m_currentStep = 1;
|
||||
m_animationController.SetPoses(m_steps[m_currentStep-1].first, m_steps[m_currentStep].first);
|
||||
m_animationController.SetDuration(m_steps[m_currentStep].second);
|
||||
m_animationController.Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentStep = 0;
|
||||
m_animationController.SetPoses(m_steps.back().first, m_steps.front().first);
|
||||
m_animationController.SetDuration(m_resetTime);
|
||||
m_animationController.Reset();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,7 +61,9 @@ namespace OpenVulkano::Scene
|
||||
|
||||
void SequenceAnimationController::Tick()
|
||||
{
|
||||
SimpleAnimationController::Tick();
|
||||
if(m_steps.empty())
|
||||
return;
|
||||
m_animationController.Tick();
|
||||
}
|
||||
|
||||
void SequenceAnimationController::Restart()
|
||||
@@ -53,26 +71,60 @@ namespace OpenVulkano::Scene
|
||||
m_currentStep = 0;
|
||||
if(!m_steps.empty())
|
||||
{
|
||||
SetPoses(GetTargetPose(), m_steps[m_currentStep].first);
|
||||
SetDuration(m_steps.back().second);
|
||||
m_animationController.SetPoses(m_animationController.GetTargetPose(), m_steps[m_currentStep].first);
|
||||
m_animationController.SetDuration(m_steps[m_currentStep].second);
|
||||
}
|
||||
SimpleAnimationController::Reset();
|
||||
m_animationController.Reset();
|
||||
}
|
||||
|
||||
bool SequenceAnimationController::IsFinished() const
|
||||
{
|
||||
if(m_loop)
|
||||
return false;
|
||||
return m_currentStep >= m_steps.size();
|
||||
}
|
||||
|
||||
void SequenceAnimationController::AddAnimationStep(const Math::PoseF &pose, double duration)
|
||||
{
|
||||
m_steps.emplace_back(pose, duration);
|
||||
if(m_steps.size() == 2)
|
||||
if(m_steps.size() > 1)
|
||||
{
|
||||
m_currentStep = 1;
|
||||
SetPoses(m_steps[0].first, m_steps[1].first);
|
||||
SetDuration(m_steps[0].second);
|
||||
Reset();
|
||||
m_animationController.SetPoses(m_steps[0].first, m_steps[1].first);
|
||||
m_animationController.SetDuration(m_steps[1].second);
|
||||
m_animationController.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAnimationController::OnCurrentFrameFinished(SimpleAnimationController *animationController)
|
||||
void SequenceAnimationController::AddAnimationSteps(std::initializer_list<Math::PoseF> poses, double duration)
|
||||
{
|
||||
AdvanceToNextStep();
|
||||
for(const auto& pose : poses)
|
||||
{
|
||||
m_steps.emplace_back(pose, duration);
|
||||
}
|
||||
|
||||
if(m_steps.size() > 1)
|
||||
{
|
||||
m_currentStep = 1;
|
||||
m_animationController.SetPoses(m_steps[0].first, m_steps[1].first);
|
||||
m_animationController.SetDuration(m_steps[1].second);
|
||||
m_animationController.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAnimationController::AddAnimationSteps(std::initializer_list<PoseDurationPair> steps)
|
||||
{
|
||||
for(const auto& step : steps)
|
||||
{
|
||||
m_steps.emplace_back(step);
|
||||
}
|
||||
|
||||
if(m_steps.size() > 1)
|
||||
{
|
||||
m_currentStep = 1;
|
||||
m_animationController.SetPoses(m_steps[0].first, m_steps[1].first);
|
||||
m_animationController.SetDuration(m_steps[1].second);
|
||||
m_animationController.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user