diff --git a/Eule/Matrix4x4.cpp b/Eule/Matrix4x4.cpp index 1dbb1e4..ee85582 100644 --- a/Eule/Matrix4x4.cpp +++ b/Eule/Matrix4x4.cpp @@ -2,7 +2,7 @@ #include "Vector3.h" #include "Math.h" -#define _EULE_NO_INTRINSICS_ +//#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif @@ -404,6 +404,16 @@ bool Matrix4x4::operator!=(const Matrix4x4& other) return !operator==(other); } +bool Matrix4x4::operator==(const Matrix4x4& other) const +{ + return v == other.v; +} + +bool Matrix4x4::operator!=(const Matrix4x4& other) const +{ + return !operator==(other); +} + const Vector3d Matrix4x4::GetTranslationComponent() const { return Vector3d(d, h, l); @@ -617,7 +627,7 @@ bool Matrix4x4::Similar(const Matrix4x4& other, double epsilon) const namespace Eule { - std::ostream& operator<<(std::ostream& os, const Matrix4x4& m) + std::ostream& operator<< (std::ostream& os, const Matrix4x4& m) { os << std::endl; @@ -632,7 +642,7 @@ namespace Eule return os; } - std::wostream& operator<<(std::wostream& os, const Matrix4x4& m) + std::wostream& operator<< (std::wostream& os, const Matrix4x4& m) { os << std::endl; diff --git a/Eule/Matrix4x4.h b/Eule/Matrix4x4.h index 1a94fbf..b27c010 100644 --- a/Eule/Matrix4x4.h +++ b/Eule/Matrix4x4.h @@ -77,7 +77,9 @@ namespace Eule void operator=(Matrix4x4&& other) noexcept; bool operator==(const Matrix4x4& other); + bool operator==(const Matrix4x4& other) const; bool operator!=(const Matrix4x4& other); + bool operator!=(const Matrix4x4& other) const; //! Will return d,h,l as a Vector3d(x,y,z) const Vector3d GetTranslationComponent() const; @@ -121,8 +123,8 @@ namespace Eule //! Will compare if two matrices are similar to a certain epsilon value bool Similar(const Matrix4x4& other, double epsilon = 0.00001) const; - friend std::ostream& operator<<(std::ostream& os, const Matrix4x4& m); - friend std::wostream& operator<<(std::wostream& os, const Matrix4x4& m); + friend std::ostream& operator<< (std::ostream& os, const Matrix4x4& m); + friend std::wostream& operator<< (std::wostream& os, const Matrix4x4& m); // Shorthands double& a = v[0][0]; diff --git a/Eule/Quaternion.cpp b/Eule/Quaternion.cpp index 55e3504..6d4d305 100644 --- a/Eule/Quaternion.cpp +++ b/Eule/Quaternion.cpp @@ -1,7 +1,7 @@ #include "Quaternion.h" #include "Constants.h" -#define _EULE_NO_INTRINSICS_ +//#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Eule/Vector2.cpp b/Eule/Vector2.cpp index 7b844ab..dcfb857 100644 --- a/Eule/Vector2.cpp +++ b/Eule/Vector2.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -#define _EULE_NO_INTRINSICS_ +//#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Eule/Vector3.cpp b/Eule/Vector3.cpp index 360deb6..b40afc1 100644 --- a/Eule/Vector3.cpp +++ b/Eule/Vector3.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -#define _EULE_NO_INTRINSICS_ +//#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif @@ -673,7 +673,6 @@ void Vector3::operator/=(const T scale) } - // Good, optimized chad version for doubles Vector3 Vector3::operator*(const Matrix4x4& mat) const { @@ -714,9 +713,9 @@ Vector3 Vector3::operator*(const Matrix4x4& mat) const #else // Rotation, Scaling - newVec.x = (mat[0][0] * x) + (mat[1][0] * y) + (mat[2][0] * z); - newVec.y = (mat[0][1] * x) + (mat[1][1] * y) + (mat[2][1] * z); - newVec.z = (mat[0][2] * x) + (mat[1][2] * y) + (mat[2][2] * z); + newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z); + newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z); + newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z); // Translation newVec.x += mat[0][3]; @@ -733,9 +732,9 @@ Vector3 Vector3::operator*(const Matrix4x4& mat) const Vector3 newVec; // Rotation, Scaling - newVec.x = ((mat[0][0] * x) + (mat[1][0] * y) + (mat[2][0] * z)); - newVec.y = ((mat[0][1] * x) + (mat[1][1] * y) + (mat[2][1] * z)); - newVec.z = ((mat[0][2] * x) + (mat[1][2] * y) + (mat[2][2] * z)); + newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z); + newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z); + newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z); // Translation newVec.x += mat[0][3]; diff --git a/Eule/Vector4.cpp b/Eule/Vector4.cpp index 941d68f..850c3bb 100644 --- a/Eule/Vector4.cpp +++ b/Eule/Vector4.cpp @@ -2,7 +2,7 @@ #include "Math.h" #include -#define _EULE_NO_INTRINSICS_ +//#define _EULE_NO_INTRINSICS_ #ifndef _EULE_NO_INTRINSICS_ #include #endif diff --git a/Test/Matrix4x4.cpp b/Test/Matrix4x4.cpp index 0a0747d..aab078e 100644 --- a/Test/Matrix4x4.cpp +++ b/Test/Matrix4x4.cpp @@ -980,5 +980,51 @@ namespace Matrices Assert::IsFalse(a != b); return; } + + // Tests if the equal const operator (==) and not-equals operator (!=) work (equal: false) + TEST_METHOD(Operator_Equals_Const_NotEquals_False) + { + Matrix4x4 a; + a[0] = { 0x0, 0x1, 0x2, 0x3 }; + a[1] = { 0x4, 0x5, 0x6, 0x7 }; + a[2] = { 0x8, 0x9, 0xA, 0xB }; + a[3] = { 0xC, 0xD, 0xE, 0xF }; + + Matrix4x4 b; + b[3] = { 0xF ,0xD, 0xE, 0xC }; + b[2] = { 0xB ,0x9, 0xA, 0x8 }; + b[1] = { 0x7 ,0x5, 0x6, 0x4 }; + b[0] = { 0x3 ,0x1, 0x2, 0x0 }; + + const Matrix4x4 a_const = a; + const Matrix4x4 b_const = b; + + Assert::IsFalse(a_const == b_const); + Assert::IsTrue(a_const != b_const); + return; + } + + // Tests if the equal const operator (==) and not-equals operator (!=) work (equal: true) + TEST_METHOD(Operator_Equals_Const_False) + { + Matrix4x4 a; + a[0] = { 0x0, 0x1, 0x2, 0x3 }; + a[1] = { 0x4, 0x5, 0x6, 0x7 }; + a[2] = { 0x8, 0x9, 0xA, 0xB }; + a[3] = { 0xC, 0xD, 0xE, 0xF }; + + Matrix4x4 b; + b[0] = { 0x0, 0x1, 0x2, 0x3 }; + b[1] = { 0x4, 0x5, 0x6, 0x7 }; + b[2] = { 0x8, 0x9, 0xA, 0xB }; + b[3] = { 0xC, 0xD, 0xE, 0xF }; + + const Matrix4x4 a_const = a; + const Matrix4x4 b_const = b; + + Assert::IsTrue(a_const == b_const); + Assert::IsFalse(a_const != b_const); + return; + } }; } diff --git a/Test/Quaternion.cpp b/Test/Quaternion.cpp index 0444330..6a08562 100644 --- a/Test/Quaternion.cpp +++ b/Test/Quaternion.cpp @@ -128,7 +128,11 @@ namespace TransformRelated Vector3d point(32, 19, -14); - Assert::IsTrue((point * a.ToRotationMatrix()).Similar(a * point)); + // Generate debug output + std::wstringstream ss; + ss << (point * a.ToRotationMatrix()) << std::endl << L"===" << (a * point) << std::endl; + + Assert::IsTrue((point * a.ToRotationMatrix()).Similar(a * point), ss.str().c_str()); } return;