Move animation related classes

This commit is contained in:
Georg Hagen
2025-01-26 18:51:34 +01:00
parent 44f12cf01e
commit dd866cd122
5 changed files with 29 additions and 31 deletions

View File

@@ -14,8 +14,8 @@
#include "Scene/Vertex.hpp" #include "Scene/Vertex.hpp"
#include "Scene/SimpleDrawable.hpp" #include "Scene/SimpleDrawable.hpp"
#include "Scene/Camera.hpp" #include "Scene/Camera.hpp"
#include "Scene/SimpleAnimationController.hpp" #include "Scene/Animation/SimpleAnimationController.hpp"
#include "Scene/SequenceAnimationController.hpp" #include "Scene/Animation/SequenceAnimationController.hpp"
#include "Scene/MorphableCameraController.hpp" #include "Scene/MorphableCameraController.hpp"
#include "Scene/UI/PerformanceInfo.hpp" #include "Scene/UI/PerformanceInfo.hpp"
#include "Scene/SceneIntersectionTestController.hpp" #include "Scene/SceneIntersectionTestController.hpp"
@@ -176,8 +176,7 @@ namespace OpenVulkano
Math::Pose srcPose(Math::Quaternion<float>(), Math::Vector3f_SIMD(-3, 0, 0)); Math::Pose srcPose(Math::Quaternion<float>(), Math::Vector3f_SIMD(-3, 0, 0));
Math::Pose destPose(Math::Quaternion<float>(), Math::Vector3f_SIMD(3, 0, 0)); Math::Pose destPose(Math::Quaternion<float>(), Math::Vector3f_SIMD(3, 0, 0));
m_simpleAnimationController.SetPoses(srcPose, destPose); m_simpleAnimationController.SetPoses(srcPose, destPose);
m_simpleAnimationController.m_completionEvent += m_simpleAnimationController.OnCompletion += EventHandler(this, &MovingCubeAppImpl::OnSimpleAnimationCompleted);
EventHandler(this, &MovingCubeAppImpl::OnSimpleAnimationCompleted);
m_sequenceAnimationController.EnableLoop(true); m_sequenceAnimationController.EnableLoop(true);
m_sequenceAnimationController.SetNode(&m_redBox.m_node); m_sequenceAnimationController.SetNode(&m_redBox.m_node);

View File

@@ -4,24 +4,23 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
#include "Scene/SequenceAnimationController.hpp" #include "SequenceAnimationController.hpp"
namespace OpenVulkano::Scene namespace OpenVulkano::Scene
{ {
SequenceAnimationController::SequenceAnimationController() 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)))]; 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()) if(m_steps.empty()) return;
return;
if(m_currentStep < m_steps.size() - 1) 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) 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) for(const auto& step : steps)
{ {

View File

@@ -6,7 +6,7 @@
#pragma once #pragma once
#include "Scene/SimpleAnimationController.hpp" #include "SimpleAnimationController.hpp"
#include "Base/Event.hpp" #include "Base/Event.hpp"
#include "Base/ITickable.hpp" #include "Base/ITickable.hpp"
#include "Math/Math.hpp" #include "Math/Math.hpp"
@@ -33,7 +33,7 @@ namespace OpenVulkano::Scene
void SequenceCompletedCallback(SimpleAnimationController *animationController); void SequenceCompletedCallback(SimpleAnimationController *animationController);
public: public:
Event<SequenceAnimationController *> OnSequenceCompleted; Event<SequenceAnimationController*> OnSequenceCompleted;
SequenceAnimationController(); SequenceAnimationController();
@@ -47,10 +47,10 @@ namespace OpenVulkano::Scene
* *
* @param loop A boolean value to enable or disable looping. * @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); } void SetNode(Node* node) { m_animationController.SetNode(node); }
Node* GetNode() const { return m_animationController.GetNode(); } [[nodiscard]] Node* GetNode() const { return m_animationController.GetNode(); }
/** /**
* Sets the time to transition back to the first pose when looping is enabled. * 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. * @param resetTime The time to transition back to the first pose.
* @see GetAnimationPoseResetTime * @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. * 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; } double GetAnimationPoseResetTime() const { return m_resetTime; }
void Restart(); void Restart();
bool IsFinished() const; [[nodiscard]] bool IsFinished() const;
void AddAnimationStep(const Math::PoseF &pose, double duration); void AddAnimationStep(const Math::PoseF &pose, double duration);
void AddAnimationSteps(std::initializer_list<Math::PoseF> poses, double duration); void AddAnimationSteps(std::initializer_list<Math::PoseF> poses, double duration);
void AddAnimationSteps(std::initializer_list<PoseDurationPair> steps); void AddAnimationSteps(std::initializer_list<PoseDurationPair> steps);
const PoseDurationPair& GetStep(int index) const; [[nodiscard]] const PoseDurationPair& GetStep(int index) const;
const std::vector<PoseDurationPair> &GetSteps() const { return m_steps; } [[nodiscard]] const std::vector<PoseDurationPair>& GetSteps() const { return m_steps; }
void Tick() override; void Tick() override;
}; };

View File

@@ -29,6 +29,6 @@ namespace OpenVulkano::Scene
m_node->SetMatrix(currentPose.ToMatrix()); m_node->SetMatrix(currentPose.ToMatrix());
if(m_elapsed > m_duration) if(m_elapsed > m_duration)
m_completionEvent.NotifyAll(this); OnCompletion(this);
} }
} }

View File

@@ -25,24 +25,24 @@ namespace OpenVulkano::Scene
double m_elapsed = 0; double m_elapsed = 0;
public: public:
Event<SimpleAnimationController *> m_completionEvent; Event<SimpleAnimationController*> OnCompletion;
SimpleAnimationController() = default; SimpleAnimationController() = default;
void Reset() { m_elapsed = 0; } void Reset() { m_elapsed = 0; }
void SwapPoses() { std::swap(m_initialPose, m_targetPose); } void SwapPoses() { std::swap(m_initialPose, m_targetPose); }
Node* GetNode() const { return m_node; } [[nodiscard]] Node* GetNode() const { return m_node; }
void SetNode(Node *node) { m_node = node; } void SetNode(Node* node) { m_node = node; }
const Math::PoseF& GetInitialPose() const { return m_initialPose; } [[nodiscard]] const Math::PoseF& GetInitialPose() const { return m_initialPose; }
const Math::PoseF& GetTargetPose() const { return m_targetPose; } [[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; } void SetPoses(const Math::PoseF& initialPose, const Math::PoseF& targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; }
double GetDuration() const { return m_duration; } [[nodiscard]] double GetDuration() const { return m_duration; }
void SetDuration(double duration) { m_duration = duration; } void SetDuration(const double duration) { m_duration = duration; }
double GetProgress(); [[nodiscard]] double GetProgress();
void Tick() override; void Tick() override;
}; };