From 7111e46954063ac58e755339dfa82b1991eaf0bc Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Wed, 5 Jun 2024 21:51:04 +0300 Subject: [PATCH 1/9] SimpleAnimationController, MovingCubeApp --- examples/ExampleApps/MovingCubeApp.cpp | 89 +++++++++++++++++++ examples/ExampleApps/MovingCubeApp.hpp | 24 +++++ examples/main.cpp | 4 +- .../Scene/SimpleAnimationController.cpp | 45 ++++++++++ .../Scene/SimpleAnimationController.hpp | 32 +++++++ 5 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 examples/ExampleApps/MovingCubeApp.cpp create mode 100644 examples/ExampleApps/MovingCubeApp.hpp create mode 100644 openVulkanoCpp/Scene/SimpleAnimationController.cpp create mode 100644 openVulkanoCpp/Scene/SimpleAnimationController.hpp diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp new file mode 100644 index 0000000..bc9be4b --- /dev/null +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -0,0 +1,89 @@ +/* + * 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 "MovingCubeApp.hpp" +#include "Math/Math.hpp" +#include "Scene/Scene.hpp" +#include "Scene/Shader/Shader.hpp" +#include "Scene/Geometry.hpp" +#include "Scene/Material.hpp" +#include "Scene/Vertex.hpp" +#include "Scene/SimpleDrawable.hpp" +#include "Scene/Camera.hpp" +#include "Scene/SimpleAnimationController.hpp" +#include "Input/InputManager.hpp" +#include "Host/GraphicsAppManager.hpp" +#include "Base/EngineConfiguration.hpp" +#include "Controller/FreeCamCameraController.hpp" + +namespace OpenVulkano +{ + class MovingCubeAppImpl final : public MovingCubeApp + { + OpenVulkano::Scene::Scene m_scene; + OpenVulkano::Scene::PerspectiveCamera m_camera; + OpenVulkano::FreeCamCameraController m_cameraControl; + OpenVulkano::Scene::Material m_material; + OpenVulkano::Scene::Shader m_shader; + + OpenVulkano::Scene::Geometry m_geometry; + OpenVulkano::Scene::SimpleDrawable m_drawable; + OpenVulkano::Scene::Node m_node; + std::unique_ptr m_animationController; + + public: + void Init() override + { + auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration(); + m_camera.Init(70, 16, 9, 0.1, 100); + // m_camera.SetMatrix(OpenVulkano::Math::Utils::translate(OpenVulkano::Math::Matrix4f(1), OpenVulkano::Math::Vector3f_SIMD(0, 0, -50))); + + m_scene.Init(); + m_scene.SetCamera(&m_camera); + + m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::VERTEX, "Shader/basic"); + m_shader.AddShaderProgram(OpenVulkano::ShaderProgramType::FRAGMENT, "Shader/basic"); + m_shader.AddVertexInputDescription(OpenVulkano::Vertex::GetVertexInputDescription()); + + m_geometry.InitCube(); + m_drawable.Init(&m_shader, &m_geometry, &m_material); + + m_node.Init(); + m_scene.GetRoot()->AddChild(&m_node); + m_node.SetUpdateFrequency(OpenVulkano::Scene::UpdateFrequency::Always); + m_node.AddDrawable(&m_drawable); + m_node.SetMatrix(OpenVulkano::Math::Matrix4f(1)); + + GetGraphicsAppManager()->GetRenderer()->SetScene(&m_scene); + m_cameraControl.Init(&m_camera); + m_cameraControl.SetDefaultKeybindings(); + + OpenVulkano::Math::Pose srcPose(OpenVulkano::Math::Quaternion(), OpenVulkano::Math::Vector3f_SIMD(-3, 0, 0)); + OpenVulkano::Math::Pose destPose(OpenVulkano::Math::Quaternion(), OpenVulkano::Math::Vector3f_SIMD(3, 0, 0)); + m_animationController = std::make_unique(&m_node, srcPose, destPose, 3); + } + + void Tick() override + { + m_cameraControl.Tick(); + m_animationController->Tick(); + } + + void Close() override + { + } + }; + + IGraphicsApp* MovingCubeApp::Create() + { + return new MovingCubeAppImpl(); + } + + std::unique_ptr MovingCubeApp::CreateUnique() + { + return std::make_unique(); + } +} diff --git a/examples/ExampleApps/MovingCubeApp.hpp b/examples/ExampleApps/MovingCubeApp.hpp new file mode 100644 index 0000000..75d464e --- /dev/null +++ b/examples/ExampleApps/MovingCubeApp.hpp @@ -0,0 +1,24 @@ +/* + * 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/. + */ + +#pragma once + +#include + +#include "Base/IGraphicsApp.hpp" + +namespace OpenVulkano +{ + class MovingCubeApp : public IGraphicsApp + { + public: + static std::unique_ptr CreateUnique(); + static IGraphicsApp* Create(); + + std::string GetAppName() const final { return "Moving Cube App"; } + OpenVulkano::Version GetAppVersion() const final { return {"v1.0"}; } + }; +} \ No newline at end of file diff --git a/examples/main.cpp b/examples/main.cpp index acc1b76..7e9c527 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -6,12 +6,14 @@ #include "Host/GraphicsAppManager.hpp" #include "ExampleApps/CubesExampleApp.hpp" +#include "ExampleApps/MovingCubeApp.hpp" using namespace OpenVulkano; int main(int argc, char** argv) { - std::unique_ptr app = CubesExampleApp::CreateUnique(); + // std::unique_ptr app = CubesExampleApp::CreateUnique(); + std::unique_ptr app = MovingCubeApp::CreateUnique(); GraphicsAppManager manager(app.get()); manager.Run(); return 0; diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.cpp b/openVulkanoCpp/Scene/SimpleAnimationController.cpp new file mode 100644 index 0000000..03fae9a --- /dev/null +++ b/openVulkanoCpp/Scene/SimpleAnimationController.cpp @@ -0,0 +1,45 @@ +/* + * 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 + +#include "SimpleAnimationController.hpp" +#include "Base/FrameMetadata.hpp" + +namespace OpenVulkano::Scene +{ + SimpleAnimationController::SimpleAnimationController(OpenVulkano::Scene::Node *node, OpenVulkano::Math::Pose initialPose, OpenVulkano::Math::Pose targetPose, float duration) + { + m_node = node; + m_initialPose = initialPose; + m_targetPose = targetPose; + m_duration = duration; + m_event += EventHandler(this, &SimpleAnimationController::OnAnimationCompleted); + } + + void SimpleAnimationController::OnAnimationCompleted() + { + std::swap(m_targetPose, m_initialPose); + m_elapsed = 0; + } + + void SimpleAnimationController::Tick() + { + 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(); + } + + OpenVulkano::Math::Pose currentPose = m_initialPose.Interpolate(m_targetPose, progress); + m_node->SetMatrix(currentPose.ToMatrix()); + } +} \ No newline at end of file diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.hpp b/openVulkanoCpp/Scene/SimpleAnimationController.hpp new file mode 100644 index 0000000..720e9f8 --- /dev/null +++ b/openVulkanoCpp/Scene/SimpleAnimationController.hpp @@ -0,0 +1,32 @@ +/* + * 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/. + */ + +#pragma once + +#include "Base/ITickable.hpp" +#include "Base/Event.hpp" +#include "Math/Math.hpp" +#include "Math/Pose.hpp" +#include "Scene/Node.hpp" + +namespace OpenVulkano::Scene +{ + class SimpleAnimationController : public ITickable + { + OpenVulkano::Scene::Node *m_node = nullptr; + OpenVulkano::Event<> m_event; + OpenVulkano::Math::Pose m_targetPose; + OpenVulkano::Math::Pose m_initialPose; + float m_duration = 0; + float m_elapsed = 0; + + public: + SimpleAnimationController() = default; + SimpleAnimationController(OpenVulkano::Scene::Node *node, OpenVulkano::Math::Pose initialPose, OpenVulkano::Math::Pose targetPose, float duration); + void OnAnimationCompleted(); + void Tick() override; + }; +} \ No newline at end of file From afddc987a2aeddcac4cc8de8d535dbf6211d6302 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Wed, 5 Jun 2024 22:05:40 +0300 Subject: [PATCH 2/9] Setting up SimpleAnimationControllers using setters --- examples/ExampleApps/MovingCubeApp.cpp | 8 +++++++- openVulkanoCpp/Scene/SimpleAnimationController.cpp | 9 --------- openVulkanoCpp/Scene/SimpleAnimationController.hpp | 9 +++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index bc9be4b..ca82b37 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -61,9 +61,15 @@ namespace OpenVulkano m_cameraControl.Init(&m_camera); m_cameraControl.SetDefaultKeybindings(); + m_animationController = std::make_unique(); + m_animationController->SetNode(&m_node); + m_animationController->SetDuration(3); + OpenVulkano::Math::Pose srcPose(OpenVulkano::Math::Quaternion(), OpenVulkano::Math::Vector3f_SIMD(-3, 0, 0)); + m_animationController->SetInitialPose(srcPose); + OpenVulkano::Math::Pose destPose(OpenVulkano::Math::Quaternion(), OpenVulkano::Math::Vector3f_SIMD(3, 0, 0)); - m_animationController = std::make_unique(&m_node, srcPose, destPose, 3); + m_animationController->SetTargetPose(destPose); } void Tick() override diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.cpp b/openVulkanoCpp/Scene/SimpleAnimationController.cpp index 03fae9a..fd3ca2e 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.cpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.cpp @@ -11,15 +11,6 @@ namespace OpenVulkano::Scene { - SimpleAnimationController::SimpleAnimationController(OpenVulkano::Scene::Node *node, OpenVulkano::Math::Pose initialPose, OpenVulkano::Math::Pose targetPose, float duration) - { - m_node = node; - m_initialPose = initialPose; - m_targetPose = targetPose; - m_duration = duration; - m_event += EventHandler(this, &SimpleAnimationController::OnAnimationCompleted); - } - void SimpleAnimationController::OnAnimationCompleted() { std::swap(m_targetPose, m_initialPose); diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.hpp b/openVulkanoCpp/Scene/SimpleAnimationController.hpp index 720e9f8..8c2dfc5 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.hpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.hpp @@ -24,8 +24,13 @@ namespace OpenVulkano::Scene float m_elapsed = 0; public: - SimpleAnimationController() = default; - SimpleAnimationController(OpenVulkano::Scene::Node *node, OpenVulkano::Math::Pose initialPose, OpenVulkano::Math::Pose targetPose, float duration); + SimpleAnimationController() { m_event += EventHandler(this, &SimpleAnimationController::OnAnimationCompleted); } + + void SetNode(OpenVulkano::Scene::Node *node) { m_node = node; } + void SetInitialPose(OpenVulkano::Math::Pose pose) { m_initialPose = pose; } + void SetTargetPose(OpenVulkano::Math::Pose pose) { m_targetPose = pose; } + void SetDuration(float duration) { m_duration = duration; } + void OnAnimationCompleted(); void Tick() override; }; From 193c942f06253f48cc585cde5db1ade4a278da72 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 13:21:02 +0300 Subject: [PATCH 3/9] Summary: - Additional getters/setters - Passing setters' value as by reference - Changed includes order - Moved callback function to MovingCubeApp - Made Event public --- examples/ExampleApps/MovingCubeApp.cpp | 12 +++++-- .../Scene/SimpleAnimationController.cpp | 21 ++++++------ .../Scene/SimpleAnimationController.hpp | 32 +++++++++++++------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index ca82b37..a1311f9 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -66,10 +66,16 @@ namespace OpenVulkano m_animationController->SetDuration(3); OpenVulkano::Math::Pose srcPose(OpenVulkano::Math::Quaternion(), OpenVulkano::Math::Vector3f_SIMD(-3, 0, 0)); - m_animationController->SetInitialPose(srcPose); - OpenVulkano::Math::Pose destPose(OpenVulkano::Math::Quaternion(), 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 diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.cpp b/openVulkanoCpp/Scene/SimpleAnimationController.cpp index fd3ca2e..5c9e005 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.cpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.cpp @@ -4,32 +4,31 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include - #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 currentPose = m_initialPose.Interpolate(m_targetPose, progress); m_node->SetMatrix(currentPose.ToMatrix()); } diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.hpp b/openVulkanoCpp/Scene/SimpleAnimationController.hpp index 8c2dfc5..4a8481a 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.hpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.hpp @@ -12,26 +12,38 @@ #include "Math/Pose.hpp" #include "Scene/Node.hpp" +#include + namespace OpenVulkano::Scene { class SimpleAnimationController : public ITickable { OpenVulkano::Scene::Node *m_node = nullptr; - OpenVulkano::Event<> m_event; OpenVulkano::Math::Pose m_targetPose; OpenVulkano::Math::Pose 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 pose) { m_initialPose = pose; } - void SetTargetPose(OpenVulkano::Math::Pose pose) { m_targetPose = pose; } - void SetDuration(float duration) { m_duration = duration; } + OpenVulkano::Event 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 GetInitialPose() { return m_initialPose; } + OpenVulkano::Math::Pose GetTargetPose() { return m_targetPose; } + void SetPoses(const OpenVulkano::Math::Pose &initialPose, const OpenVulkano::Math::Pose &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; }; } \ No newline at end of file From 8a23389973f015c8bee649762cceed2e791d314f Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 13:51:28 +0300 Subject: [PATCH 4/9] Early exiting Tick function, returning Poses as const references --- openVulkanoCpp/Scene/SimpleAnimationController.cpp | 9 ++++----- openVulkanoCpp/Scene/SimpleAnimationController.hpp | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.cpp b/openVulkanoCpp/Scene/SimpleAnimationController.cpp index 5c9e005..3f616d3 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.cpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.cpp @@ -19,17 +19,16 @@ namespace OpenVulkano::Scene 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) + if(!m_node || m_duration <= 0 || m_elapsed > m_duration) return; m_elapsed += OpenVulkano::CURRENT_FRAME.frameTime; - if(m_elapsed > m_duration) - m_completionEvent.NotifyAll(this); double progress = GetProgress(); OpenVulkano::Math::Pose currentPose = m_initialPose.Interpolate(m_targetPose, progress); m_node->SetMatrix(currentPose.ToMatrix()); + + if(m_elapsed > m_duration) + m_completionEvent.NotifyAll(this); } } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.hpp b/openVulkanoCpp/Scene/SimpleAnimationController.hpp index 4a8481a..c6b2760 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.hpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.hpp @@ -19,8 +19,8 @@ namespace OpenVulkano::Scene class SimpleAnimationController : public ITickable { OpenVulkano::Scene::Node *m_node = nullptr; - OpenVulkano::Math::Pose m_targetPose; - OpenVulkano::Math::Pose m_initialPose; + OpenVulkano::Math::PoseF m_targetPose; + OpenVulkano::Math::PoseF m_initialPose; double m_duration = 0; double m_elapsed = 0; @@ -35,9 +35,9 @@ namespace OpenVulkano::Scene OpenVulkano::Scene::Node* GetNode() { return m_node; } void SetNode(OpenVulkano::Scene::Node *node) { m_node = node; } - OpenVulkano::Math::Pose GetInitialPose() { return m_initialPose; } - OpenVulkano::Math::Pose GetTargetPose() { return m_targetPose; } - void SetPoses(const OpenVulkano::Math::Pose &initialPose, const OpenVulkano::Math::Pose &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; } + const OpenVulkano::Math::PoseF GetInitialPose() { return m_initialPose; } + const OpenVulkano::Math::PoseF GetTargetPose() { return m_targetPose; } + void SetPoses(const OpenVulkano::Math::PoseF &initialPose, const OpenVulkano::Math::PoseF &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; } double GetDuration() { return m_duration; } void SetDuration(double duration) { m_duration = duration; } From f67219321104430d3ca44f853d85a3d0674a63c5 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 15:32:17 +0300 Subject: [PATCH 5/9] Fixed dumb mistakes with references, got rid of unnecessary OpenVulkano:: --- .../Scene/SimpleAnimationController.cpp | 4 ++-- .../Scene/SimpleAnimationController.hpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.cpp b/openVulkanoCpp/Scene/SimpleAnimationController.cpp index 3f616d3..82594bd 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.cpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.cpp @@ -22,10 +22,10 @@ namespace OpenVulkano::Scene if(!m_node || m_duration <= 0 || m_elapsed > m_duration) return; - m_elapsed += OpenVulkano::CURRENT_FRAME.frameTime; + m_elapsed += CURRENT_FRAME.frameTime; double progress = GetProgress(); - OpenVulkano::Math::Pose currentPose = m_initialPose.Interpolate(m_targetPose, progress); + Math::Pose currentPose = m_initialPose.Interpolate(m_targetPose, progress); m_node->SetMatrix(currentPose.ToMatrix()); if(m_elapsed > m_duration) diff --git a/openVulkanoCpp/Scene/SimpleAnimationController.hpp b/openVulkanoCpp/Scene/SimpleAnimationController.hpp index c6b2760..a369f4c 100644 --- a/openVulkanoCpp/Scene/SimpleAnimationController.hpp +++ b/openVulkanoCpp/Scene/SimpleAnimationController.hpp @@ -18,26 +18,26 @@ namespace OpenVulkano::Scene { class SimpleAnimationController : public ITickable { - OpenVulkano::Scene::Node *m_node = nullptr; - OpenVulkano::Math::PoseF m_targetPose; - OpenVulkano::Math::PoseF m_initialPose; + Node *m_node = nullptr; + Math::PoseF m_targetPose; + Math::PoseF m_initialPose; double m_duration = 0; double m_elapsed = 0; public: - OpenVulkano::Event m_completionEvent; + Event 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; } + Node* GetNode() { return m_node; } + void SetNode(Node *node) { m_node = node; } - const OpenVulkano::Math::PoseF GetInitialPose() { return m_initialPose; } - const OpenVulkano::Math::PoseF GetTargetPose() { return m_targetPose; } - void SetPoses(const OpenVulkano::Math::PoseF &initialPose, const OpenVulkano::Math::PoseF &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; } + const Math::PoseF& GetInitialPose() { return m_initialPose; } + const Math::PoseF& GetTargetPose() { return m_targetPose; } + void SetPoses(const Math::PoseF &initialPose, const Math::PoseF &targetPose) { m_initialPose = initialPose; m_targetPose = targetPose; } double GetDuration() { return m_duration; } void SetDuration(double duration) { m_duration = duration; } From e6615a2bf53d9fbd958a5d4c5bdf61773c83f524 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 15:37:38 +0300 Subject: [PATCH 6/9] Decomposing matrix in Pose constructor, added GetPose() and GetWorldPose() to Node class --- openVulkanoCpp/Math/Math.hpp | 1 + openVulkanoCpp/Math/Pose.hpp | 16 ++++++++++++++++ openVulkanoCpp/Scene/Node.hpp | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/openVulkanoCpp/Math/Math.hpp b/openVulkanoCpp/Math/Math.hpp index 6c4d115..cdaa1c5 100644 --- a/openVulkanoCpp/Math/Math.hpp +++ b/openVulkanoCpp/Math/Math.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/openVulkanoCpp/Math/Pose.hpp b/openVulkanoCpp/Math/Pose.hpp index 3e12ff5..d9dbd0a 100644 --- a/openVulkanoCpp/Math/Pose.hpp +++ b/openVulkanoCpp/Math/Pose.hpp @@ -28,6 +28,22 @@ namespace OpenVulkano::Math : m_orientation(Math::Utils::qua(eulerAngle)), m_position(position) {} + Pose(const Math::Matrix4 &matrix) + { + glm::vec3 scale; + glm::quat rotation; + glm::vec3 translation; + glm::vec3 skew; + glm::vec4 perspective; + + bool decomposed = glm::decompose((glm::mat4)matrix, scale, rotation, translation, skew, perspective); + if(decomposed) + { + m_orientation = rotation; + m_position = translation; + } + } + [[nodiscard]] Quaternion& GetOrientation() const { return m_orientation; } [[nodiscard]] Vector3_SIMD GetPosition() const { return m_position; } diff --git a/openVulkanoCpp/Scene/Node.hpp b/openVulkanoCpp/Scene/Node.hpp index 5a193b5..08ab16c 100644 --- a/openVulkanoCpp/Scene/Node.hpp +++ b/openVulkanoCpp/Scene/Node.hpp @@ -8,6 +8,7 @@ #include "Base/ICloseable.hpp" #include "Math/Math.hpp" +#include "Math/Pose.hpp" #include "Drawable.hpp" #include "UpdateFrequency.hpp" #include "Shader/DescriptorInputDescription.hpp" @@ -64,6 +65,10 @@ namespace OpenVulkano::Scene [[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; } + [[nodiscard]] Math::PoseF GetPose() { return Math::PoseF(GetMatrix()); } + + [[nodiscard]] Math::PoseF GetWorldPose() { return Math::PoseF(GetWorldMatrix()); } + [[nodiscard]] bool IsEnabled() const { return enabled; } void Enable() { enabled = true; } From 453fa467b04fd8cd7fc675db6638ef00ec5f19d8 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 15:41:59 +0300 Subject: [PATCH 7/9] Using CubesExampleApp as a default app --- examples/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index 7e9c527..cd4dc04 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -12,8 +12,8 @@ using namespace OpenVulkano; int main(int argc, char** argv) { - // std::unique_ptr app = CubesExampleApp::CreateUnique(); - std::unique_ptr app = MovingCubeApp::CreateUnique(); + std::unique_ptr app = CubesExampleApp::CreateUnique(); + // std::unique_ptr app = MovingCubeApp::CreateUnique(); GraphicsAppManager manager(app.get()); manager.Run(); return 0; From 458f51889ce0ef6756546d9ced169d9b0145903b Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 6 Jun 2024 22:35:21 +0300 Subject: [PATCH 8/9] Changed glm:: types to Math::, calling Math::Utils::decompose --- openVulkanoCpp/Math/Pose.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openVulkanoCpp/Math/Pose.hpp b/openVulkanoCpp/Math/Pose.hpp index d9dbd0a..6ee6506 100644 --- a/openVulkanoCpp/Math/Pose.hpp +++ b/openVulkanoCpp/Math/Pose.hpp @@ -30,13 +30,13 @@ namespace OpenVulkano::Math Pose(const Math::Matrix4 &matrix) { - glm::vec3 scale; - glm::quat rotation; - glm::vec3 translation; - glm::vec3 skew; - glm::vec4 perspective; + Math::Vector3_SIMD scale; + Math::Quaternion rotation; + Math::Vector3_SIMD translation; + Math::Vector3_SIMD skew; + Math::Vector4_SIMD perspective; - bool decomposed = glm::decompose((glm::mat4)matrix, scale, rotation, translation, skew, perspective); + bool decomposed = Math::Utils::decompose(matrix, scale, rotation, translation, skew, perspective); if(decomposed) { m_orientation = rotation; From 3e8ea0fd32d7a4772ed3459112aef1599efae1e3 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Fri, 7 Jun 2024 10:50:34 +0200 Subject: [PATCH 9/9] Fix linux build issue --- openVulkanoCpp/AR/ArFrame.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openVulkanoCpp/AR/ArFrame.hpp b/openVulkanoCpp/AR/ArFrame.hpp index 2384b2a..ef68870 100644 --- a/openVulkanoCpp/AR/ArFrame.hpp +++ b/openVulkanoCpp/AR/ArFrame.hpp @@ -109,7 +109,7 @@ namespace OpenVulkano::AR [[nodiscard]] ArTrackingState GetTrackingState() const { return frameMetadata.trackingState; }; - [[nodiscard]] virtual Math::PoseF GetPose() const { return Math::PoseF({}); }; //TODO + [[nodiscard]] virtual Math::PoseF GetPose() const { return Math::PoseF(); }; //TODO [[nodiscard]] Math::Timestamp GetTimestamp() const { return frameMetadata.timestamp; };