Fixed discrepancy between compiler intrinsics mode and unparallelized mode. Also added const * *= operator to matrix.
This commit is contained in:
parent
b168289208
commit
2a505e0321
@ -2,7 +2,7 @@
|
|||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
|
|
||||||
#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
@ -404,6 +404,16 @@ bool Matrix4x4::operator!=(const Matrix4x4& other)
|
|||||||
return !operator==(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
|
const Vector3d Matrix4x4::GetTranslationComponent() const
|
||||||
{
|
{
|
||||||
return Vector3d(d, h, l);
|
return Vector3d(d, h, l);
|
||||||
@ -617,7 +627,7 @@ bool Matrix4x4::Similar(const Matrix4x4& other, double epsilon) const
|
|||||||
|
|
||||||
namespace Eule
|
namespace Eule
|
||||||
{
|
{
|
||||||
std::ostream& operator<<(std::ostream& os, const Matrix4x4& m)
|
std::ostream& operator<< (std::ostream& os, const Matrix4x4& m)
|
||||||
{
|
{
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
@ -632,7 +642,7 @@ namespace Eule
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wostream& operator<<(std::wostream& os, const Matrix4x4& m)
|
std::wostream& operator<< (std::wostream& os, const Matrix4x4& m)
|
||||||
{
|
{
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
|
@ -77,7 +77,9 @@ namespace Eule
|
|||||||
void operator=(Matrix4x4&& other) noexcept;
|
void operator=(Matrix4x4&& other) noexcept;
|
||||||
|
|
||||||
bool operator==(const Matrix4x4& other);
|
bool operator==(const Matrix4x4& other);
|
||||||
|
bool operator==(const Matrix4x4& other) const;
|
||||||
bool operator!=(const Matrix4x4& other);
|
bool operator!=(const Matrix4x4& other);
|
||||||
|
bool operator!=(const Matrix4x4& other) const;
|
||||||
|
|
||||||
//! Will return d,h,l as a Vector3d(x,y,z)
|
//! Will return d,h,l as a Vector3d(x,y,z)
|
||||||
const Vector3d GetTranslationComponent() const;
|
const Vector3d GetTranslationComponent() const;
|
||||||
@ -121,8 +123,8 @@ namespace Eule
|
|||||||
//! Will compare if two matrices are similar to a certain epsilon value
|
//! Will compare if two matrices are similar to a certain epsilon value
|
||||||
bool Similar(const Matrix4x4& other, double epsilon = 0.00001) const;
|
bool Similar(const Matrix4x4& other, double epsilon = 0.00001) const;
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Matrix4x4& m);
|
friend std::ostream& operator<< (std::ostream& os, const Matrix4x4& m);
|
||||||
friend std::wostream& operator<<(std::wostream& os, const Matrix4x4& m);
|
friend std::wostream& operator<< (std::wostream& os, const Matrix4x4& m);
|
||||||
|
|
||||||
// Shorthands
|
// Shorthands
|
||||||
double& a = v[0][0];
|
double& a = v[0][0];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Quaternion.h"
|
#include "Quaternion.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
|
||||||
#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
@ -673,7 +673,6 @@ void Vector3<T>::operator/=(const T scale)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Good, optimized chad version for doubles
|
// Good, optimized chad version for doubles
|
||||||
Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
||||||
{
|
{
|
||||||
@ -714,9 +713,9 @@ Vector3<double> Vector3<double>::operator*(const Matrix4x4& mat) const
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
// Rotation, Scaling
|
// Rotation, Scaling
|
||||||
newVec.x = (mat[0][0] * x) + (mat[1][0] * y) + (mat[2][0] * z);
|
newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z);
|
||||||
newVec.y = (mat[0][1] * x) + (mat[1][1] * y) + (mat[2][1] * z);
|
newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z);
|
||||||
newVec.z = (mat[0][2] * x) + (mat[1][2] * y) + (mat[2][2] * z);
|
newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z);
|
||||||
|
|
||||||
// Translation
|
// Translation
|
||||||
newVec.x += mat[0][3];
|
newVec.x += mat[0][3];
|
||||||
@ -733,9 +732,9 @@ Vector3<int> Vector3<int>::operator*(const Matrix4x4& mat) const
|
|||||||
Vector3<double> newVec;
|
Vector3<double> newVec;
|
||||||
|
|
||||||
// Rotation, Scaling
|
// Rotation, Scaling
|
||||||
newVec.x = ((mat[0][0] * x) + (mat[1][0] * y) + (mat[2][0] * z));
|
newVec.x = (mat[0][0] * x) + (mat[0][1] * y) + (mat[0][2] * z);
|
||||||
newVec.y = ((mat[0][1] * x) + (mat[1][1] * y) + (mat[2][1] * z));
|
newVec.y = (mat[1][0] * x) + (mat[1][1] * y) + (mat[1][2] * z);
|
||||||
newVec.z = ((mat[0][2] * x) + (mat[1][2] * y) + (mat[2][2] * z));
|
newVec.z = (mat[2][0] * x) + (mat[2][1] * y) + (mat[2][2] * z);
|
||||||
|
|
||||||
// Translation
|
// Translation
|
||||||
newVec.x += mat[0][3];
|
newVec.x += mat[0][3];
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define _EULE_NO_INTRINSICS_
|
//#define _EULE_NO_INTRINSICS_
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -980,5 +980,51 @@ namespace Matrices
|
|||||||
Assert::IsFalse(a != b);
|
Assert::IsFalse(a != b);
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,11 @@ namespace TransformRelated
|
|||||||
|
|
||||||
Vector3d point(32, 19, -14);
|
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;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user