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; }