Summary:
- Additional getters/setters - Passing setters' value as by reference - Changed includes order - Moved callback function to MovingCubeApp - Made Event public
This commit is contained in:
@@ -66,10 +66,16 @@ namespace OpenVulkano
|
||||
m_animationController->SetDuration(3);
|
||||
|
||||
OpenVulkano::Math::Pose srcPose(OpenVulkano::Math::Quaternion<float>(), OpenVulkano::Math::Vector3f_SIMD(-3, 0, 0));
|
||||
m_animationController->SetInitialPose(srcPose);
|
||||
|
||||
OpenVulkano::Math::Pose destPose(OpenVulkano::Math::Quaternion<float>(), OpenVulkano::Math::Vector3f_SIMD(3, 0, 0));
|
||||
m_animationController->SetTargetPose(destPose);
|
||||
m_animationController->SetPoses(srcPose, destPose);
|
||||
|
||||
m_animationController->m_completionEvent += EventHandler(this, &MovingCubeAppImpl::OnAnimationCompleted);
|
||||
}
|
||||
|
||||
void OnAnimationCompleted(OpenVulkano::Scene::SimpleAnimationController *anim)
|
||||
{
|
||||
anim->SwapPoses();
|
||||
anim->Reset();
|
||||
}
|
||||
|
||||
void Tick() override
|
||||
|
||||
@@ -4,32 +4,31 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "SimpleAnimationController.hpp"
|
||||
#include "Base/FrameMetadata.hpp"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
void SimpleAnimationController::OnAnimationCompleted()
|
||||
double SimpleAnimationController::GetProgress()
|
||||
{
|
||||
std::swap(m_targetPose, m_initialPose);
|
||||
m_elapsed = 0;
|
||||
double progress = m_elapsed / m_duration;
|
||||
if(progress >= 1.0)
|
||||
progress = 1;
|
||||
return progress;
|
||||
}
|
||||
|
||||
void SimpleAnimationController::Tick()
|
||||
{
|
||||
// NOTE(vb): We can't early quit by condition elapsed > duration because we need to
|
||||
// emit an event when animation is completed
|
||||
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();
|
||||
}
|
||||
if(m_elapsed > m_duration)
|
||||
m_completionEvent.NotifyAll(this);
|
||||
|
||||
double progress = GetProgress();
|
||||
OpenVulkano::Math::Pose<float> currentPose = m_initialPose.Interpolate(m_targetPose, progress);
|
||||
m_node->SetMatrix(currentPose.ToMatrix());
|
||||
}
|
||||
|
||||
@@ -12,26 +12,38 @@
|
||||
#include "Math/Pose.hpp"
|
||||
#include "Scene/Node.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
class SimpleAnimationController : public ITickable
|
||||
{
|
||||
OpenVulkano::Scene::Node *m_node = nullptr;
|
||||
OpenVulkano::Event<> m_event;
|
||||
OpenVulkano::Math::Pose<float> m_targetPose;
|
||||
OpenVulkano::Math::Pose<float> m_initialPose;
|
||||
float m_duration = 0;
|
||||
float m_elapsed = 0;
|
||||
double m_duration = 0;
|
||||
double m_elapsed = 0;
|
||||
|
||||
public:
|
||||
SimpleAnimationController() { m_event += EventHandler(this, &SimpleAnimationController::OnAnimationCompleted); }
|
||||
|
||||
void SetNode(OpenVulkano::Scene::Node *node) { m_node = node; }
|
||||
void SetInitialPose(OpenVulkano::Math::Pose<float> pose) { m_initialPose = pose; }
|
||||
void SetTargetPose(OpenVulkano::Math::Pose<float> pose) { m_targetPose = pose; }
|
||||
void SetDuration(float duration) { m_duration = duration; }
|
||||
OpenVulkano::Event<SimpleAnimationController *> m_completionEvent;
|
||||
|
||||
SimpleAnimationController() = default;
|
||||
|
||||
void Reset() { m_elapsed = 0; }
|
||||
void SwapPoses() { std::swap(m_initialPose, m_targetPose); }
|
||||
|
||||
OpenVulkano::Scene::Node* GetNode() { return m_node; }
|
||||
void SetNode(OpenVulkano::Scene::Node *node) { m_node = node; }
|
||||
|
||||
OpenVulkano::Math::Pose<float> GetInitialPose() { return m_initialPose; }
|
||||
OpenVulkano::Math::Pose<float> GetTargetPose() { return m_targetPose; }
|
||||
void SetPoses(const OpenVulkano::Math::Pose<float> &initialPose, const OpenVulkano::Math::Pose<float> &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; }
|
||||
|
||||
double GetDuration() { return m_duration; }
|
||||
void SetDuration(double duration) { m_duration = duration; }
|
||||
|
||||
double GetProgress();
|
||||
|
||||
void OnAnimationCompleted();
|
||||
void Tick() override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user