diff --git a/Engine/Source/Runtime/Core/public/Math/IntPoint.hpp b/Engine/Source/Runtime/Core/public/Math/IntPoint.hpp index 7ed2811..1442b0d 100644 --- a/Engine/Source/Runtime/Core/public/Math/IntPoint.hpp +++ b/Engine/Source/Runtime/Core/public/Math/IntPoint.hpp @@ -8,7 +8,7 @@ #include "Core/public/Math/IntVector2.hpp" #include "Core/public/Math/IntVector3.hpp" -// #include "Core/public/Math/IntVector4.h" +#include "Core/public/Math/IntVector4.hpp" #ifndef P_DEBUG #pragma warning(disable : 4244) @@ -29,9 +29,9 @@ namespace Phanes::Core::Math { */ template - struct TIntPoint2 : public TIntVector2 { + struct TIntPoint2 : public TIntVector2 { - using TIntVector2::TIntVector2; + using TIntVector2::TIntVector2; /** * Creates IntPoint2 from IntPoint3's xy @@ -59,12 +59,6 @@ namespace Phanes::Core::Math { //} }; - template - Rt Distance(const TIntPoint2& p1, const TIntPoint2& p2) - { - return Magnitude(p2 - p1); - } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -74,9 +68,9 @@ namespace Phanes::Core::Math { template - struct TIntPoint3 : public TIntVector3 { + struct TIntPoint3 : public TIntVector3 { - using TIntVector3::TIntVector3; + using TIntVector3::TIntVector3; /** * Creates IntPoint3 from IntPoint2's xy and zero @@ -105,12 +99,6 @@ namespace Phanes::Core::Math { //} }; - template - Rt Distance(const TIntPoint3& p1, const TIntPoint3& p2) - { - return Magnitude(p2 - p1); - } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -119,41 +107,39 @@ namespace Phanes::Core::Math { */ - //template - //struct TIntPoint4 : public TIntVector4 { - // static_assert(std::is_integral_v(T), "T must be an integer type."); + template + struct TIntPoint4 : public TIntVector4 { - // using IntVector4::IntVector4; + using TIntVector4::TIntVector4; - // /** - // * Creates IntPoint4 from IntPoint2's xy and the last two zero - // * - // * @param a IntPoint2 one - // */ + /** + * Creates IntPoint4 from IntPoint2's xy and the last two zero + * + * @param a IntPoint2 one + */ - // PHANES_CORE_API IntPoint4(const IntPoint2& a) - // { - // this->components[0] = a.components[0]; - // this->components[1] = a.components[1]; - // this->components[2] = 0; - // this->components[3] = 0; - // } + TIntPoint4(const TIntPoint2& a) + { + this->data[0] = a.data[0]; + this->data[1] = a.data[1]; + this->data[2] = 0; + this->data[3] = 0; + } - // /** - // * Creates IntPoint4 from IntPoint3's xyz and zero - // * - // * @param a IntPoint3 one - // */ - - // PHANES_CORE_API IntPoint4(const IntPoint3& a) - // { - // this->components[0] = a.components[0]; - // this->components[1] = a.components[1]; - // this->components[2] = a.components[2]; - // this->components[3] = 0; - // } - //}; + /** + * Creates IntPoint4 from IntPoint3's xyz and zero + * + * @param a IntPoint3 one + */ + TIntPoint4(const TIntPoint3& a) + { + this->data[0] = a.data[0]; + this->data[1] = a.data[1]; + this->data[2] = a.data[2]; + this->data[3] = 0; + } + }; } // phanes::core::math::coretypes diff --git a/Engine/Source/Runtime/Core/public/Math/IntVector3.hpp b/Engine/Source/Runtime/Core/public/Math/IntVector3.hpp index 3582201..31a9fbd 100644 --- a/Engine/Source/Runtime/Core/public/Math/IntVector3.hpp +++ b/Engine/Source/Runtime/Core/public/Math/IntVector3.hpp @@ -352,6 +352,7 @@ namespace Phanes::Core::Math { // IntVector3 static function implementation // // ============================================== // + /** * Dot product of two vectors * diff --git a/Engine/Source/Runtime/Core/public/Math/IntVector4.hpp b/Engine/Source/Runtime/Core/public/Math/IntVector4.hpp index 61e1168..b875b04 100644 --- a/Engine/Source/Runtime/Core/public/Math/IntVector4.hpp +++ b/Engine/Source/Runtime/Core/public/Math/IntVector4.hpp @@ -441,6 +441,7 @@ namespace Phanes::Core::Math { // TIntVector4 functions // // ========================= // + template void Set(TIntVector4& v1, TIntVector4& v2) { diff --git a/Engine/Source/Runtime/Core/public/Math/Line.hpp b/Engine/Source/Runtime/Core/public/Math/Line.hpp index de6638f..0b3deea 100644 --- a/Engine/Source/Runtime/Core/public/Math/Line.hpp +++ b/Engine/Source/Runtime/Core/public/Math/Line.hpp @@ -22,11 +22,11 @@ namespace Phanes::Core::Math /** Direction of line */ - TVector3 direction; + TVector3 direction; /** Base point of line */ - TVector3 base; + TVector3 base; public: @@ -36,7 +36,7 @@ namespace Phanes::Core::Math * @param(p) Base of line */ - TLine(const TVector3& direction, const TVector3& p) : direction(direction), base(p) {}; + TLine(const TVector3& direction, const TVector3& p) : direction(direction), base(p) {}; }; diff --git a/Engine/Source/Runtime/Core/public/Math/MathFwd.h b/Engine/Source/Runtime/Core/public/Math/MathFwd.h index 5b511c6..8787a99 100644 --- a/Engine/Source/Runtime/Core/public/Math/MathFwd.h +++ b/Engine/Source/Runtime/Core/public/Math/MathFwd.h @@ -27,9 +27,7 @@ namespace Phanes::Core::Math { template struct TColor; template struct TLinearColor; - template struct TRay; template struct TLine; - template struct TPlane; template struct TQuaternion; template struct TTransform; template struct TPoint2; @@ -47,11 +45,50 @@ namespace Phanes::Core::Math { template struct TIntVector2; template struct TIntVector3; template struct TIntVector4; + template struct TPlane; + template struct TRay; /** * Specific instantiation of forward declarations. */ + // TPoint2 + + typedef TPoint2 Point2; + typedef TPoint2 Point2f; + typedef TPoint2 Point2d; + + // TPoint3 + + typedef TPoint3 Point3; + typedef TPoint3 Point3f; + typedef TPoint3 Point3d; + + // TPoint4 + + typedef TPoint4 Point4; + typedef TPoint4 Point4f; + typedef TPoint4 Point4d; + + + // TIntPoint2 + + typedef TIntPoint2 IntPoint2; + typedef TIntPoint2 IntPoint2i; + typedef TIntPoint2 IntPoint2l; + + // TIntPoint3 + + typedef TIntPoint3 IntPoint3; + typedef TIntPoint3 IntPoint3i; + typedef TIntPoint3 IntPoint3l; + + // TIntPoint4 + + typedef TIntPoint4 IntPoint4; + typedef TIntPoint4 IntPoint4i; + typedef TIntPoint4 IntPoint4l; + // IntVetor2 typedef TIntVector2 IntVector2; @@ -123,7 +160,7 @@ namespace Phanes::Core::Math { typedef TMatrix3::value> Matrix3Reg; typedef TMatrix3::value> Matrix3Regf; typedef TMatrix3::value> Matrix3Regd; - typedef TMatrix3::value> Matrix3Regf64; + typedef TMatrix3::value> Matrix3Regf64; // Matrix4 @@ -134,7 +171,19 @@ namespace Phanes::Core::Math { typedef TMatrix3::value> Matrix4Reg; typedef TMatrix3::value> Matrix4Regf; typedef TMatrix3::value> Matrix4Regd; - typedef TMatrix3::value> Matrix4Regf64; + typedef TMatrix3::value> Matrix4Regf64; + + + + // TPlane + + typedef TPlane Plane; + typedef TPlane Planef; + typedef TPlane Planed; + + typedef TPlane::value> PlaneReg; + typedef TPlane::value> PlaneRegd; + } // Phanes::Core::Math::coretypes diff --git a/Engine/Source/Runtime/Core/public/Math/Point.hpp b/Engine/Source/Runtime/Core/public/Math/Point.hpp index 6c3c6d8..ea23952 100644 --- a/Engine/Source/Runtime/Core/public/Math/Point.hpp +++ b/Engine/Source/Runtime/Core/public/Math/Point.hpp @@ -28,10 +28,9 @@ namespace Phanes::Core::Math { */ template - struct TPoint2 : public TVector2 { - static_assert(std::is_floating_point_v, "T must be a floating point"); + struct TPoint2 : public TVector2 { - using TVector2::TVector2; + using TVector2::TVector2; using Real = T; @@ -84,10 +83,9 @@ namespace Phanes::Core::Math { template - struct TPoint3 : public TVector3 { - static_assert(std::is_floating_point_v(T), "T must be a floating point"); + struct TPoint3 : public TVector3 { - using TVector3::TVector3; + using TVector3::TVector3; using Real = T; @@ -141,52 +139,54 @@ namespace Phanes::Core::Math { */ - //template - //struct TPoint4 : public TVector4 { - // static_assert(std::is_floating_point_v(T), "T must be a floating point"); + template + struct TPoint4 : public TVector4 { + + using TVector4::TVector4; + + /** + * Creates Point4 from Point2's xy and the last two zero + * + * @param a Point2 one + */ + + TPoint4(const TPoint2& p) + { + this->x = p.x; + this->y = p.y; + this->z = 0; + this->w = 0; + } + + /** + * Creates Point4 from Point3's xyz and zero + * + * @param a Point3 one + */ + + TPoint4(const TPoint3& p) + { + this->x = p.x; + this->y = p.y; + this->z = p.z; + this->w = 0; + } + }; - // using TVector4::TVector4; + /** + * Calculates distance between two points. + * + * @param(p1) Point one + * @param(p2) Point two + * + * @return Distance between two points. + */ - // /** - // * Creates Point4 from Point2's xy and the last two zero - // * - // * @param a Point2 one - // */ - - // TPoint4(const TPoint2& p) - // { - // this->x = p.x; - // this->y = p.y; - // this->z = 0; - // this->w = 0; - // } - - // /** - // * Creates Point4 from Point3's xyz and zero - // * - // * @param a Point3 one - // */ - - // TPoint4(const TPoint3& p) - // { - // this->x = p.x; - // this->y = p.y; - // this->z = p.z; - // this->w = 0; - // } - //}; - - ///** - // * Calculates distance between two points. - // * - // * @param(p1) Point one - // * @param(p2) Point two - // * - // * @return Distance between two points. - // */ - - //template - //T Distance(const TPoint4& p1, const TPoint4& p2); + template + T Distance(const TPoint4& p1, const TPoint4& p2) + { + return Magnitude(p2 - p1); + } } // phanes::core::math::coretypes diff --git a/Engine/Source/Runtime/Core/public/Math/Ray.hpp b/Engine/Source/Runtime/Core/public/Math/Ray.hpp index 7ea1c79..92a0d9d 100644 --- a/Engine/Source/Runtime/Core/public/Math/Ray.hpp +++ b/Engine/Source/Runtime/Core/public/Math/Ray.hpp @@ -10,24 +10,24 @@ namespace Phanes::Core::Math // Ray with origin and direction (L = p + t * v) - template + template struct TRay { public: using Real = T; - TVector3 origin; - TVector3 direction; + TVector3 origin; + TVector3 direction; public: /** Default constructor */ TRay() = default; /** Copy constructor */ - TRay(const TRay& r) : direction(r.direction), origin(r.origin) {}; + TRay(const TRay& r) : direction(r.direction), origin(r.origin) {}; /** Move constructor */ - TRay(TRay&& r) : direction(std::move(r.direction)), origin(std::move(r.origin)) {}; + TRay(TRay&& r) : direction(std::move(r.direction)), origin(std::move(r.origin)) {}; /** * Construct ray from origin and direction. @@ -36,7 +36,7 @@ namespace Phanes::Core::Math * @param(origin) Origin */ - TRay(const TVector3& direction, const TVector3& origin) : direction(direction), origin(origin) {}; + TRay(const TVector3& direction, const TVector3& origin) : direction(direction), origin(origin) {}; }; @@ -55,7 +55,7 @@ namespace Phanes::Core::Math */ template - FORCEINLINE bool operator== (const TRay& r1, const TRay& r2) + FORCEINLINE bool operator== (const TRay& r1, const TRay& r2) { return (r1.origin == r2.origin && r1.direction == r2.direction); } @@ -70,7 +70,7 @@ namespace Phanes::Core::Math */ template - FORCEINLINE bool operator== (const TRay& r1, const TRay& r2) + FORCEINLINE bool operator!= (const TRay& r1, const TRay& r2) { return (r1.origin != r2.origin || r1.direction != r2.direction); } @@ -89,8 +89,8 @@ namespace Phanes::Core::Math * @return Point at t */ - template - TVector3 PointAt(const TRay& r1, T t) + template + TVector3 PointAt(const TRay& r1, T t) { return r1.origin + r1.direction * t; } @@ -104,8 +104,8 @@ namespace Phanes::Core::Math * @return parameter t */ - template - TVector3 GetParameter(const TRay& r1, const TVector3& p1) + template + TVector3 GetParameter(const TRay& r1, const TVector3& p1) { return DotP((p1 - r1.origin), r1.direction); } @@ -119,8 +119,8 @@ namespace Phanes::Core::Math * @return True, if both rays point in the same direction, false if not. */ - template - inline bool SameDirection(const TRay& r1, const TRay& r2) + template + inline bool SameDirection(const TRay& r1, const TRay& r2) { return (r1.direction == r1.direction); } diff --git a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp index 747be76..cda1c1b 100644 --- a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp +++ b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp @@ -785,16 +785,16 @@ namespace Phanes::Core::Math::Detail // Second column - __m128 tmp0 = _mm_mul_ps(m1.c0.data, m2.c1.data); - __m128 tmp1 = _mm_mul_ps(m1.c1.data, m2.c1.data); - __m128 tmp2 = _mm_mul_ps(m1.c2.data, m2.c1.data); + tmp0 = _mm_mul_ps(m1.c0.data, m2.c1.data); + tmp1 = _mm_mul_ps(m1.c1.data, m2.c1.data); + tmp2 = _mm_mul_ps(m1.c2.data, m2.c1.data); r.c1.data = _mm_add_ps(_mm_add_ps(tmp0, tmp1), tmp2); // Third column - __m128 tmp0 = _mm_mul_ps(m1.c0.data, m2.c2.data); - __m128 tmp1 = _mm_mul_ps(m1.c1.data, m2.c2.data); - __m128 tmp2 = _mm_mul_ps(m1.c2.data, m2.c2.data); + tmp0 = _mm_mul_ps(m1.c0.data, m2.c2.data); + tmp1 = _mm_mul_ps(m1.c1.data, m2.c2.data); + tmp2 = _mm_mul_ps(m1.c2.data, m2.c2.data); r.c2.data = _mm_add_ps(_mm_add_ps(tmp0, tmp1), tmp2); } diff --git a/Engine/Source/Runtime/Core/public/Math/Vector2.inl b/Engine/Source/Runtime/Core/public/Math/Vector2.inl index 432c0b3..fd8b358 100644 --- a/Engine/Source/Runtime/Core/public/Math/Vector2.inl +++ b/Engine/Source/Runtime/Core/public/Math/Vector2.inl @@ -202,4 +202,7 @@ namespace Phanes::Core::Math { return --v1; } + + + } \ No newline at end of file diff --git a/MathTestFPU/test.cpp b/MathTestFPU/test.cpp index 69bd502..214760b 100644 --- a/MathTestFPU/test.cpp +++ b/MathTestFPU/test.cpp @@ -1246,5 +1246,29 @@ namespace MatrixTests 0.356495f, -0.287009f, -0.024169f, 0.033232f)); EXPECT_TRUE(PMath::Transpose(m0) == PMath::Matrix4(1.0f, 2.0f, 2.0f, 8.0f, 5.0f, 6.0f, -3.0f, -4.0f, 3.0f, 4.0f, 5.0f, 6.0f, 4.0f, 1.0f, 3.0f, -2.0f)); + } + +} + +namespace Misc +{ + + TEST(Point, FloatPoint) + { + EXPECT_FLOAT_EQ(PMath::Distance(PMath::Point2(7.0f, 3.0f), PMath::Point2(4.0f, -1.0f)), 5.0f); + EXPECT_FLOAT_EQ(PMath::Distance(PMath::Point3(7.0f, 3.0f, 4.0f), PMath::Point3(4.0f, -1.0f, 3.0f)), 5.099019f); + EXPECT_FLOAT_EQ(PMath::Distance(PMath::Point4(7.0f, 3.0f, 4.0f, 5.0f), PMath::Point4(4.0f, -1.0f, 3.0f, -5.0f)), 11.224972f); + } +} + +namespace Plane +{ + TEST(Plane, OperatorTests) + { + PMath::Plane pl1; + PMath::Plane pl2; + + + } } \ No newline at end of file