From c7fdf254325c98579851e2d3d288cde8ae6bb0be Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 21 Mar 2013 18:29:50 +0100 Subject: [PATCH] Added Matrix4::GetDeterminantAffine Former-commit-id: 404098cc552509039c38e7449b167dbab0385008 --- include/Nazara/Math/Matrix4.hpp | 1 + include/Nazara/Math/Matrix4.inl | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index be1f7eb8b..e618ca74a 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -37,6 +37,7 @@ class NzMatrix4 NzMatrix4& ConcatenateAffine(const NzMatrix4& matrix); T GetDeterminant() const; + T GetDeterminantAffine() const; bool GetInverse(NzMatrix4* dest) const; bool GetInverseAffine(NzMatrix4* dest) const; NzQuaternion GetRotation() const; diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 606cd18d0..094226f02 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -139,6 +139,16 @@ T NzMatrix4::GetDeterminant() const return m11*A - m21*B + m31*C - m41*D; } +template +T NzMatrix4::GetDeterminantAffine() const +{ + T A = m22*m33 - m32*m23; + T B = m12*m33 - m32*m13; + T C = m12*m23 - m22*m13; + + return m11*A - m21*B + m31*C; +} + template bool NzMatrix4::GetInverse(NzMatrix4* dest) const { @@ -286,7 +296,13 @@ template bool NzMatrix4::GetInverseAffine(NzMatrix4* dest) const { ///DOC: Il est possible d'appeler cette méthode avec la même matrice en argument qu'en appelant - #ifdef NAZARA_DEBUG + #if NAZARA_MATH_SAFE + if (!IsAffine()) + { + NazaraError("Matrix is not affine"); + return false; + } + if (!dest) { NazaraError("Destination matrix must be valid"); @@ -294,7 +310,7 @@ bool NzMatrix4::GetInverseAffine(NzMatrix4* dest) const } #endif - T det = GetDeterminant(); + T det = GetDeterminantAffine(); if (!NzNumberEquals(det, F(0.0))) { // http://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix @@ -432,17 +448,6 @@ NzMatrix4& NzMatrix4::Inverse(bool* succeeded) template NzMatrix4& NzMatrix4::InverseAffine(bool* succeeded) { - #if NAZARA_MATH_SAFE - if (!IsAffine()) - { - NazaraError("Matrix not affine"); - if (succeeded) - *succeeded = false; - - return *this; - } - #endif - bool result = GetInverseAffine(this); if (succeeded) *succeeded = result;