From 454a5b128198784883ab7609435cfb576268ad95 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 28 Jul 2014 16:16:32 +0200 Subject: [PATCH] Added Matrix4::Get[Column|Row] Former-commit-id: 5dc655f97d8523714c69627e70b3bf8dfdcdb1ae --- include/Nazara/Math/Matrix4.hpp | 2 ++ include/Nazara/Math/Matrix4.inl | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 2def3428d..90a5ae967 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -38,12 +38,14 @@ class NzMatrix4 NzMatrix4& Concatenate(const NzMatrix4& matrix); NzMatrix4& ConcatenateAffine(const NzMatrix4& matrix); + NzVector4 GetColumn(unsigned int column) const; T GetDeterminant() const; T GetDeterminantAffine() const; bool GetInverse(NzMatrix4* dest) const; bool GetInverseAffine(NzMatrix4* dest) const; NzQuaternion GetRotation() const; //NzMatrix3 GetRotationMatrix() const; + NzVector4 GetRow(unsigned int row) const; NzVector3 GetScale() const; NzVector3 GetTranslation() const; void GetTransposed(NzMatrix4* dest) const; diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 7caa3cb04..baab59da6 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -144,6 +144,25 @@ NzMatrix4& NzMatrix4::ConcatenateAffine(const NzMatrix4& matrix) F(1.0)); } +template +NzVector4 NzMatrix4::GetColumn(unsigned int column) const +{ + ///FIXME: Est-ce une bonne idée de gérer la matrice de cette façon ? + + #if NAZARA_MATH_SAFE + if (row > 3) + { + NzStringStream ss; + ss << "Row out of range: (" << row << ") > 3"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + T* ptr = (&m11) + row*4; + return NzVector4(ptr); +} + template T NzMatrix4::GetDeterminant() const { @@ -444,6 +463,25 @@ NzQuaternion NzMatrix4::GetRotation() const return quat; } +template +NzVector4 NzMatrix4::GetRow(unsigned int row) const +{ + ///FIXME: Est-ce une bonne idée de gérer la matrice de cette façon ? + + #if NAZARA_MATH_SAFE + if (column > 3) + { + NzStringStream ss; + ss << "Column out of range: (" << column << ") > 3"; + + throw std::out_of_range(ss.ToString()); + } + #endif + + T* ptr = &m11; + return NzVector4(ptr[column], ptr[column+4], ptr[column+8], ptr[column+12]); +} + template NzVector3 NzMatrix4::GetScale() const {