From bcc10a1ee29e0767745979e03b913574b4eda769 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 10 Dec 2019 09:49:52 +0100 Subject: [PATCH] Math/Matrix4: Add Decompose --- ChangeLog.md | 1 + include/Nazara/Math/Matrix4.hpp | 2 ++ include/Nazara/Math/Matrix4.inl | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 5a7a81ea1..fe438cc97 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -202,6 +202,7 @@ Nazara Engine: - Add Flags::Set(Flags) helper method, to enable flags - ⚠ Constraint2D are no longer managed by references and are now handled objects - ⚠ Removed all Set methods from math classes taking their own type (e.g. Box::Set(Box)) +- Added Matrix4::Decompose Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 5a0e1808f..3ed2cd717 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -44,6 +44,8 @@ namespace Nz Matrix4& Concatenate(const Matrix4& matrix); Matrix4& ConcatenateAffine(const Matrix4& matrix); + void Decompose(Vector3& translation, Quaternion& rotation, Vector3& scale); + Vector4 GetColumn(unsigned int column) const; T GetDeterminant() const; T GetDeterminantAffine() const; diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 48d99f21e..1f2f58a17 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -220,6 +220,25 @@ namespace Nz F(1.0)); } + template + void Matrix4::Decompose(Vector3& translation, Quaternion& rotation, Vector3& scale) + { + Matrix4f localMat(*this); + + translation = localMat.GetTranslation(); + scale = localMat.GetScale(); + + Vector3 invScale; + invScale.x = T(1) / scale.x; + invScale.y = T(1) / scale.y; + invScale.z = T(1) / scale.z; + + localMat.ApplyScale(invScale); + + rotation = localMat.GetRotation(); + } + + /*! * \brief Gets the ith column of the matrix * \return Vector4 which is the transformation of this axis