From aaca9349fdcb358b055acfbb19662d0ab1f98184 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 30 Sep 2012 23:11:43 +0200 Subject: [PATCH] Fixed Matrix4 equality comparison Former-commit-id: cb1e21196c2053138a8d70bc09d39ecbf7b83ba8 --- include/Nazara/Math/Matrix4.hpp | 6 +++++- include/Nazara/Math/Matrix4.inl | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index a8b2cd5cc..51bdaf0ce 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -22,7 +22,8 @@ template class NzVector2; template class NzVector3; template class NzVector4; -template class NzMatrix4 +template +class NzMatrix4 { public: NzMatrix4(); @@ -104,6 +105,9 @@ template class NzMatrix4 NzMatrix4& operator*=(const NzMatrix4& matrix); NzMatrix4& operator*=(T scalar); + bool operator==(const NzMatrix4& mat) const; + bool operator!=(const NzMatrix4& mat) const; + static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2); static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2); static NzMatrix4 Identity(); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 5dbad7f42..3d6d30f7c 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -724,6 +724,28 @@ NzMatrix4& NzMatrix4::operator*=(T scalar) return *this; } +template +bool NzMatrix4::operator==(const NzMatrix4& mat) const +{ + if (!m_sharedMatrix) + return mat.m_sharedMatrix == nullptr; + + if (!mat.m_sharedMatrix) + return false; + + for (unsigned int i = 0; i < 16; ++i) + if (!NzNumberEquals((&m_sharedMatrix->m11)[i])) + return false; + + return true; +} + +template +bool NzMatrix4::operator!=(const NzMatrix4& mat) const +{ + return !operator==(mat); +} + template NzMatrix4 NzMatrix4::Concatenate(const NzMatrix4& m1, const NzMatrix4& m2) {