Decomposing matrix in Pose constructor, added GetPose() and GetWorldPose() to Node class

This commit is contained in:
Vladyslav Baranovskyi
2024-06-06 15:37:38 +03:00
parent f672193211
commit e6615a2bf5
3 changed files with 22 additions and 0 deletions

View File

@@ -11,6 +11,7 @@
#include <glm/gtc/type_aligned.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/io.hpp>

View File

@@ -28,6 +28,22 @@ namespace OpenVulkano::Math
: m_orientation(Math::Utils::qua(eulerAngle)), m_position(position)
{}
Pose(const Math::Matrix4<T> &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<T>& GetOrientation() const { return m_orientation; }
[[nodiscard]] Vector3_SIMD<T> GetPosition() const { return m_position; }

View File

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