diff --git a/Engine/src/Runtime/Core/private/Math/Matrix3.cpp b/Engine/src/Runtime/Core/private/Math/Matrix3.cpp deleted file mode 100644 index c0c2a6b..0000000 --- a/Engine/src/Runtime/Core/private/Math/Matrix3.cpp +++ /dev/null @@ -1,303 +0,0 @@ -// ========================== // -// Matrix3 implementation // -// ========================== // - - - -#include "Misc/CommonDefines.h" -#include PHANES_CORE_PCH_DEFAULT_PATH - -#include "Math/Matrix3.h" - -// ================================= // -// Class Methods for easy access // -// ================================= // - -float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m) -{ - return this->fields[m][n]; -} - -phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m) -{ - return (*reinterpret_cast(this->fields[m])); -} - -const float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m) const -{ - return this->fields[m][n]; -} - -const phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m) const -{ - return (*reinterpret_cast(this->fields[m])); -} - - -// ================= // -// Constructors // -// ================= // - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float fields[3][3]) -{ - Matrix3 a; - std::copy(&fields[0][0], &fields[3][3], &a.fields[0][0]); - return a; -} - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f02, float f10, float f11, float f12, float f20, float f21, float f22) -{ - Matrix3 a; - a.fields[0][0] = f00; a.fields[1][0] = f01; a.fields[2][0] = f02; - a.fields[0][1] = f10; a.fields[1][1] = f11; a.fields[2][1] = f12; - a.fields[0][2] = f20; a.fields[1][2] = f21; a.fields[2][2] = f22; - return a; -} - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(const Vector3& a, const Vector3& b, const Vector3& c) -{ - Matrix3 m; - m.fields[0][0] = a.x; m.fields[1][0] = b.x; m.fields[2][0] = c.x; - m.fields[0][1] = a.y; m.fields[1][1] = b.y; m.fields[2][1] = c.y; - m.fields[0][2] = a.z; m.fields[1][2] = b.z; m.fields[2][2] = c.z; - return m; -} - - -// ============= // -// Operators // -// ============= // - - -void phanes::core::math::coretypes::operator+=(Matrix3& a, float s) -{ - a[0] += s; - a[1] += s; - a[2] += s; -} - - -void phanes::core::math::coretypes::operator+=(Matrix3& a, const Matrix3& b) -{ - a[0] += b[0]; - a[1] += b[1]; - a[2] += b[2]; -} - - -void phanes::core::math::coretypes::operator-=(Matrix3& a, float s) -{ - a[0] -= s; - a[1] -= s; - a[2] -= s; -} - - -void phanes::core::math::coretypes::operator-=(Matrix3& a, const Matrix3& b) -{ - a[0] -= b[0]; - a[1] -= b[1]; - a[2] -= b[2]; -} - - -void phanes::core::math::coretypes::operator*=(Matrix3& a, float s) -{ - a[0] *= s; - a[1] *= s; - a[2] *= s; -} - - -void phanes::core::math::coretypes::operator*=(Matrix3& a, const Matrix3& b) -{ - Matrix3 c = a; - a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0) + c(0, 2) * b(2, 0); - a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1) + c(0, 2) * b(2, 1); - a(0, 2) = c(0, 0) * b(0, 2) + c(0, 1) * b(1, 2) + c(0, 2) * b(2, 2); - - a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0) + c(1, 2) * b(2, 0); - a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1) + c(1, 2) * b(2, 1); - a(1, 2) = c(1, 0) * b(0, 2) + c(1, 1) * b(1, 2) + c(1, 2) * b(2, 2); - - a(2, 0) = c(2, 0) * b(0, 0) + c(2, 1) * b(1, 0) + c(2, 2) * b(2, 0); - a(2, 1) = c(2, 0) * b(0, 1) + c(2, 1) * b(1, 1) + c(2, 2) * b(2, 1); - a(2, 2) = c(2, 0) * b(0, 2) + c(2, 1) * b(1, 2) + c(2, 2) * b(2, 2); -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, float s) -{ - Matrix3 m; - m[0] = a[0] + s; - m[1] = a[1] + s; - m[2] = a[2] + s; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, const Matrix3& b) -{ - Matrix3 m; - m[0] = a[0] + b[0]; - m[1] = a[1] + b[1]; - m[2] = a[2] + b[2]; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, float s) -{ - Matrix3 m; - m[0] = a[0] - s; - m[1] = a[1] - s; - m[2] = a[2] - s; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, const Matrix3& b) -{ - Matrix3 m; - m[0] = a[0] - b[0]; - m[1] = a[1] - b[1]; - m[2] = a[2] - b[2]; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, float s) -{ - Matrix3 m; - m[0] = a[0] * s; - m[1] = a[1] * s; - m[2] = a[2] * s; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Matrix3& b) -{ - Matrix3 m; - - m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0) + a(0, 2) * b(2, 0); - m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1) + a(0, 2) * b(2, 1); - m(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2) * b(2, 2); - - m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0) + a(1, 2) * b(2, 0); - m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1) + a(1, 2) * b(2, 1); - m(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2) * b(2, 2); - - m(2, 0) = a(2, 0) * b(0, 0) + a(2, 1) * b(1, 0) + a(2, 2) * b(2, 0); - m(2, 1) = a(2, 0) * b(0, 1) + a(2, 1) * b(1, 1) + a(2, 2) * b(2, 1); - m(2, 2) = a(2, 0) * b(0, 2) + a(2, 1) * b(1, 2) + a(2, 2) * b(2, 2); - - return m; -} - - -phanes::core::math::coretypes::Vector3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Vector3& v) -{ - Vector3 b = createVector( - a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z, - a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z, - a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z - ); - return b; -} - - -bool phanes::core::math::coretypes::operator==(const Matrix3& a, const Matrix3& b) -{ - if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) { - return true; - } - return false; -} - - -// =============================== // -// Matrix function definition // -// =============================== // - - -float phanes::core::math::coretypes::determinant(const Matrix3& a) -{ - return (a(0, 0) * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1)) - -a(0, 1) * (a(1, 0) * a(2, 2) - a(1, 2) * a(2, 0)) - +a(0, 2) * (a(1, 0) * a(2, 1) - a(1, 1) * a(2, 0))); -} - - -void phanes::core::math::coretypes::inverseNR(Matrix3& a) -{ - const Vector3& v0 = a[0]; - const Vector3& v1 = a[1]; - const Vector3& v2 = a[2]; - - Vector3 r0 = crossP(v1, v2); - Vector3 r1 = crossP(v2, v0); - Vector3 r2 = crossP(v0, v1); - - float _1_det = 1.0f / determinant(a); - - a = createMatrix( - r0.x, r0.y, r0.z, - r1.x, r1.y, r1.z, - r2.x, r2.y, r2.z - ); - - a *= _1_det; -} - - -void phanes::core::math::coretypes::transposeNR(Matrix3& a) -{ - swap(a(0, 1), a(1, 0)); - swap(a(0, 2), a(2, 0)); - swap(a(1, 2), a(2, 1)); -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::inverse(Matrix3& a) -{ - const Vector3& v0 = a[0]; - const Vector3& v1 = a[1]; - const Vector3& v2 = a[2]; - - Vector3 r0 = crossP(v1, v2); - Vector3 r1 = crossP(v2, v0); - Vector3 r2 = crossP(v0, v1); - - float _1_det = 1.0f / determinant(a); - - Matrix3 m = createMatrix( - r0.x, r0.y, r0.z, - r1.x, r1.y, r1.z, - r2.x, r2.y, r2.z - ); - - m *= _1_det; - return m; -} - - -phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::transpose(const Matrix3& a) -{ - Matrix3 m = createMatrix( - a(0, 0), a(1, 0), a(2, 0), - a(0, 1), a(1, 1), a(2, 1), - a(0, 2), a(1, 2), a(2, 2) - ); - - return m; -} - - -bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix3& a) -{ - if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1)) { - return true; - } - return false; -} \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/Math/Boilerplate.h b/Engine/src/Runtime/Core/public/Math/Boilerplate.h new file mode 100644 index 0000000..8306552 --- /dev/null +++ b/Engine/src/Runtime/Core/public/Math/Boilerplate.h @@ -0,0 +1,56 @@ +// Math is independent from the rest of the library, to ensure seamless usage with other client. + +#pragma once + + + + +#ifdef P_BUILD_LIB + #include "PhanesEnginePCH.h" + +#else + #include + +#endif + + +#ifdef P_WIN_BUILD + + #ifdef P_DEBUG + + #define P_DEBUGBREAK DebugBreak(); + + #else + + #define P_DEBUGBREAK + + #endif // P_DEBUG + + #define FORCEINLINE __forceinline + +#elif defined(P_UNIX_BUILD) + + #error Only Windows is supported at the moment. + +#elif defined(P_ARM_BUILD) + + #error Only Windows is supported at the moment. + +#else + + #error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information) + +#endif // P_WIN_BUILD + + + + + + +// Typenames with RealType constrain have to be floating point numbers. +template +concept RealType = std::is_floating_point_v; + +// Typenames with IntType constrain have to be integer number. +template +concept IntType = std::is_integral_v; \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/Math/IntPoint.hpp b/Engine/src/Runtime/Core/public/Math/IntPoint.hpp index c7449d5..7ed2811 100644 --- a/Engine/src/Runtime/Core/public/Math/IntPoint.hpp +++ b/Engine/src/Runtime/Core/public/Math/IntPoint.hpp @@ -1,13 +1,13 @@ #pragma once -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" -#include "Core/public/Math/MathCommon.h" +#include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" #include "Core/public/Math/MathFwd.h" -#include "Core/public/Math/IntVector2.h" -#include "Core/public/Math/IntVector3.h" +#include "Core/public/Math/IntVector2.hpp" +#include "Core/public/Math/IntVector3.hpp" // #include "Core/public/Math/IntVector4.h" #ifndef P_DEBUG diff --git a/Engine/src/Runtime/Core/public/Math/IntVector2.hpp b/Engine/src/Runtime/Core/public/Math/IntVector2.hpp index d692284..6867ea5 100644 --- a/Engine/src/Runtime/Core/public/Math/IntVector2.hpp +++ b/Engine/src/Runtime/Core/public/Math/IntVector2.hpp @@ -1,8 +1,6 @@ #pragma once -#include "Core/Core.h" - -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" diff --git a/Engine/src/Runtime/Core/public/Math/IntVector3.hpp b/Engine/src/Runtime/Core/public/Math/IntVector3.hpp index 1ce9626..b196da7 100644 --- a/Engine/src/Runtime/Core/public/Math/IntVector3.hpp +++ b/Engine/src/Runtime/Core/public/Math/IntVector3.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" diff --git a/Engine/src/Runtime/Core/public/Math/MathCommon.hpp b/Engine/src/Runtime/Core/public/Math/MathCommon.hpp index a6d59d6..efad93c 100644 --- a/Engine/src/Runtime/Core/public/Math/MathCommon.hpp +++ b/Engine/src/Runtime/Core/public/Math/MathCommon.hpp @@ -14,8 +14,6 @@ #define P_PI_FLT 3.1415926535897932f // PI -#include "Core/Core.h" - #ifndef MATH_COMMON_H #define MATH_COMMON_H @@ -114,7 +112,7 @@ namespace Phanes::Core::Math { template float FastInvSqrt(T n) { - Phanes::Core::Types::int32 i = *(int*)&n; + int i = *(int*)&n; float x2 = n * 0.5f; i = 0x5f3759df - (i >> 1); diff --git a/Engine/src/Runtime/Core/public/Math/MathFwd.h b/Engine/src/Runtime/Core/public/Math/MathFwd.h index 3f9f523..b7302fa 100644 --- a/Engine/src/Runtime/Core/public/Math/MathFwd.h +++ b/Engine/src/Runtime/Core/public/Math/MathFwd.h @@ -1,13 +1,15 @@ #pragma once -#include "Core/Core.h" - -#include "Core/public/OSAL/PlatformTypes.h" +#ifdef P_BUILD_LIB + #include "PhanesEnginePCH.h" +#else + #include +#endif #ifndef MATH_FWD_H #define MATH_FWD_H -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" /** * Includes forward declarations, as well as certain useful typedefs. @@ -18,85 +20,92 @@ namespace Phanes::Core::Math { - /** - * Template forward declarations. - */ + /** + * Template forward declarations. + */ - template struct TColor; - template struct TLinearColor; + template struct TColor; + template struct TLinearColor; template struct TVector2; - template struct TVector3; - template struct TVector4; - template struct TRay; - template struct TPlane; - template struct TMatrix2; - template struct TMatrix3; - template struct TMatrix4; - template struct TQuaternion; - template struct TTransform; - template struct TPoint2; - template struct TPoint3; - template struct TPoint4; - template struct TIntVector2; - template struct TIntVector3; - template struct TIntVector4; - template struct TIntPoint2; - template struct TIntPoint3; - template struct TIntPoint4; + template struct TVector3; + template struct TVector4; + template struct TRay; + template struct TPlane; + template struct TMatrix2; + template struct TMatrix3; + template struct TMatrix4; + template struct TQuaternion; + template struct TTransform; + template struct TPoint2; + template struct TPoint3; + template struct TPoint4; + template struct TIntVector2; + template struct TIntVector3; + template struct TIntVector4; + template struct TIntPoint2; + template struct TIntPoint3; + template struct TIntPoint4; - /** - * Specific instantiation of forward declarations. - */ + /** + * Specific instantiation of forward declarations. + */ - // TVector2 - typedef TVector2 Vector2; - typedef TVector2 Vector2d; + // TVector2 + typedef TVector2 Vector2; + typedef TVector2 Vector2d; - typedef std::vector Vector2List; - typedef std::vector Vector2Listd; + typedef std::vector Vector2List; + typedef std::vector Vector2Listd; - // TVector3 - typedef TVector3 Vector3; - typedef TVector3 Vector3d; + // TVector3 + typedef TVector3 Vector3; + typedef TVector3 Vector3d; - typedef std::vector Vector3List; - typedef std::vector Vector3Listd; + typedef std::vector Vector3List; + typedef std::vector Vector3Listd; - // TIntVector2 - typedef TIntVector2 IntVector2; - typedef TIntVector2 IntVector2l; + // TIntVector2 + typedef TIntVector2 IntVector2; + typedef TIntVector2 IntVector2l; - typedef std::vector IntVector2List; - typedef std::vector IntVector2Listl; + typedef std::vector IntVector2List; + typedef std::vector IntVector2Listl; - // TIntVector3 - typedef TIntVector3 IntVector3; - typedef TIntVector3 IntVector3l; + // TIntVector3 + typedef TIntVector3 IntVector3; + typedef TIntVector3 IntVector3l; - typedef std::vector IntVector3List; - typedef std::vector IntVector3Listl; + typedef std::vector IntVector3List; + typedef std::vector IntVector3Listl; - // TMatrix2 - typedef TMatrix2 Matrix2; - typedef TMatrix2 Matrix2d; + // TMatrix2 + typedef TMatrix2 Matrix2; + typedef TMatrix2 Matrix2d; - typedef std::vector Matrix2List; - typedef std::vector Matrix2Listd; + typedef std::vector Matrix2List; + typedef std::vector Matrix2Listd; + + // TMatrix3 + typedef TMatrix3 Matrix3; + typedef TMatrix3 Matrix3d; + + typedef std::vector Matrix3List; + typedef std::vector Matrix3Listd; } // Phanes::Core::Math::coretypes namespace Phanes::Core::Math::Internal { - // Internal types + // Internal types - template struct AVector; + template struct AVector; - template struct AMatrix; + template struct AMatrix; } diff --git a/Engine/src/Runtime/Core/public/Math/MathPCH.h b/Engine/src/Runtime/Core/public/Math/MathPCH.h new file mode 100644 index 0000000..ca313f7 --- /dev/null +++ b/Engine/src/Runtime/Core/public/Math/MathPCH.h @@ -0,0 +1,20 @@ +// Header file containing all files to be compiled to use core math. +// Should be included in PCH file of project to use. + +#pragma once + +#include "Point.hpp" +#include "Plane.hpp" +#include "Vector2.hpp" +#include "Vector3.hpp" + +#include "IntPoint.hpp" +#include "IntVector2.hpp" +#include "IntVector3.hpp" + +#include "Matrix2.hpp" +#include "Matrix3.hpp" + +#include "MathCommon.hpp" +#include "MathTypeConversion.hpp" +#include "MathUnitConversion.hpp" \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/Math/MathTypeConversion.hpp b/Engine/src/Runtime/Core/public/Math/MathTypeConversion.hpp index e650448..488e940 100644 --- a/Engine/src/Runtime/Core/public/Math/MathTypeConversion.hpp +++ b/Engine/src/Runtime/Core/public/Math/MathTypeConversion.hpp @@ -6,8 +6,13 @@ // @ref [FILE]MathUnitConversion // // ============================================= // -#include "PhanesEnginePCH.h" -#include "Core/public/Misc/Boilerplate.h" +#ifdef P_BUILD_LIB + #include "PhanesEnginePCH.h" +#else + #include +#endif + +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathAbstractTypes.h" #include "Core/public/Math/Vector2.hpp" @@ -16,7 +21,7 @@ #include "Core/public/Math/Matrix2.hpp" //#include "Core/public/Math/Matrix3.h" #include "Core/public/Math/IntVector2.hpp" -#include "Core/public/Math/IntVector3.h" +#include "Core/public/Math/IntVector3.hpp" #ifndef MATH_TYPE_CONVERSION_H #define MATH_TYPE_CONVERSION_H @@ -84,7 +89,7 @@ namespace Phanes::Core::Math { template std::string toString(const TMatrix2& m) { - return "[[" + ToString(m.m(0, 0)) + " " + ToString(m.m(0, 1)) + "], [" + ToString(m.m(0, 0)) + " " + ToString(m.m(0, 1)) + "]]" + return "[[" + ToString(m.m(0, 0)) + " " + ToString(m.m(0, 1)) + "], [" + ToString(m.m(0, 0)) + " " + ToString(m.m(0, 1)) + "]]"; } //std::string toString(const Matrix3& v); diff --git a/Engine/src/Runtime/Core/public/Math/MathUnitConversion.hpp b/Engine/src/Runtime/Core/public/Math/MathUnitConversion.hpp index 24b4cd2..66f6db1 100644 --- a/Engine/src/Runtime/Core/public/Math/MathUnitConversion.hpp +++ b/Engine/src/Runtime/Core/public/Math/MathUnitConversion.hpp @@ -4,7 +4,7 @@ // Contains functions to convert units // // ======================================= // -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" diff --git a/Engine/src/Runtime/Core/public/Math/Matrix2.hpp b/Engine/src/Runtime/Core/public/Math/Matrix2.hpp index d8a59e3..0ca94fa 100644 --- a/Engine/src/Runtime/Core/public/Math/Matrix2.hpp +++ b/Engine/src/Runtime/Core/public/Math/Matrix2.hpp @@ -1,7 +1,6 @@ #pragma once -#include "Core/Core.h" -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/Vector2.hpp" @@ -96,14 +95,6 @@ namespace Phanes::Core::Math { return reinterpret_cast(this->m[m]); } - FORCEINLINE const T& operator() (int n, int m) const - { - return this->m[m][n]; - } - FORCEINLINE const TVector2& operator[] (int m) const - { - return reinterpret_cast(this->m[m]); - } }; // ===================== // @@ -190,7 +181,7 @@ namespace Phanes::Core::Math { TMatrix2 operator+ (const TMatrix2& m1, const TMatrix2& m2) { return TMatrix2(m1(0, 0) + m2(0, 0), m1(0, 1) + m2(0, 1), - m1(1, 0) + m2(1, 0), m1(1, 1) + m2(1, 1); + m1(1, 0) + m2(1, 0), m1(1, 1) + m2(1, 1)); } template @@ -204,7 +195,7 @@ namespace Phanes::Core::Math { TMatrix2 operator- (const TMatrix2& m1, const TMatrix2& m2) { return TMatrix2(m1(0, 0) - m2(0, 0), m1(0, 1) - m2(0, 1), - m1(1, 0) - m2(1, 0), m1(1, 1) - m2(1, 1); + m1(1, 0) - m2(1, 0), m1(1, 1) - m2(1, 1)); } template diff --git a/Engine/src/Runtime/Core/public/Math/Matrix3.hpp b/Engine/src/Runtime/Core/public/Math/Matrix3.hpp index 01876c9..f1f85ef 100644 --- a/Engine/src/Runtime/Core/public/Math/Matrix3.hpp +++ b/Engine/src/Runtime/Core/public/Math/Matrix3.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathAbstractTypes.h" #include "Core/public/Math/Vector3.hpp" @@ -15,11 +15,11 @@ namespace Phanes::Core::Math { // Accessed by M[Row][Col]. template - struct alignas(9) TMatrix3 + struct TMatrix3 { public: - alignas(9) T m[3][3]; + T m[3][3]; public: @@ -35,16 +35,6 @@ namespace Phanes::Core::Math { memcpy(this->m, m1.m, sizeof(T) * 9); } - /** - * Move constructor. - */ - - TMatrix3(TMatrix3&& m) - { - this->m = m.m; - m.m = nullptr; - } - /** * Construct Matrix from 2d array. * @@ -53,9 +43,9 @@ namespace Phanes::Core::Math { TMatrix3(T fields[2][2]) { - this->m[0][0] = fields[0][0]; this->m[1][0] = fields[1][0]; this->[2][0] = fields[2][0]; - this->m[0][1] = fields[0][1]; this->m[1][1] = fields[1][1]; this->[2][1] = fields[2][1]; - this->m[0][2] = fields[0][2]; this->m[1][2] = fields[1][2]; this->[2][2] = fields[2][2]; + this->m[0][0] = fields[0][0]; this->m[1][0] = fields[1][0]; this->m[2][0] = fields[2][0]; + this->m[0][1] = fields[0][1]; this->m[1][1] = fields[1][1]; this->m[2][1] = fields[2][1]; + this->m[0][2] = fields[0][2]; this->m[1][2] = fields[1][2]; this->m[2][2] = fields[2][2]; } /** @@ -73,9 +63,9 @@ namespace Phanes::Core::Math { T n10, T n11, T n12, T n20, T n21, T n22) { - this->m[0][0] = n00; this->m[1][0] = n01; this->[2][0] = n02; - this->m[1][0] = n10; this->m[1][1] = n11; this->[2][1] = n12; - this->m[1][2] = n20; this->m[1][2] = n21; this->[2][2] = n22; + this->m[0][0] = n00; this->m[1][0] = n01; this->m[2][0] = n02; + this->m[1][0] = n10; this->m[1][1] = n11; this->m[2][1] = n12; + this->m[1][2] = n20; this->m[1][2] = n21; this->m[2][2] = n22; } /** @@ -87,31 +77,31 @@ namespace Phanes::Core::Math { TMatrix3(const TVector3& v1, const TVector3& v2, const TVector3 v3) { - this->m[0][0] = v1.x; this->m[1][0] = v2.x; this->[2][0] = v3.x; - this->m[0][1] = v1.y; this->m[1][1] = v2.y; this->[2][1] = v3.y; - this->m[0][2] = v1.z; this->m[1][2] = v2.z; this->[2][2] = v3.z; + this->m[0][0] = v1.x; this->m[1][0] = v2.x; this->m[2][0] = v3.x; + this->m[0][1] = v1.y; this->m[1][1] = v2.y; this->m[2][1] = v3.y; + this->m[0][2] = v1.z; this->m[1][2] = v2.z; this->m[2][2] = v3.z; } public: FORCEINLINE T& operator() (int n, int m) { - return this->[m][n]; + return this->m[m][n]; } FORCEINLINE TVector3& operator[] (int m) { - return reinterpret_cast*>(this->m[m]); + return (*reinterpret_cast*>(this->m[m])); } FORCEINLINE const T& operator() (int n, int m) const { - return this->[m][n]; + return this->m[m][n]; } FORCEINLINE const TVector3& operator[] (int m) const { - return reinterpret_cast*>(this->m[m]); + return (*reinterpret_cast*>(this->m[m])); } }; @@ -129,11 +119,11 @@ namespace Phanes::Core::Math { */ template - TMatrix3 operator+= (TMatrix3& m, T s) + TMatrix3 operator+= (TMatrix3& m1, T s) { - m(0, 0) += s; m(0, 1) += s; m(0, 2) += s; - m(1, 0) += s; m(1, 1) += s; m(1, 2) += s; - m(2, 0) += s; m(2, 1) += s; m(2, 2) += s; + m1(0, 0) += s; m1(0, 1) += s; m1(0, 2) += s; + m1(1, 0) += s; m1(1, 1) += s; m1(1, 2) += s; + m1(2, 0) += s; m1(2, 1) += s; m1(2, 2) += s; return m1; } @@ -163,11 +153,11 @@ namespace Phanes::Core::Math { */ template - TMatrix3 operator-= (TMatrix3& a, T s) + TMatrix3 operator-= (TMatrix3& m1, T s) { - m(0, 0) -= s; m(0, 1) -= s; m(0, 2) -= s; - m(1, 0) -= s; m(1, 1) -= s; m(1, 2) -= s; - m(2, 0) -= s; m(2, 1) -= s; m(2, 2) -= s; + m1(0, 0) -= s; m1(0, 1) -= s; m1(0, 2) -= s; + m1(1, 0) -= s; m1(1, 1) -= s; m1(1, 2) -= s; + m1(2, 0) -= s; m1(2, 1) -= s; m1(2, 2) -= s; return m1; } @@ -197,11 +187,11 @@ namespace Phanes::Core::Math { */ template - TMatrix3 operator*= (TMatrix3& m, T s) + TMatrix3 operator*= (TMatrix3& m1, T s) { - m(0, 0) *= s; m(0, 1) *= s; m(0, 2) *= s; - m(1, 0) *= s; m(1, 1) *= s; m(1, 2) *= s; - m(2, 0) *= s; m(2, 1) *= s; m(2, 2) *= s; + m1(0, 0) *= s; m1(0, 1) *= s; m1(0, 2) *= s; + m1(1, 0) *= s; m1(1, 1) *= s; m1(1, 2) *= s; + m1(2, 0) *= s; m1(2, 1) *= s; m1(2, 2) *= s; return m1; } @@ -216,7 +206,7 @@ namespace Phanes::Core::Math { template TMatrix3 operator*= (TMatrix3& m1, const TMatrix3& m2) { - TMatrix3 c = a; + TMatrix3 c = m1; m1(0, 0) = c(0, 0) * m2(0, 0) + c(0, 1) * m2(1, 0) + c(0, 2) * m2(2, 0); m1(0, 1) = c(0, 0) * m2(0, 1) + c(0, 1) * m2(1, 1) + c(0, 2) * m2(2, 1); m1(0, 2) = c(0, 0) * m2(0, 2) + c(0, 1) * m2(1, 2) + c(0, 2) * m2(2, 2); @@ -462,7 +452,7 @@ namespace Phanes::Core::Math { TVector3 r1 = CrossP(v2, v0); TVector3 r2 = CrossP(v0, v1); - T _1_det = (T)1.0 / determinant(m1); + T _1_det = (T)1.0 / Determinant(m1); TMatrix3 inverse(r0.x, r0.y, r0.z, r1.x, r1.y, r1.z, diff --git a/Engine/src/Runtime/Core/public/Math/Plane.hpp b/Engine/src/Runtime/Core/public/Math/Plane.hpp index b64ec07..ab9492b 100644 --- a/Engine/src/Runtime/Core/public/Math/Plane.hpp +++ b/Engine/src/Runtime/Core/public/Math/Plane.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathFwd.h" #include "Core/public/Math/Vector3.hpp" diff --git a/Engine/src/Runtime/Core/public/Math/Point.hpp b/Engine/src/Runtime/Core/public/Math/Point.hpp index afd2a36..6c3c6d8 100644 --- a/Engine/src/Runtime/Core/public/Math/Point.hpp +++ b/Engine/src/Runtime/Core/public/Math/Point.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" diff --git a/Engine/src/Runtime/Core/public/Math/Vector2.hpp b/Engine/src/Runtime/Core/public/Math/Vector2.hpp index a1a5a1c..77a4c91 100644 --- a/Engine/src/Runtime/Core/public/Math/Vector2.hpp +++ b/Engine/src/Runtime/Core/public/Math/Vector2.hpp @@ -1,7 +1,6 @@ #pragma once -#include "Core/Core.h" -#include "Core/public/Misc/Boilerplate.h" +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" diff --git a/Engine/src/Runtime/Core/public/Math/Vector3.hpp b/Engine/src/Runtime/Core/public/Math/Vector3.hpp index fcca152..4e6475c 100644 --- a/Engine/src/Runtime/Core/public/Math/Vector3.hpp +++ b/Engine/src/Runtime/Core/public/Math/Vector3.hpp @@ -5,8 +5,8 @@ // TODO: ClampToCube // TODO: Slerp (using Quaternions) -#include "Core/Core.h" -#include "Core/public/Misc/Boilerplate.h" + +#include "Core/public/Math/Boilerplate.h" #include "Core/public/Math/MathCommon.hpp" #include "Core/public/Math/MathAbstractTypes.h" diff --git a/Engine/src/Runtime/PhanesEnginePCH.h b/Engine/src/Runtime/PhanesEnginePCH.h index 6474d3f..e8e5b7f 100644 --- a/Engine/src/Runtime/PhanesEnginePCH.h +++ b/Engine/src/Runtime/PhanesEnginePCH.h @@ -6,34 +6,38 @@ #define NOMAXMIN #ifndef PHANES_CORE_PCH_H - + - // STL + // STL - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #include - #include + #include + #include - #include - #include + #include + #include - #ifdef P_WIN_BUILD + #ifdef P_WIN_BUILD - #include + #include - #endif + #endif - // spdlog - #include - #include + + // spdlog + #include + #include + + // Local PCH + #include "Core/public/Math/MathPCH.h" #endif // !PHANES_CORE_PCH_H diff --git a/Tests/TestProject/Main.cpp b/Tests/TestProject/Main.cpp index 76eff4f..29fbe71 100644 --- a/Tests/TestProject/Main.cpp +++ b/Tests/TestProject/Main.cpp @@ -1,11 +1,38 @@ +#include "Core/public/Math/MathPCH.h" + + #include +#include + + + +namespace PMath = Phanes::Core::Math; + int main() { - int x = 13; - x %= 7; - std::cout << x; - + PMath::TMatrix2 m1(7.3f,4.3f, + 9.4f,2.5f); + + + + + for (int i = 0; i < 10; i++) + { + auto start = std::chrono::high_resolution_clock::now(); + + for (size_t i = 0; i < 999999; i++) + { + + + } + auto end = std::chrono::high_resolution_clock::now(); + + std::cout << std::chrono::duration_cast(end - start).count() << std::endl; + } + + return 0; + } \ No newline at end of file