Move animation related classes
This commit is contained in:
@@ -4,24 +4,23 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Scene/SequenceAnimationController.hpp"
|
||||
#include "SequenceAnimationController.hpp"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
SequenceAnimationController::SequenceAnimationController()
|
||||
{
|
||||
m_animationController.m_completionEvent += EventHandler(this, &SequenceAnimationController::SequenceCompletedCallback);
|
||||
m_animationController.OnCompletion += EventHandler(this, &SequenceAnimationController::SequenceCompletedCallback);
|
||||
}
|
||||
|
||||
const SequenceAnimationController::PoseDurationPair& SequenceAnimationController::GetStep(int index) const
|
||||
const SequenceAnimationController::PoseDurationPair& SequenceAnimationController::GetStep(const int index) const
|
||||
{
|
||||
return m_steps[std::max(0, std::min(index, static_cast<int>(m_steps.size() - 1)))];
|
||||
}
|
||||
|
||||
void SequenceAnimationController::SequenceCompletedCallback(SimpleAnimationController *ignored)
|
||||
void SequenceAnimationController::SequenceCompletedCallback(SimpleAnimationController* ignored)
|
||||
{
|
||||
if(m_steps.empty())
|
||||
return;
|
||||
if(m_steps.empty()) return;
|
||||
|
||||
if(m_currentStep < m_steps.size() - 1)
|
||||
{
|
||||
@@ -94,7 +93,7 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAnimationController::AddAnimationSteps(std::initializer_list<Math::PoseF> poses, double duration)
|
||||
void SequenceAnimationController::AddAnimationSteps(const std::initializer_list<Math::PoseF> poses, double duration)
|
||||
{
|
||||
for(const auto& pose : poses)
|
||||
{
|
||||
@@ -110,7 +109,7 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceAnimationController::AddAnimationSteps(std::initializer_list<PoseDurationPair> steps)
|
||||
void SequenceAnimationController::AddAnimationSteps(const std::initializer_list<PoseDurationPair> steps)
|
||||
{
|
||||
for(const auto& step : steps)
|
||||
{
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Scene/SimpleAnimationController.hpp"
|
||||
#include "SimpleAnimationController.hpp"
|
||||
#include "Base/Event.hpp"
|
||||
#include "Base/ITickable.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
@@ -33,7 +33,7 @@ namespace OpenVulkano::Scene
|
||||
void SequenceCompletedCallback(SimpleAnimationController *animationController);
|
||||
|
||||
public:
|
||||
Event<SequenceAnimationController *> OnSequenceCompleted;
|
||||
Event<SequenceAnimationController*> OnSequenceCompleted;
|
||||
|
||||
SequenceAnimationController();
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace OpenVulkano::Scene
|
||||
*
|
||||
* @param loop A boolean value to enable or disable looping.
|
||||
*/
|
||||
void EnableLoop(bool value) { m_loop = value; }
|
||||
void EnableLoop(const bool loop) { m_loop = loop; }
|
||||
|
||||
void SetNode(Node *node) { m_animationController.SetNode(node); }
|
||||
Node* GetNode() const { return m_animationController.GetNode(); }
|
||||
void SetNode(Node* node) { m_animationController.SetNode(node); }
|
||||
[[nodiscard]] Node* GetNode() const { return m_animationController.GetNode(); }
|
||||
|
||||
/**
|
||||
* Sets the time to transition back to the first pose when looping is enabled.
|
||||
@@ -62,7 +62,7 @@ namespace OpenVulkano::Scene
|
||||
* @param resetTime The time to transition back to the first pose.
|
||||
* @see GetAnimationPoseResetTime
|
||||
*/
|
||||
void SetAnimationPoseResetTime(double resetTime) { m_resetTime = resetTime; }
|
||||
void SetAnimationPoseResetTime(const double resetTime) { m_resetTime = resetTime; }
|
||||
|
||||
/**
|
||||
* Gets the current reset time for transitioning back to the first pose.
|
||||
@@ -73,13 +73,13 @@ namespace OpenVulkano::Scene
|
||||
double GetAnimationPoseResetTime() const { return m_resetTime; }
|
||||
|
||||
void Restart();
|
||||
bool IsFinished() const;
|
||||
[[nodiscard]] bool IsFinished() const;
|
||||
|
||||
void AddAnimationStep(const Math::PoseF &pose, double duration);
|
||||
void AddAnimationSteps(std::initializer_list<Math::PoseF> poses, double duration);
|
||||
void AddAnimationSteps(std::initializer_list<PoseDurationPair> steps);
|
||||
const PoseDurationPair& GetStep(int index) const;
|
||||
const std::vector<PoseDurationPair> &GetSteps() const { return m_steps; }
|
||||
[[nodiscard]] const PoseDurationPair& GetStep(int index) const;
|
||||
[[nodiscard]] const std::vector<PoseDurationPair>& GetSteps() const { return m_steps; }
|
||||
|
||||
void Tick() override;
|
||||
};
|
||||
@@ -29,6 +29,6 @@ namespace OpenVulkano::Scene
|
||||
m_node->SetMatrix(currentPose.ToMatrix());
|
||||
|
||||
if(m_elapsed > m_duration)
|
||||
m_completionEvent.NotifyAll(this);
|
||||
OnCompletion(this);
|
||||
}
|
||||
}
|
||||
@@ -25,24 +25,24 @@ namespace OpenVulkano::Scene
|
||||
double m_elapsed = 0;
|
||||
|
||||
public:
|
||||
Event<SimpleAnimationController *> m_completionEvent;
|
||||
Event<SimpleAnimationController*> OnCompletion;
|
||||
|
||||
SimpleAnimationController() = default;
|
||||
|
||||
void Reset() { m_elapsed = 0; }
|
||||
void SwapPoses() { std::swap(m_initialPose, m_targetPose); }
|
||||
|
||||
Node* GetNode() const { return m_node; }
|
||||
void SetNode(Node *node) { m_node = node; }
|
||||
[[nodiscard]] Node* GetNode() const { return m_node; }
|
||||
void SetNode(Node* node) { m_node = node; }
|
||||
|
||||
const Math::PoseF& GetInitialPose() const { return m_initialPose; }
|
||||
const Math::PoseF& GetTargetPose() const { return m_targetPose; }
|
||||
void SetPoses(const Math::PoseF &initialPose, const Math::PoseF &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; }
|
||||
[[nodiscard]] const Math::PoseF& GetInitialPose() const { return m_initialPose; }
|
||||
[[nodiscard]] const Math::PoseF& GetTargetPose() const { return m_targetPose; }
|
||||
void SetPoses(const Math::PoseF& initialPose, const Math::PoseF& targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; }
|
||||
|
||||
double GetDuration() const { return m_duration; }
|
||||
void SetDuration(double duration) { m_duration = duration; }
|
||||
[[nodiscard]] double GetDuration() const { return m_duration; }
|
||||
void SetDuration(const double duration) { m_duration = duration; }
|
||||
|
||||
double GetProgress();
|
||||
[[nodiscard]] double GetProgress();
|
||||
|
||||
void Tick() override;
|
||||
};
|
||||
Reference in New Issue
Block a user