diff --git a/Engine/src/Runtime/Core/Core.h b/Engine/src/Runtime/Core/Core.h index 80942d0..0625e01 100644 --- a/Engine/src/Runtime/Core/Core.h +++ b/Engine/src/Runtime/Core/Core.h @@ -3,28 +3,28 @@ #ifdef P_WIN_BUILD - #ifdef P_DEBUG - - #define P_DEBUGBREAK DebugBreak(); + #ifdef P_DEBUG + + #define P_DEBUGBREAK DebugBreak(); - #else - - #define P_DEBUGBREAK + #else + + #define P_DEBUGBREAK - #endif // P_DEBUG + #endif // P_DEBUG - #define FORCEINLINE __forceinline + #define FORCEINLINE __forceinline #elif defined(P_UNIX_BUILD) - #error Only Windows is supported at the moment. + #error Only Windows is supported at the moment. #elif defined(P_ARM_BUILD) - - #error Only Windows is supported at the moment. + + #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) + #error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information) #endif // P_WIN_BUILD \ No newline at end of file diff --git a/Engine/src/Runtime/Core/private/Math/IntPoint.cpp b/Engine/src/Runtime/Core/private/Math/IntPoint.cpp index 6334390..a6936e9 100644 --- a/Engine/src/Runtime/Core/private/Math/IntPoint.cpp +++ b/Engine/src/Runtime/Core/private/Math/IntPoint.cpp @@ -9,7 +9,7 @@ template Rt Phanes::Core::Math::Distance(const TIntPoint2& p1, const TIntPoint2& p2) { - return Magnitude(p2 - p1); + return Magnitude(p2 - p1); } // ----- TIntPoint3 ------------------------------------------ @@ -18,5 +18,5 @@ Rt Phanes::Core::Math::Distance(const TIntPoint2& p1, const TIntPoint2& p2 template Rt Phanes::Core::Math::Distance(const TIntPoint3& p1, const TIntPoint3& p2) { - return Magnitude(p2 - p1); + return Magnitude(p2 - p1); } \ No newline at end of file diff --git a/Engine/src/Runtime/Core/private/Math/IntVector2.cpp b/Engine/src/Runtime/Core/private/Math/IntVector2.cpp index 29eb20d..f770a06 100644 --- a/Engine/src/Runtime/Core/private/Math/IntVector2.cpp +++ b/Engine/src/Runtime/Core/private/Math/IntVector2.cpp @@ -25,42 +25,42 @@ template Phanes::Core::Math::TIntVector2::TIntVector2(const T x, const T y) { - this->x = x; - this->y = y; + this->x = x; + this->y = y; } template Phanes::Core::Math::TIntVector2::TIntVector2(const T* comp) { - static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components."); - memcpy(this->comp, comp, sizeof(T) * 2); + static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components."); + memcpy(this->comp, comp, sizeof(T) * 2); } template Phanes::Core::Math::TIntVector2::TIntVector2(const TIntPoint2& start, const TIntPoint2& end) { - this->x = end.x - start.x; - this->y = end.y - start.y; + this->x = end.x - start.x; + this->y = end.y - start.y; } template Phanes::Core::Math::TIntVector2::TIntVector2(const TIntVector3& v) { - this->x = v.x; - this->y = v.y; + this->x = v.x; + this->y = v.y; } template Phanes::Core::Math::TIntVector2::TIntVector2(const TIntVector2& v) { - memcpy(this->comp, comp, sizeof(T) * 2); + memcpy(this->comp, comp, sizeof(T) * 2); } template Phanes::Core::Math::TIntVector2::TIntVector2(TIntVector2&& v) { - this->comp = v.comp; - v.comp = nullptr; + this->comp = v.comp; + v.comp = nullptr; } @@ -71,254 +71,254 @@ Phanes::Core::Math::TIntVector2::TIntVector2(TIntVector2&& v) template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator+=(TIntVector2& v1, T s) { - v1.x += s; - v1.y += s; + v1.x += s; + v1.y += s; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator+=(TIntVector2& v1, const TIntVector2& v2) { - v1.x += v2.x; - v1.y += v2.y; + v1.x += v2.x; + v1.y += v2.y; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator-=(TIntVector2& v1, T s) { - v1.x -= s; - v1.y -= s; + v1.x -= s; + v1.y -= s; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator-=(TIntVector2& v1, const TIntVector2& v2) { - v1.x -= v2.x; - v1.y -= v2.y; + v1.x -= v2.x; + v1.y -= v2.y; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator*=(TIntVector2& v1, T s) { - v1.x *= s; - v1.y *= s; + v1.x *= s; + v1.y *= s; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator*(const TIntVector2& v1, T s) { - return TIntVector2(v1.x * s, v1.y * s); + return TIntVector2(v1.x * s, v1.y * s); } template inline Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator*(T s, const TIntVector2& v1) { - return v1 * s; + return v1 * s; } template Rt Phanes::Core::Math::operator* (const TIntVector2& v1, const TIntVector2& v2) { - return v1.x * v2.x + v1.y * v2.y; + return v1.x * v2.x + v1.y * v2.y; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator+(const TIntVector2& v1, T s) { - return TIntVector2(v1.x + s, v1.y + s); + return TIntVector2(v1.x + s, v1.y + s); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator+(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(v1.x + v2.x, v1.y + v2.y); + return TIntVector2(v1.x + v2.x, v1.y + v2.y); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator-(const TIntVector2& v1, T s) { - return TIntVector2(v1.x - s, v1.y - s); + return TIntVector2(v1.x - s, v1.y - s); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::operator-(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(v1.x - v2.x, v1.y - v2.y); + return TIntVector2(v1.x - v2.x, v1.y - v2.y); } template void Phanes::Core::Math::operator-(TIntVector2& v1) { - v1.x = -v1.x; - v1.y = -v1.y; + v1.x = -v1.x; + v1.y = -v1.y; } template bool Phanes::Core::Math::operator== (const TIntVector2& v1, const TIntVector2& v2) { - return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC); + return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC); } template bool Phanes::Core::Math::operator!=(const TIntVector2& v1, const TIntVector2& v2) { - return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC); + return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC); } template Rt Phanes::Core::Math::Magnitude(const TIntVector2& v1) { - return sqrtf(v1.x * v1.x + v1.y * v1.y); + return sqrtf(v1.x * v1.x + v1.y * v1.y); } template T Phanes::Core::Math::SqrMagnitude(const TIntVector2& v1) { - return v1.x * v1.x + v1.y * v1.y; + return v1.x * v1.x + v1.y * v1.y; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::DivideTruncV(TIntVector2& v1, T s) { - Rt _s = (Rt)1.0 / s; + Rt _s = (Rt)1.0 / s; - v1.x = trunc(v1.x * s); - v1.y = trunc(v1.y * s); + v1.x = trunc(v1.x * s); + v1.y = trunc(v1.y * s); - return v1; + return v1; } template Rt Phanes::Core::Math::Angle(const TIntVector2& v1, const TIntVector2& v2) { - return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); + return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); } template Rt Phanes::Core::Math::CosineAngle(const TIntVector2& v1, const TIntVector2& v2) { - return (v1 * v2) / Magnitude(v1) * Magnitude(v2); + return (v1 * v2) / Magnitude(v1) * Magnitude(v2); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::SignVectorV(TIntVector2& v1) { - v1.x = (v1.x > 0) ? 1 : -1; - v1.y = (v1.y > 0) ? 1 : -1; + v1.x = (v1.x > 0) ? 1 : -1; + v1.y = (v1.y > 0) ? 1 : -1; - return v1; + return v1; } template T Phanes::Core::Math::DotP(const TIntVector2& v1, const TIntVector2& v2) { - return v1.x * v2.x + v1.y * v2.y; + return v1.x * v2.x + v1.y * v2.y; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::MaxV(TIntVector2& v1, const TIntVector2& v2) { - v1.x = Phanes::Core::Math::Max(v1.x, v2.x); - v1.y = Phanes::Core::Math::Max(v1.y, v2.y); + v1.x = Phanes::Core::Math::Max(v1.x, v2.x); + v1.y = Phanes::Core::Math::Max(v1.y, v2.y); - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::MinV(TIntVector2& v1, const TIntVector2& v2) { - v1.x = Phanes::Core::Math::Min(v1.x, v2.x); - v1.y = Phanes::Core::Math::Min(v1.y, v2.y); + v1.x = Phanes::Core::Math::Min(v1.x, v2.x); + v1.y = Phanes::Core::Math::Min(v1.y, v2.y); - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::GetPerpendicularV(TIntVector2& v1) { - T x = v1.x; - v1.x = v1.y; - v1.y = -v1.x; + T x = v1.x; + v1.x = v1.y; + v1.y = -v1.x; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::GetReversePerpendicularV(TIntVector2& v1) { - T x = v1.x; - v1.x = -v1.y; - v1.y = v1.x; + T x = v1.x; + v1.x = -v1.y; + v1.y = v1.x; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::ScaleV(TIntVector2& v1, const TIntVector2& v2) { - v1.x *= v2.x; - v1.y *= v2.y; + v1.x *= v2.x; + v1.y *= v2.y; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Set(TIntVector2& v1, const TIntVector2& v2) { - v1 = v2; + v1 = v2; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Set(TIntVector2& v1, T x, T y) { - v1.x = x; - v1.y = y; + v1.x = x; + v1.y = y; - return v1; + return v1; } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::NegateV(TIntVector2& v1) { - v1.x = -v1.x; - v1.y = -v1.y; + v1.x = -v1.x; + v1.y = -v1.y; } template inline bool Phanes::Core::Math::IsNormalized(const TIntVector2& v1) { - return (SqrMagnitude(v1)); + return (SqrMagnitude(v1)); } template inline bool Phanes::Core::Math::IsPerpendicular(const TIntVector2& v1, const TIntVector2& v2) { - return (abs(DotP(v1, v2)) = 0); + return (abs(DotP(v1, v2)) = 0); } template inline bool Phanes::Core::Math::IsParallel(const TIntVector2& v1, const TIntVector2& v2) { - return (abs(DotP(v1, v2)) = 1); + return (abs(DotP(v1, v2)) = 1); } template inline bool Phanes::Core::Math::IsCoincident(const TIntVector2& v1, const TIntVector2& v2) { - return (DotP(v1, v2) > 1); + return (DotP(v1, v2) > 1); } // @@ -337,125 +337,125 @@ inline bool Phanes::Core::Math::IsCoincident(const TIntVector2& v1, const TIn template Phanes::Core::Math::TVector2 Phanes::Core::Math::Reflect(const TIntVector2& v1, const TVector2& normal) { - return TVector2(v1 - (2 * (v1 * normal) * normal)); + return TVector2(v1 - (2 * (v1 * normal) * normal)); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Scale(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(v1.x * v2.x, v1.y * v2.y); + return TIntVector2(v1.x * v2.x, v1.y * v2.y); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::CompInverse(const TIntVector2& v1) { - return TVector2(1.0f / v1.x, 1.0f / v1.y); + return TVector2(1.0f / v1.x, 1.0f / v1.y); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Negate(const TIntVector2& v1) { - return TIntVector2(-v1.x, -v1.y); + return TIntVector2(-v1.x, -v1.y); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::GetPerpendicular(const TIntVector2& v1) { - return TIntVector2(v1.y, -v1.x); + return TIntVector2(v1.y, -v1.x); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::GetReversePerpendicular(const TIntVector2& v1) { - return TIntVector2(-v1.y, v1.x); + return TIntVector2(-v1.y, v1.x); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Min(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); + return TIntVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::Max(const TIntVector2& v1, const TIntVector2& v2) { - return TIntVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); + return TIntVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Normalize(const TIntVector2& v1) { - float vecNorm = Magnitude(v1); - return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm); + float vecNorm = Magnitude(v1); + return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::UnsafeNormalize(const TIntVector2& v1) { - return TVector2(v1 / Magnitude(v1)); + return TVector2(v1 / Magnitude(v1)); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::SignVector(const TIntVector2& v1) { - return TIntVector2((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); + return TIntVector2((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::BindToSquare(const TIntVector2& v1, T radius) { - float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); - return v1 * k; + float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); + return v1 * k; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClampToSquare(const TIntVector2& v1, T radius) { - float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; - float k = (prime > radius) ? abs(radius / prime) : 1.0f; + float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; + float k = (prime > radius) ? abs(radius / prime) : 1.0f; - return TVector2(v1 * k); + return TVector2(v1 * k); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Lerp(const TIntVector2& startVec, const TIntVector2& destVec, Rt t) { - t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0); + t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0); - return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec); + return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::LerpUnclamped(const TIntVector2& startVec, const TIntVector2& destVec, Rt t) { - return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec); + return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Rotate(const TIntVector2& v1, Rt angle) { - float sinAngle = sin(angle); - float cosAngle = cos(angle); + float sinAngle = sin(angle); + float cosAngle = cos(angle); - return TVector2((Rt)v1.x * cosAngle - (Rt)v1.y * sinAngle, (Rt)v1.y * cosAngle + (Rt)v1.x * sinAngle); + return TVector2((Rt)v1.x * cosAngle - (Rt)v1.y * sinAngle, (Rt)v1.y * cosAngle + (Rt)v1.x * sinAngle); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClockwiseRotate(const TIntVector2& v1, Rt angle) { - return Rotate(v1, -angle); + return Rotate(v1, -angle); } template Phanes::Core::Math::TIntVector2 Phanes::Core::Math::DivideTrunc(const TIntVector2& v1, T s) { - Rt _s = (Rt)1.0 / s; - return TIntVector2(trunc(v1.x * _s), trunc(v1.y * _s)); + Rt _s = (Rt)1.0 / s; + return TIntVector2(trunc(v1.x * _s), trunc(v1.y * _s)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::DivideFloat(const TIntVector2& v1, T s) { - Rt _s = (Rt)1.0 / s; - return TIntVector2((Rt)v1.x * _s, (Rt)v1.y * _s); + Rt _s = (Rt)1.0 / s; + return TIntVector2((Rt)v1.x * _s, (Rt)v1.y * _s); } diff --git a/Engine/src/Runtime/Core/private/Math/IntVector3.cpp b/Engine/src/Runtime/Core/private/Math/IntVector3.cpp index 0148b94..4e8d81f 100644 --- a/Engine/src/Runtime/Core/private/Math/IntVector3.cpp +++ b/Engine/src/Runtime/Core/private/Math/IntVector3.cpp @@ -177,8 +177,6 @@ bool Phanes::Core::Math::operator!=(const TIntVector3& v1, const TIntVector3< // TIntVector3 function implementation // // ======================================= // - - template Rt Phanes::Core::Math::Magnitude(const TIntVector3& v1) { diff --git a/Engine/src/Runtime/Core/private/Math/MathCommon.cpp b/Engine/src/Runtime/Core/private/Math/MathCommon.cpp index 4a44082..d673e3d 100644 --- a/Engine/src/Runtime/Core/private/Math/MathCommon.cpp +++ b/Engine/src/Runtime/Core/private/Math/MathCommon.cpp @@ -54,4 +54,4 @@ float Phanes::Core::Math::FastInvSqrt(T n) n = n * (1.5f - (x2 * n * n)); return n; -} +} \ No newline at end of file diff --git a/Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp b/Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp index fd6300d..c4a0934 100644 --- a/Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp +++ b/Engine/src/Runtime/Core/private/Math/MathTypeConversion.cpp @@ -7,26 +7,26 @@ template std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector2& v) { - return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; + return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; } template std::string Phanes::Core::Math::ToString(const TIntVector2& v) { - return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; + return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; } template std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector3& v) { - return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")"; + return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")"; } template std::string Phanes::Core::Math::ToString(const TIntVector3& v) { - std::to_string(3); + std::to_string(3); - return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")"; + return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ", " + std::to_string(v.z) + ")"; } //template diff --git a/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp b/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp index 58da39f..e43776b 100644 --- a/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp +++ b/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp @@ -2,6 +2,7 @@ #include "Core/public/Math/MathUnitConversion.h" + template inline T Phanes::Core::Math::UnitConversion::DegToRad(T deg) { diff --git a/Engine/src/Runtime/Core/private/Math/Point.cpp b/Engine/src/Runtime/Core/private/Math/Point.cpp index 5e455e3..75228b4 100644 --- a/Engine/src/Runtime/Core/private/Math/Point.cpp +++ b/Engine/src/Runtime/Core/private/Math/Point.cpp @@ -12,7 +12,7 @@ template T Phanes::Core::Math::Distance(const TPoint2& p1, const TPoint2& p2) { - return Magnitude(p2 - p1); + return Magnitude(p2 - p1); } @@ -21,7 +21,7 @@ T Phanes::Core::Math::Distance(const TPoint2& p1, const TPoint2& p2) template T Phanes::Core::Math::Distance(const TPoint3& p1, const TPoint3& p2) { - return Magnitude(p2 - p1); + return Magnitude(p2 - p1); } diff --git a/Engine/src/Runtime/Core/private/Math/Vector2.cpp b/Engine/src/Runtime/Core/private/Math/Vector2.cpp index 41f2926..d9a8de7 100644 --- a/Engine/src/Runtime/Core/private/Math/Vector2.cpp +++ b/Engine/src/Runtime/Core/private/Math/Vector2.cpp @@ -25,42 +25,42 @@ template Phanes::Core::Math::TVector2::TVector2(const Real x, const Real y) { - this->x = x; - this->y = y; + this->x = x; + this->y = y; } template Phanes::Core::Math::TVector2::TVector2(const Real* comp) { - static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components."); - memcpy(this->comp, comp, sizeof(T) * 2); + static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components."); + memcpy(this->comp, comp, sizeof(T) * 2); } template Phanes::Core::Math::TVector2::TVector2(const TPoint2& start, const TPoint2& end) { - this->x = end.x - start.x; - this->y = end.y - start.y; + this->x = end.x - start.x; + this->y = end.y - start.y; } template Phanes::Core::Math::TVector2::TVector2(const TVector3& v) { - this->x = v.x; - this->y = v.y; + this->x = v.x; + this->y = v.y; } template Phanes::Core::Math::TVector2::TVector2(const TVector2& v) { - memcpy(this->comp, comp, sizeof(T) * 2); + memcpy(this->comp, comp, sizeof(T) * 2); } template Phanes::Core::Math::TVector2::TVector2(TVector2&& v) { - this->comp = v.comp; - v.comp = nullptr; + this->comp = v.comp; + v.comp = nullptr; } @@ -107,340 +107,340 @@ Phanes::Core::Math::TVector2::TVector2(TVector2&& v) template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator+=(TVector2& v1, T s) { - v1.x += s; - v1.y += s; + v1.x += s; + v1.y += s; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator+=(TVector2& v1, const TVector2& v2) { - v1.x += v2.x; - v1.y += v2.y; + v1.x += v2.x; + v1.y += v2.y; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator-=(TVector2& v1, T s) { - v1.x -= s; - v1.y -= s; + v1.x -= s; + v1.y -= s; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator-=(TVector2& v1, const TVector2& v2) { - v1.x -= v2.x; - v1.y -= v2.y; + v1.x -= v2.x; + v1.y -= v2.y; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator*=(TVector2& v1, T s) { - v1.x *= s; - v1.y *= s; + v1.x *= s; + v1.y *= s; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator/=(TVector2& v1, T s) { - s = 1.0f / s; - v1.x *= s; - v1.y *= s; + s = 1.0f / s; + v1.x *= s; + v1.y *= s; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator*(const TVector2& v1, T s) { - return TVector2(v1.x * s, v1.y * s); + return TVector2(v1.x * s, v1.y * s); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator/(const TVector2& v1, T s) { - s = 1.0f / s; - return TVector2(v1.x * s, v1.y * s); + s = 1.0f / s; + return TVector2(v1.x * s, v1.y * s); } template inline Phanes::Core::Math::TVector2 Phanes::Core::Math::operator*(T s, const TVector2& v1) { - return v1 * s; + return v1 * s; } template inline Phanes::Core::Math::TVector2 Phanes::Core::Math::operator/(T s, const TVector2& v1) { - s = 1.0f / s; - return v1 * s; + s = 1.0f / s; + return v1 * s; } template T Phanes::Core::Math::operator* (const TVector2& v1, const TVector2& v2) { - return v1.x * v2.x + v1.y * v2.y; + return v1.x * v2.x + v1.y * v2.y; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator+(const TVector2& v1, T s) { - return TVector2(v1.x + s, v1.y + s); + return TVector2(v1.x + s, v1.y + s); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator+(const TVector2& v1, const TVector2& v2) { - return TVector2(v1.x + v2.x, v1.y + v2.y); + return TVector2(v1.x + v2.x, v1.y + v2.y); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator-(const TVector2& v1, T s) { - return TVector2(v1.x - s, v1.y - s); + return TVector2(v1.x - s, v1.y - s); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::operator-(const TVector2& v1, const TVector2& v2) { - return TVector2(v1.x - v2.x, v1.y - v2.y); + return TVector2(v1.x - v2.x, v1.y - v2.y); } template void Phanes::Core::Math::operator-(TVector2& v1) { - v1.x = -v1.x; - v1.y = -v1.y; + v1.x = -v1.x; + v1.y = -v1.y; } template bool Phanes::Core::Math::operator== (const TVector2& v1, const TVector2& v2) { - return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC); + return (abs(v1.x - v1.x) < P_FLT_INAC && abs(v1.y - v1.y) < P_FLT_INAC); } template bool Phanes::Core::Math::operator!=(const TVector2& v1, const TVector2& v2) { - return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC); + return (abs(v1.x - v1.x) > P_FLT_INAC || abs(v1.y - v1.y) > P_FLT_INAC); } template T Phanes::Core::Math::Magnitude(const TVector2& v1) { - return sqrtf(v1.x * v1.x + v1.y * v1.y); + return sqrtf(v1.x * v1.x + v1.y * v1.y); } template T Phanes::Core::Math::SqrMagnitude(const TVector2& v1) { - return v1.x * v1.x + v1.y * v1.y; + return v1.x * v1.x + v1.y * v1.y; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::NormalizeV(TVector2& v1) { - float vecNorm = Magnitude(v1); - v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; - return v1; + float vecNorm = Magnitude(v1); + v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::UnsafeNormalizeV(TVector2& v1) { - v1 /= Magnitude(v1); + v1 /= Magnitude(v1); - return v1; + return v1; } template T Phanes::Core::Math::Angle(const TVector2& v1, const TVector2& v2) { - return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); + return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); } template T Phanes::Core::Math::CosineAngle(const TVector2& v1, const TVector2& v2) { - return (v1 * v2) / Magnitude(v1) * Magnitude(v2); + return (v1 * v2) / Magnitude(v1) * Magnitude(v2); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::SignVectorV(TVector2& v1) { - v1.x = (v1.x > 0) ? 1 : -1; - v1.y = (v1.y > 0) ? 1 : -1; + v1.x = (v1.x > 0) ? 1 : -1; + v1.y = (v1.y > 0) ? 1 : -1; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::BindToSquareV(TVector2& v1, T radius) { - float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); - v1 *= k; + float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); + v1 *= k; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClampToSquareV(TVector2& v1, T radius) { - float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; - float k = (prime > radius) ? abs(radius / prime) : 1.0f; - v1 *= k; + float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; + float k = (prime > radius) ? abs(radius / prime) : 1.0f; + v1 *= k; - return v1; + return v1; } template T Phanes::Core::Math::DotP(const TVector2& v1, const TVector2& v2) { - return v1.x * v2.x + v1.y * v2.y; + return v1.x * v2.x + v1.y * v2.y; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::MaxV(TVector2& v1, const TVector2& v2) { - v1.x = Phanes::Core::Math::Max(v1.x, v2.x); - v1.y = Phanes::Core::Math::Max(v1.y, v2.y); + v1.x = Phanes::Core::Math::Max(v1.x, v2.x); + v1.y = Phanes::Core::Math::Max(v1.y, v2.y); - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::MinV(TVector2& v1, const TVector2& v2) { - v1.x = Phanes::Core::Math::Min(v1.x, v2.x); - v1.y = Phanes::Core::Math::Min(v1.y, v2.y); + v1.x = Phanes::Core::Math::Min(v1.x, v2.x); + v1.y = Phanes::Core::Math::Min(v1.y, v2.y); - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::GetPerpendicularV(TVector2& v1) { - T x = v1.x; - v1.x = v1.y; - v1.y = -v1.x; + T x = v1.x; + v1.x = v1.y; + v1.y = -v1.x; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::GetReversePerpendicularV(TVector2& v1) { - T x = v1.x; - v1.x = -v1.y; - v1.y = v1.x; + T x = v1.x; + v1.x = -v1.y; + v1.y = v1.x; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ScaleV(TVector2& v1, const TVector2& v2) { - v1.x *= v2.x; - v1.y *= v2.y; + v1.x *= v2.x; + v1.y *= v2.y; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::CompInverseV(TVector2& v1) { - v1.x = 1.0f / v1.x; - v1.y = 1.0f / v1.y; - - return v1; + v1.x = 1.0f / v1.x; + v1.y = 1.0f / v1.y; + + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ReflectV(TVector2& v1, const TVector2& normal) { - Set(v1, v1 - (2 * (v1 * normal) * normal)); + Set(v1, v1 - (2 * (v1 * normal) * normal)); - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Set(TVector2& v1, const TVector2& v2) { - v1 = v2; + v1 = v2; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Set(TVector2& v1, T x, T y) { - v1.x = x; - v1.y = y; + v1.x = x; + v1.y = y; - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::RotateV(TVector2& v1, T angle) { - float sinAngle = sin(angle); - float cosAngle = cos(angle); + float sinAngle = sin(angle); + float cosAngle = cos(angle); - Set(v1, - v1.x * cosAngle - v1.y * sinAngle, - v1.y * cosAngle + v1.x * sinAngle - ); + Set(v1, + v1.x * cosAngle - v1.y * sinAngle, + v1.y * cosAngle + v1.x * sinAngle + ); - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClockwiseRotateV(TVector2& v1, T angle) { - RotateV(v1, -angle); + RotateV(v1, -angle); - return v1; + return v1; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::NegateV(TVector2& v1) { - v1.x = -v1.x; - v1.y = -v1.y; + v1.x = -v1.x; + v1.y = -v1.y; } template inline bool Phanes::Core::Math::IsNormalized(const TVector2& v1, T threshold) { - return (SqrMagnitude(v1) < threshold); + return (SqrMagnitude(v1) < threshold); } template inline bool Phanes::Core::Math::IsPerpendicular(const TVector2& v1, const TVector2& v2, T threshold) { - return (abs(DotP(v1, v2)) < threshold); + return (abs(DotP(v1, v2)) < threshold); } template inline bool Phanes::Core::Math::IsParallel(const TVector2& v1, const TVector2& v2, T threshold) { - return (abs(DotP(v1,v2)) > threshold); + return (abs(DotP(v1,v2)) > threshold); } template inline bool Phanes::Core::Math::IsCoincident(const TVector2& v1, const TVector2& v2, T threshold) { - return (DotP(v1, v2) > threshold); + return (DotP(v1, v2) > threshold); } // @@ -459,112 +459,112 @@ inline bool Phanes::Core::Math::IsCoincident(const TVector2& v1, const TVecto template Phanes::Core::Math::TVector2 Phanes::Core::Math::Reflect(const TVector2& v1, const TVector2& normal) { - return TVector2(v1 - (2 * (v1 * normal) * normal)); + return TVector2(v1 - (2 * (v1 * normal) * normal)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Scale(const TVector2& v1, const TVector2& v2) { - return TVector2(v1.x * v2.x, v1.y * v2.y); + return TVector2(v1.x * v2.x, v1.y * v2.y); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::CompInverse(const TVector2& v1) { - return TVector2(1.0f / v1.x, 1.0f / v1.y); + return TVector2(1.0f / v1.x, 1.0f / v1.y); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Negate(const TVector2& v1) { - return TVector2(-v1.x, -v1.y); + return TVector2(-v1.x, -v1.y); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::GetPerpendicular(const TVector2& v1) { - return TVector2(v1.y, -v1.x); + return TVector2(v1.y, -v1.x); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::GetReversePerpendicular(const TVector2& v1) { - return TVector2(-v1.y, v1.x); + return TVector2(-v1.y, v1.x); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Min(const TVector2& v1, const TVector2& v2) { - return TVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); + return TVector2(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Max(const TVector2& v1, const TVector2& v2) { - return TVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); + return TVector2(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Normalize(const TVector2& v1) { - float vecNorm = Magnitude(v1); - return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm); + float vecNorm = Magnitude(v1); + return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::UnsafeNormalize(const TVector2& v1) { - return (v1 / Magnitude(v1)); + return (v1 / Magnitude(v1)); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::SignVector(const TVector2& v1) { - return TVector2((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); + return TVector2((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::BindToSquare(const TVector2& v1, T radius) { - float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); - return v1 * k; + float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); + return v1 * k; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClampToSquare(const TVector2& v1, T radius) { - float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; - float k = (prime > radius) ? abs(radius / prime) : 1.0f; + float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; + float k = (prime > radius) ? abs(radius / prime) : 1.0f; - return v1 * k; + return v1 * k; } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Lerp(const TVector2& startVec, const TVector2& destVec, T t) { - t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0); - - return (t * destVec) + ((1 - t) * startVec); + t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0); + + return (t * destVec) + ((1 - t) * startVec); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::LerpUnclamped(const TVector2& startVec, const TVector2& destVec, T t) { - return (t * destVec) + ((1 - t) * startVec); + return (t * destVec) + ((1 - t) * startVec); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::Rotate(const TVector2& v1, T angle) { - float sinAngle = sin(angle); - float cosAngle = cos(angle); + float sinAngle = sin(angle); + float cosAngle = cos(angle); - return TVector2(v1.x * cosAngle - v1.y * sinAngle, - v1.y * cosAngle + v1.x * sinAngle); + return TVector2(v1.x * cosAngle - v1.y * sinAngle, + v1.y * cosAngle + v1.x * sinAngle); } template Phanes::Core::Math::TVector2 Phanes::Core::Math::ClockwiseRotate(const TVector2& v1, T angle) { - return Rotate(v1, -angle); + return Rotate(v1, -angle); } \ No newline at end of file diff --git a/Engine/src/Runtime/Core/private/Math/Vector3.cpp b/Engine/src/Runtime/Core/private/Math/Vector3.cpp index 6b0b12e..24e8384 100644 --- a/Engine/src/Runtime/Core/private/Math/Vector3.cpp +++ b/Engine/src/Runtime/Core/private/Math/Vector3.cpp @@ -12,37 +12,37 @@ template inline Phanes::Core::Math::TVector3::TVector3(const Real x, const Real y, const Real z) { - this->x = x; - this->y = y; - this->z = z; + this->x = x; + this->y = y; + this->z = z; } template Phanes::Core::Math::TVector3::TVector3(const Real* comp) { - static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector3.cpp): Setting 3D vector coordinates by an array, comp must have a size of at least 3 components."); - memcpy(this->comp, comp, sizeof(T) * 3); + static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector3.cpp): Setting 3D vector coordinates by an array, comp must have a size of at least 3 components."); + memcpy(this->comp, comp, sizeof(T) * 3); } template Phanes::Core::Math::TVector3::TVector3(const TPoint3& start, const TPoint3& end) { - this->x = end.x - start.x; - this->y = end.y - start.y; - this->z = end.z - start.z; + this->x = end.x - start.x; + this->y = end.y - start.y; + this->z = end.z - start.z; } template Phanes::Core::Math::TVector3::TVector3(const TVector3& v) { - memcpy(this->comp, comp, sizeof(T) * 3); + memcpy(this->comp, comp, sizeof(T) * 3); } template Phanes::Core::Math::TVector3::TVector3(TVector3&& v) { - this->comp = v.comp; - v.comp = nullptr; + this->comp = v.comp; + v.comp = nullptr; } @@ -55,139 +55,139 @@ Phanes::Core::Math::TVector3::TVector3(TVector3&& v) template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator+=(TVector3& v1, T s) { - v1.x += s; - v1.y += s; - v1.z += s; + v1.x += s; + v1.y += s; + v1.z += s; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator+=(TVector3& v1, const TVector3& v2) { - v1.x += v2.x; - v1.y += v2.y; - v1.z += v2.z; + v1.x += v2.x; + v1.y += v2.y; + v1.z += v2.z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator-=(TVector3& v1, T s) { - v1.x -= s; - v1.y -= s; - v1.z -= s; + v1.x -= s; + v1.y -= s; + v1.z -= s; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator-=(TVector3& v1, const TVector3& v2) { - v1.x -= v2.x; - v1.y -= v2.y; - v1.z -= v2.z; + v1.x -= v2.x; + v1.y -= v2.y; + v1.z -= v2.z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator*=(TVector3& v1, T s) { - v1.x *= s; - v1.y *= s; - v1.z *= s; + v1.x *= s; + v1.y *= s; + v1.z *= s; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator/=(TVector3& v1, T s) { - s = (T)1.0 / s; - v1.x *= s; - v1.y *= s; - v1.z *= s; + s = (T)1.0 / s; + v1.x *= s; + v1.y *= s; + v1.z *= s; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator*(const TVector3& v1, T s) { - return TVector3(v1.x * s. v1.y * s, v1.z * s); + return TVector3(v1.x * s. v1.y * s, v1.z * s); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator/(const TVector3& v1, T s) { - s = (T)1.0 / s; - return TVector3(v1.x * s.v1.y * s, v1.z * s); + s = (T)1.0 / s; + return TVector3(v1.x * s.v1.y * s, v1.z * s); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator*(T s, const TVector3& v1) { - return v1 * s; + return v1 * s; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator/(T s, const TVector3& v1) { - return v1 / s; + return v1 / s; } template T Phanes::Core::Math::operator*(const TVector3& v1, const TVector3& v2) { - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; + return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator+(const TVector3& v1, T s) { - return TVector3(v1.x + s.v1.y + s, v1.z + s); + return TVector3(v1.x + s.v1.y + s, v1.z + s); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator+(const TVector3& v1, const TVector3& v2) { - return TVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); + return TVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator-(const TVector3& v1, T s) { - return TVector3(v1.x - s.v1.y - s, v1.z - s); + return TVector3(v1.x - s.v1.y - s, v1.z - s); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator-(const TVector3& v1, const TVector3& v2) { - return TVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); + return TVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::operator-(TVector3& v1) { - v1.x = -v1.x; - v1.y = -v1.y; - v1.z = -v1.z; + v1.x = -v1.x; + v1.y = -v1.y; + v1.z = -v1.z; - return v1; + return v1; } template bool Phanes::Core::Math::operator==(const TVector3& v1, const TVector3& v2) { - return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC); + return (abs(v1.x - v2.x) < P_FLT_INAC && abs(v1.y - v2.y) < P_FLT_INAC && abs(v1.z - v2.z) < P_FLT_INAC); } template bool Phanes::Core::Math::operator!=(const TVector3& v1, const TVector3& v2) { - return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC); + return (abs(v1.x - v2.x) > P_FLT_INAC || abs(v1.y - v2.y) > P_FLT_INAC || abs(v1.z - v2.z) > P_FLT_INAC); } // ==================================== // @@ -197,381 +197,381 @@ bool Phanes::Core::Math::operator!=(const TVector3& v1, const TVector3& v2 template T Phanes::Core::Math::Magnitude(const TVector3& v1) { - return sqrt(DotP(v1, v1)); + return sqrt(DotP(v1, v1)); } template T Phanes::Core::Math::SqrMagnitude(const TVector3& v1) { - return DotP(v1, v1); + return DotP(v1, v1); } template T Phanes::Core::Math::SqrLength(const TVector3& v1) { - return SqrMagnitude(v1); + return SqrMagnitude(v1); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::NormalizeV(TVector3& v1) { - float vecNorm = Magnitude(v1); - v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; + float vecNorm = Magnitude(v1); + v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::UnsafeNormalizeV(TVector3& v1) { - v1 /= Magnitude(v1); + v1 /= Magnitude(v1); - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectV(TVector3& v1, const TVector3& normal) { - Set(v1, v1 - (2 * (v1 * normal) * normal)); + Set(v1, v1 - (2 * (v1 * normal) * normal)); - return v1; + return v1; } template T Phanes::Core::Math::Angle(const TVector3& v1, const TVector3& v2) { - return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2))); + return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2))); } template T Phanes::Core::Math::DotP(const TVector3& v1, const TVector3& v2) { - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; + return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } template void Phanes::Core::Math::Orthogonalize(TVector3& v1, TVector3& v2, TVector3& v3) { - Set(v2, Reject(v2, v1)); - Set(v3, Reject(Reject(v3, v1), v2)); + Set(v2, Reject(v2, v1)); + Set(v3, Reject(Reject(v3, v1), v2)); } template void Phanes::Core::Math::OrthoNormalize(TVector3& v1, TVector3& v2, TVector3& v3) { - Set(v2, Reject(v2, v1)); - Set(v3, Reject(Reject(v3, v1), v2)); + Set(v2, Reject(v2, v1)); + Set(v3, Reject(Reject(v3, v1), v2)); - NormalizeV(v1); - NormalizeV(v2); - NormalizeV(v3); + NormalizeV(v1); + NormalizeV(v2); + NormalizeV(v3); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ScaleToMagnitude(const TVector3& v1, T magnitude) { - NormalizeV(v1) *= magnitude; + NormalizeV(v1) *= magnitude; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::CompInverse(const TVector3& v1) { - return TVector3((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z); + return TVector3((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlane(const TVector3& v1, const TPlane& plane) { - return Reflect(v1, plane.normal); + return Reflect(v1, plane.normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlane(const TVector3& v1, const TVector3& normal) { - return Reflect(v1, normal); + return Reflect(v1, normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::RotateAroundAxis(const TVector3& v1, const TVector3& axisNormal, T angle) { - T sinAngle = sin(angle); - T cosAngle = cos(angle); + T sinAngle = sin(angle); + T cosAngle = cos(angle); - return (1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal); + return (1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::VectorTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) { - return CrossP(CrossP(v1, v2), v3); + return CrossP(CrossP(v1, v2), v3); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Project(const TVector3& v1, const TVector3& v2) { - return (DotP(v1, v2) / DotP(v2, v2)) * v2; + return (DotP(v1, v2) / DotP(v2, v2)) * v2; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Reject(const TVector3& v1, const TVector3& v2) { - return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2; + return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlane(const TVector3& v1, const TVector3& normal) { - return Reject(v1, normal); + return Reject(v1, normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlane(const TVector3& v1, const TPlane& plane) { - return Reject(v1, plane.normal); + return Reject(v1, plane.normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::SignVector(const TVector3& v1) { - v1.x = (v1.x > 0) - (v1.x < 0); - v1.y = (v1.y > 0) - (v1.y < 0); - v1.z = (v1.z > 0) - (v1.z < 0); + v1.x = (v1.x > 0) - (v1.x < 0); + v1.y = (v1.y > 0) - (v1.y < 0); + v1.z = (v1.z > 0) - (v1.z < 0); - return v1; + return v1; } template bool Phanes::Core::Math::Equals(const TVector3& v1, const TVector3& v2, T threshold) { - return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold); + return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::PerspectiveDivideV(TVector3& v1) { - float _z = (T)1.0 / v1.z; - v1.x *= _z; - v1.y *= _z; - v1.z = (T)0.0; - return v1; + float _z = (T)1.0 / v1.z; + v1.x *= _z; + v1.y *= _z; + v1.z = (T)0.0; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::CrossPV(TVector3& v1, const TVector3& v2) { - float x = v1.x; - float y = v1.y; - float z = v1.z; + float x = v1.x; + float y = v1.y; + float z = v1.z; - v1.x = (y * v2.z) - (z * v2.y); - v1.y = (z * v2.x) - (x * v2.z); - v1.z = (x * v2.y) - (y * v2.x); + v1.x = (y * v2.z) - (z * v2.y); + v1.y = (z * v2.x) - (x * v2.z); + v1.z = (x * v2.y) - (y * v2.x); - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::MaxV(TVector3& v1, const TVector3& v2) { - v1.x = Max(v1.x, v2.x); - v1.y = Max(v1.y, v2.y); - v1.z = Max(v1.z, v2.z); + v1.x = Max(v1.x, v2.x); + v1.y = Max(v1.y, v2.y); + v1.z = Max(v1.z, v2.z); - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::MinV(TVector3& v1, const TVector3& v2) { - v1.x = Min(v1.x, v2.x); - v1.y = Min(v1.y, v2.y); - v1.z = Min(v1.z, v2.z); + v1.x = Min(v1.x, v2.x); + v1.y = Min(v1.y, v2.y); + v1.z = Min(v1.z, v2.z); - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::NegateV(TVector3& v1) { - v1.x = -v1.x; - v1.y = -v1.y; - v1.z = -v1.z; + v1.x = -v1.x; + v1.y = -v1.y; + v1.z = -v1.z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ScaleV(TVector3& v1, const TVector3& v2) { - v1.x *= v2.x; - v1.y *= v2.y; - v1.z *= v2.z; + v1.x *= v2.x; + v1.y *= v2.y; + v1.z *= v2.z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectV(TVector3& v1, const TVector3& v2) { - float x = (v1 * v2) / (v2 * v2); - v1 = x * v2; + float x = (v1 * v2) / (v2 * v2); + v1 = x * v2; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::RejectV(TVector3& v1, const TVector3& v2) { - float x = (v1 * v2) / (v2 * v2); - v1 -= x * v2; + float x = (v1 * v2) / (v2 * v2); + v1 -= x * v2; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlaneV(TVector3& v1, const TVector3& normal) { - return RejectV(v1, normal); + return RejectV(v1, normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlaneV(TVector3& v1, const TPlane& plane) { - return RejectV(v1, plane.normal); + return RejectV(v1, plane.normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Set(TVector3& v1, const TVector3& v2) { - v1 = v2; + v1 = v2; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Set(TVector3& v1, T x, T y, T z) { - v1.x = x; - v1.y = y; - v1.z = z; + v1.x = x; + v1.y = y; + v1.z = z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ClampMagnitudeV(TVector3& v1, T min, T max) { - T magnitude = Magnitude(v1); + T magnitude = Magnitude(v1); - v1 = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); + v1 = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); - Clamp(magnitude, min, max); + Clamp(magnitude, min, max); - v1 *= magnitude; + v1 *= magnitude; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::CompInverseV(TVector3& v1) { - v1.x = 1.0f / v1.x; - v1.y = 1.0f / v1.y; - v1.z = 1.0f / v1.z; + v1.x = 1.0f / v1.x; + v1.y = 1.0f / v1.y; + v1.z = 1.0f / v1.z; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlaneV(TVector3& v1, const TPlane& plane) { - return ReflectV(v1, plane.normal); + return ReflectV(v1, plane.normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlaneV(TVector3& v1, const TVector3& normal) { - return ReflectV(v1, normal); + return ReflectV(v1, normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::RotateAroundAxisV(TVector3& v1, const TVector3& axisNormal, T angle) { - T sinAngle = sin(angle); - T cosAngle = cos(angle); + T sinAngle = sin(angle); + T cosAngle = cos(angle); - v1 = ((T)1.0 - cosAngle) * DotP(axisNormal, v1) * axisNormal + cosAngle * v1 + sinAngle * CrossP(axisNormal, v1); + v1 = ((T)1.0 - cosAngle) * DotP(axisNormal, v1) * axisNormal + cosAngle * v1 + sinAngle * CrossP(axisNormal, v1); - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ScaleToMagnitudeV(TVector3& v1, T magnitude) { - NormalizeV(v1) *= magnitude; + NormalizeV(v1) *= magnitude; - return v1; + return v1; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::SignVectorV(TVector3& v1) { - v1.x = (v1.x > 0) ? 1 : 0; - v1.y = (v1.y > 0) ? 1 : 0; - v1.z = (v1.z > 0) ? 1 : 0; + v1.x = (v1.x > 0) ? 1 : 0; + v1.y = (v1.y > 0) ? 1 : 0; + v1.z = (v1.z > 0) ? 1 : 0; - return v1; + return v1; } template T Phanes::Core::Math::ScalarTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3) { - return CrossP(v1, v2) * v3; + return CrossP(v1, v2) * v3; } template T Phanes::Core::Math::CosineAngle(const TVector3& v1, const TVector3& v2) { - return (v1 * v2) / (Magnitude(v1) * Magnitude(v2)); + return (v1 * v2) / (Magnitude(v1) * Magnitude(v2)); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::VectorTripleV(TVector3& v1, const TVector3& v2, const TVector3& v3) { - CrossPV(CrossPV(v1, v2), v3); + CrossPV(CrossPV(v1, v2), v3); - return v1; + return v1; } template bool Phanes::Core::Math::IsPerpendicular(const TVector3& v1, const TVector3& v2, T threshold) { - return (abs(DotP(v1, v2)) < threshold); + return (abs(DotP(v1, v2)) < threshold); } template bool Phanes::Core::Math::IsParallel(const TVector3& v1, const TVector3& v2, T threshold) { - return (abs(DotP(v1, v2)) > threshold); + return (abs(DotP(v1, v2)) > threshold); } template bool Phanes::Core::Math::IsCoincident(const TVector3& v1, const TVector3& v2, T threshold) { - return (DotP(v1, v2) > threshold); + return (DotP(v1, v2) > threshold); } template bool Phanes::Core::Math::IsNormalized(const TVector3& v1, T threshold) { - return (SqrMagnitude(v1) < threshold); + return (SqrMagnitude(v1) < threshold); } template bool Phanes::Core::Math::IsCoplanar(const TVector3& v1, const TVector3& v2, const TVector3& v3, T threshold) { - return (ScalarTriple(v1, v2, v3) < threshold); + return (ScalarTriple(v1, v2, v3) < threshold); } @@ -583,87 +583,87 @@ bool Phanes::Core::Math::IsCoplanar(const TVector3& v1, const TVector3& v2 template Phanes::Core::Math::TVector3 Phanes::Core::Math::Normalize(const TVector3& v1) { - float vecNorm = Magnitude(v1); - return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm; + float vecNorm = Magnitude(v1); + return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::UnsafeNormalize(const TVector3& v1) { - return v1 / Magnitude(v1); + return v1 / Magnitude(v1); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Reflect(const TVector3& v1, const TVector3& normal) { - return v1 - (2 * (v1 * normal) * normal); + return v1 - (2 * (v1 * normal) * normal); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::PerspectiveDivide(const TVector3& v1) { - float _z = (T)1.0 / v1.z; - return TVector3(v1.x * _z, v1.y * _z, (T)0.0); + float _z = (T)1.0 / v1.z; + return TVector3(v1.x * _z, v1.y * _z, (T)0.0); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::CrossP(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.y * v2.z) - (v1.z * v2.y), - (v1.z * v2.x) - (v1.x * v2.z), - (v1.x * v2.y) - (v1.y * v2.x)); + return TVector3((v1.y * v2.z) - (v1.z * v2.y), + (v1.z * v2.x) - (v1.x * v2.z), + (v1.x * v2.y) - (v1.y * v2.x)); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Lerp(const TVector3& start, const TVector3& dest, T t) { - t = Clamp(t, (T)0.0, (T), 1.0); - return (1 - t) * start + t * dest; + t = Clamp(t, (T)0.0, (T), 1.0); + return (1 - t) * start + t * dest; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::LerpUnclamped(const TVector3& start, const TVector3& dest, T t) { - return (1 - t) * start + t * dest; + return (1 - t) * start + t * dest; } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Max(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.x > v2.x) ? v1.x : v2.x, - (v1.y > v2.y) ? v1.y : v2.y, - (v1.z > v2.z) ? v1.z : v2.z); + return TVector3((v1.x > v2.x) ? v1.x : v2.x, + (v1.y > v2.y) ? v1.y : v2.y, + (v1.z > v2.z) ? v1.z : v2.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Min(const TVector3& v1, const TVector3& v2) { - return TVector3((v1.x < v2.x) ? v1.x : v2.x, - (v1.y < v2.y) ? v1.y : v2.y, - (v1.z < v2.z) ? v1.z : v2.z); + return TVector3((v1.x < v2.x) ? v1.x : v2.x, + (v1.y < v2.y) ? v1.y : v2.y, + (v1.z < v2.z) ? v1.z : v2.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Negate(const TVector3& v1) { - return TVector3(-v1.x, -v1.y, -v1.z); + return TVector3(-v1.x, -v1.y, -v1.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::Scale(const TVector3& v1, const TVector3& v2) { - return TVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); + return TVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); } template Phanes::Core::Math::TVector3 Phanes::Core::Math::ClampMagnitude(const TVector3& v1, T min, T max) { - T magnitude = Magnitude(v1); + T magnitude = Magnitude(v1); - const TVector3 unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); + const TVector3 unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); - Clamp(magnitude, min, max); + Clamp(magnitude, min, max); - return unitVec * magnitude; + return unitVec * magnitude; } diff --git a/Engine/src/Runtime/Core/private/StartingPoint/StartingPoint.cpp b/Engine/src/Runtime/Core/private/StartingPoint/StartingPoint.cpp index 9170a40..7c6c5e5 100644 --- a/Engine/src/Runtime/Core/private/StartingPoint/StartingPoint.cpp +++ b/Engine/src/Runtime/Core/private/StartingPoint/StartingPoint.cpp @@ -13,5 +13,5 @@ Phanes::Core::Application::PhanesGame::~PhanesGame() void Phanes::Core::Application::PhanesGame::Run() { - while (true); + while (true); } diff --git a/Engine/src/Runtime/Core/public/Math/IntPoint.h b/Engine/src/Runtime/Core/public/Math/IntPoint.h index 7284c52..24369c6 100644 --- a/Engine/src/Runtime/Core/public/Math/IntPoint.h +++ b/Engine/src/Runtime/Core/public/Math/IntPoint.h @@ -24,131 +24,131 @@ namespace Phanes::Core::Math { - /** - * A 2D Point with components x and y with integer precision. - */ + /** + * A 2D Point with components x and y with integer precision. + */ - template - struct TIntPoint2 : public TIntVector2 { + template + struct TIntPoint2 : public TIntVector2 { - using TIntVector2::TIntVector2; + using TIntVector2::TIntVector2; - /** - * Creates IntPoint2 from IntPoint3's xy - * - * @param a IntPoint3 one - */ + /** + * Creates IntPoint2 from IntPoint3's xy + * + * @param a IntPoint3 one + */ - TIntPoint2(const TIntPoint3& a) - { - this->x = a.x; - this->y = a.y; - } + TIntPoint2(const TIntPoint3& a) + { + this->x = a.x; + this->y = a.y; + } - /** - * Creates IntPoint2 from IntPoint4's xy - * - * @param a IntPoint4 one - */ + /** + * Creates IntPoint2 from IntPoint4's xy + * + * @param a IntPoint4 one + */ - //TIntPoint2(const TIntPoint4& a) - //{ - // this->x = a.x; - // this->y = a.y; + //TIntPoint2(const TIntPoint4& a) + //{ + // this->x = a.x; + // this->y = a.y; - //} - }; + //} + }; - template - Rt Distance(const TIntPoint2& p1, const TIntPoint2& p2); + template + Rt Distance(const TIntPoint2& p1, const TIntPoint2& p2); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /** - * A 3D Point with components x and y with integer precision. - */ + /** + * A 3D Point with components x and y with integer precision. + */ - template - struct TIntPoint3 : public TIntVector3 { + template + struct TIntPoint3 : public TIntVector3 { - using TIntVector3::TIntVector3; + using TIntVector3::TIntVector3; - /** - * Creates IntPoint3 from IntPoint2's xy and zero - * - * @param a IntPoint2 one - */ + /** + * Creates IntPoint3 from IntPoint2's xy and zero + * + * @param a IntPoint2 one + */ - TIntPoint3(const TIntPoint2& a) - { - this->x = a.x; - this->y = a.y; - this->z = 0; - } + TIntPoint3(const TIntPoint2& a) + { + this->x = a.x; + this->y = a.y; + this->z = 0; + } - /** - * Creates IntPoint3 from IntPoint4's xyz - * - * @param a IntPoint4 one - */ + /** + * Creates IntPoint3 from IntPoint4's xyz + * + * @param a IntPoint4 one + */ - //TIntPoint3(const TIntPoint4& a) - //{ - // this->components[0] = a.components[0]; - // this->components[1] = a.components[1]; - // this->components[2] = a.components[2]; - //} - }; + //TIntPoint3(const TIntPoint4& a) + //{ + // this->components[0] = a.components[0]; + // this->components[1] = a.components[1]; + // this->components[2] = a.components[2]; + //} + }; - template - Rt Distance(const TIntPoint3& p1, const TIntPoint3& p2); + template + Rt Distance(const TIntPoint3& p1, const TIntPoint3& p2); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /** - * A 4D Point with components x and y with integer precision. - */ + /** + * A 4D Point with components x and y with integer precision. + */ - - //template - //struct TIntPoint4 : public TIntVector4 { - // static_assert(std::is_integral_v(T), "T must be an integer type."); + + //template + //struct TIntPoint4 : public TIntVector4 { + // static_assert(std::is_integral_v(T), "T must be an integer type."); - // using IntVector4::IntVector4; + // using IntVector4::IntVector4; - // /** - // * 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; - // } + // 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; + // } - // /** - // * Creates IntPoint4 from IntPoint3's xyz and zero - // * - // * @param a IntPoint3 one - // */ + // /** + // * 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; - // } - //}; + // 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; + // } + //}; } // phanes::core::math::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/IntVector2.h b/Engine/src/Runtime/Core/public/Math/IntVector2.h index e7ab999..3035264 100644 --- a/Engine/src/Runtime/Core/public/Math/IntVector2.h +++ b/Engine/src/Runtime/Core/public/Math/IntVector2.h @@ -30,841 +30,841 @@ namespace Phanes::Core::Math { - /** - * A 2D Vector with components x and y with integer precision. - */ + /** + * A 2D Vector with components x and y with integer precision. + */ - template - struct TIntVector2 { + template + struct TIntVector2 { - static_assert(std::is_integral_v, "T must be an integer type."); + static_assert(std::is_integral_v, "T must be an integer type."); - public: + public: - // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. + // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. - union - { + union + { - struct - { - /** X component of Vector - * - * @ref [FIELD]components - * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - T x; + struct + { + /** X component of Vector + * + * @ref [FIELD]components + * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + T x; - /** Y component of Vector - * - * @ref [FIELD]components - * - * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - T y; - }; + /** Y component of Vector + * + * @ref [FIELD]components + * + * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + T y; + }; - /** Components array holding the data - * - * @ref [FIELD]x - * @ref [FIELD]y - * - * @note Components are split into x and y. Access and manipulation is possible by these variables. - */ + /** Components array holding the data + * + * @ref [FIELD]x + * @ref [FIELD]y + * + * @note Components are split into x and y. Access and manipulation is possible by these variables. + */ - T comp[2]; + T comp[2]; - }; - + }; + - - public: + + public: - /** - * Default constructor without initialization - */ + /** + * Default constructor without initialization + */ - TIntVector2() = default; + TIntVector2() = default; - /** - * Copy constructor - */ - - TIntVector2(const TIntVector2& v); + /** + * Copy constructor + */ + + TIntVector2(const TIntVector2& v); - /** - * Move constructor - */ + /** + * Move constructor + */ - TIntVector2(TIntVector2&& v); - - /** - * Convert other type of vector - */ - - template - explicit TIntVector2(const TIntVector2& v) : x((T)v.x), y((T)v.y) {}; - - template - explicit TIntVector2(const TVector2& v) : x((T)v.x), y((T)v.y) {}; - - /** - * Construct Vector from xy components. - * - * @param x X component - * @param y Y component - */ - - TIntVector2(const T x, const T y); - - /** - * Construct Vector from two component array. - * - * @param comp Array of components - */ - - TIntVector2(const T* comp); - - /** - * Construct Vector from 3D integer Vector's xy. - * - * @param v 3D IntVector to copy from - */ - - TIntVector2(const TIntVector3& v); - - /** - * Construct Vector from 4D integer Vector's xy. - * - * @param v 4D IntVector to copy from - */ - - //TIntVector2(const TIntVector4& v); - - /** - * Construct Vector from 2D Point's xy. - * - * @param v 2D Point to copy from - */ - - //TIntVector2(const TIntPoint2& v); - - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ - - TIntVector2(const TIntPoint2& start, const TIntPoint2& end); - }; - - // ======================== // - // IntVector2 operators // - // ======================== // - - - /** - * Addition operation on same TIntVector2 (this) by a floating point value. - * - * @param(v1) Vector to add to - * @param(s) Floating point to add - */ - - template - TIntVector2 operator+= (TIntVector2& v1, T s); - - /** - * Addition operation on same TIntVector2 (this) by a another TIntVector2. - * - * @param(v1) Vector to add to - * @param(v2) Vector to add - */ - - template - TIntVector2 operator+= (TIntVector2& v1, const TIntVector2& v2); - - /** - * Substraction operation on same TIntVector2 (this) by a floating point. - * - * @param(v1) Vector to substract from - * @param(v2) Floating point to substract - */ - - template - TIntVector2 operator-= (TIntVector2& v1, T s); - - /** - * Substraction operation on same TIntVector2 (this) by a another TIntVector2. - * - * @param(v1) Vector to substract from - * @param(v2) Vector to substract - */ - - template - TIntVector2 operator-= (TIntVector2& v1, const TIntVector2& v2); - - /** - * Multiplication of TIntVector2 (this) with a floating point. - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - */ - - template - TIntVector2 operator*= (TIntVector2& v1, T s); - - /** - * Devision of Vector (this) by floating point. - * - * @param(v1) Vector to divide with - * @param(s Floating point to divide with - */ - - template - TIntVector2 operator/= (TIntVector2& v1, T s) = delete; - - /** - * Scale of Vector by floating point. (> Creates a new TIntVector2) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - * - * @return Result Vector - */ - - template - TIntVector2 operator* (const TIntVector2& v1, T s); - - /** - * Division of Vector by floating point. (> Creates another TIntVector2) - * - * @see [FUNC]DivideFloat - * - * @param(v1) Vector to multiply with - * @param(s Floating point to divide with - * - * @return Result Vector - * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. - */ - - template - TIntVector2 operator/ (const TIntVector2& v1, T s) = delete; - - /** - * Scale of Vector by floating point. (> Creates a new TIntVector2) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - * - * @return Result Vector - */ - - template - inline TIntVector2 operator* (T s, const TIntVector2& v1); - - /** - * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.) - * - * @see [FUNC]DivideFloat - * - * @param(v1) Vector to multiply with - * @param(s Floating point to divide with - * - * @return Result Vector - * - * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. - */ - - template - inline TIntVector2 operator/ (T s, const TIntVector2& v1) = delete; - - /** - * Dot product between two Vectors. - * - * @see [FUNC]DotP - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @result Dot product - */ - - template - Rt operator* (const TIntVector2& v1, const TIntVector2& v2); - - /** - * Componentwise addition of Vector with floating point. - * - * @param(v1) Vector to add to - * @param(s Floating point to add - * - * @return Result Vector - */ - - template - TIntVector2 operator+ (const TIntVector2& v1, T s); - - /** - * Componentwise addition of Vector with floating point. - * - * @param(v1) Vector to add to - * @param(s Floating point to add - * - * @return Result Vector - */ - - template - TIntVector2 operator+ (const TIntVector2& v1, const TIntVector2& v2); - - /** - * Componentwise substraction of Vector with floating point. - * - * @param(v1) Vector to substract from - * @param(s Floating point to substract - * - * @return Result Vector - */ - - template - TIntVector2 operator- (const TIntVector2& v1, T s); - - /** - * Componentwise substraction of Vector with Vector. - * - * @param(v1) Vector to substract from - * @param(s Floating point to substract - * - * @return Result Vector - */ - - template - TIntVector2 operator- (const TIntVector2& v1, const TIntVector2& v2); - - /** - * Negate Vector. - * - * @param(v1) Vector to negate - */ - - template - void operator- (TIntVector2& v1); - - /** - * Compare Vector for equality. - * - * @see [FUNC]Equals - * - * @param(v1) Vector to negate - * - * @return true if equal, false if inequal - */ - - template - bool operator== (const TIntVector2& v1, const TIntVector2& v2); - - - /** - * Compare Vector for inequality. - * - * @see [FUNC]Equals - * - * @param(v1) Vector to negate - * - * @return true if inequal, false if equal - */ - - template - bool operator!= (const TIntVector2& v1, const TIntVector2& v2); - - // ============================================== // - // IntVector2 static function implementation // - // ============================================== // - - /** - * Magnitude of Vector - * - * @param(v1) Vector - * - * @return Size of Vector - */ - - template - Rt Magnitude(const TIntVector2& v1); - - /** - * @see [FUNC]Magnitude - */ - template - FORCEINLINE Rt Length(const TIntVector2& v1) { return Magnitude(v1); }; - - /** - * Square of magnitude of Vector - * - * @param(v1) Vector - * - * @return Magnitude without calculating square root - */ - - template - T SqrMagnitude(const TIntVector2& v1); - - /** - * @see [FUNC]SqrMagnitude - */ - template - FORCEINLINE T SqrLength(const TIntVector2& v1) { return SqrMagnitude(v1); }; - - - /** - * Divide vector and truncate result. - * - * @param(v1) Vector to divide - * @param(s) Number to divide with - * - * @note Rt is the type of the reciprocal of s. - */ - - template - TIntVector2 DivideTruncV(TIntVector2& v1, T s); - - /** - * Angle between to Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - Rt Angle(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Cosine of angle between to Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - Rt CosineAngle(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - */ - - template - TIntVector2 SignVectorV(TIntVector2& v1); - - /** - * Dot product of two Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - T DotP(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Creates Vector, with component wise largest values. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TIntVector2 MaxV(TIntVector2& v1, const TIntVector2& v2); - - /** - * Creates Vector, with component wise smallest values. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TIntVector2 MinV(TIntVector2& v1, const TIntVector2& v2); - - /** - * Gets perpendicular Vector to v1. - * - * @param(v1) Vector one - * - * @note Stores new Vector to v1 - */ - - template - TIntVector2 GetPerpendicularV(TIntVector2& v1); - - /** - * Gets perpendicular Vector to v1. - * - * @reg [FUNC]PerpendicularV - * - * @param(v1) Vector one - * - * @note Stores new Vector to v1 - */ - - template - TIntVector2 GetReversePerpendicularV(TIntVector2& v1); - - /** - * Component wise multiplication of Vector - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TIntVector2 ScaleV(TIntVector2& v1, const TIntVector2& v2); - - /** - * Copies one Vector two another - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TIntVector2 Set(TIntVector2& v1, const TIntVector2& v2); - - /** - * Sets components of a vector. - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TIntVector2 Set(TIntVector2& v1, T x, T y); - - - /** - * Negates Vector - * - * @param(v1) Vector one - */ - - template - TIntVector2 NegateV(TIntVector2& v1); - - /** - * Tests if vector is a unity vector. - * - * @param(v1) Vector one - * - * @return true if unit vector, false if not - */ - - template - inline bool IsNormalized(const TIntVector2& v1); - - /** - * Tests if 2 vectors are perpendicular to each other. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return true if perpendicular, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsPerpendicular(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Tests if 2 vectors are parallel to each other. (Angle is close to zero.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return true if parallel, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsParallel(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Tests if 2 vectors are coincident. (Are parallel and point in the same direction.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return true if coincident, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsCoincident(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Gets outer product of to vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Resulting matrix - */ - - //template - //Matrix2 OuterProduct(const TIntVector2& v1, const TIntVector2& v2); - - - // ============================================================= // - // IntVector2 static function implementation with return values // - // ============================================================= // - - - /** - * Reflects a vector on a normal - * - * @param(v1) Vector one - * @param(normal) Normal of surface - * - * @return Reflected vector - */ - - template - TVector2 Reflect(const TIntVector2& v1, const TVector2& normal); - - /** - * Scales a vector component wise - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Reflected vector - */ - - template - TIntVector2 Scale(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Componentwise inverse of a vector - * - * @param(v1) Vector one - * - * @return Componentwise inverted, floating point vector - */ - - template - TVector2 CompInverse(const TIntVector2& v1); - - - /** - * Negates Vector - * - * @param(v1) Vector one - * - * @return Componentwise inverted vector - */ - - template - TIntVector2 Negate(const TIntVector2& v1); - - /** - * Gets the perpendicular vector of v1 - * - * @param(v1) Vector one - * - * @return Perpendicular vector - */ - - template - TIntVector2 GetPerpendicular(const TIntVector2& v1); - - /** - * Gets reverse of the perpendicular vector of v1 - * - * @param(v1) Vector one - * - * @return Reversed perpendicular vector - */ - - template - TIntVector2 GetReversePerpendicular(const TIntVector2& v1); - - /** - * Creates a new Vector by the component wise minimals of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Minimal vector - */ - - template - TIntVector2 Min(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Creates a new Vector by the component wise maxima of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Maximal vector - */ - - template - TIntVector2 Max(const TIntVector2& v1, const TIntVector2& v2); - - /** - * Creates a normalized instance of the vector - * - * @param(v1) Vector to normalize - * - * @return Unit vector - * @note Returns floating point vector. - */ - - template - TVector2 Normalize(const TIntVector2& v1); - - /** - * Creates a normalized instance of the vector - * - * @param(v1) Vector to normalize - * - * @return Unit vector - * @note Does not test for zero vector - * @note Returns floating point vector. - */ - - template - TVector2 UnsafeNormalize(const TIntVector2& v1); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - * - * @return Vector with signs as components - */ - - template - TIntVector2 SignVector(const TIntVector2& v1); - - /** - * Binds a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - * - * @return Bound, floating point vector - */ - - template - TVector2 BindToSquare(const TIntVector2& v1, T radius); - - /** - * Clamps a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - * - * @return Clamped, floating point vector. If the length of the vector fits the square, then the vector is returned. - */ - - template - TVector2 ClampToSquare(const TIntVector2& v1, T radius); - - /** - * Interpolates between to vectors. - * - * @param(startVec) Start vector (t = 0) - * @param(destVec) Destination vector (t = 1) - * @param(t) Interpolation value - * - * @return Interpolated vector - * - * @note Interpolation is clamped between 0 - 1. - */ - - template - TVector2 Lerp(const TIntVector2& startVec, const TIntVector2& destVec, Rt t); - - /** - * Interpolates between to vectors. - * - * @param(startVec) Start vector (t = 0) - * @param(destVec) Destination vector (t = 1) - * @param(t) Interpolation value - * - * @return Interpolated vector - * - * @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f - */ - - template - TVector2 LerpUnclamped(const TIntVector2& startVec, const TIntVector2& destVec, Rt t); - - /** - * Anti-clockwise vector rotation. - * - * @param(v1) Vector to rotate - * @param(angle) Angle to rotate - * - * @return Rotated vector - * - * @note Angle is not clamped - */ - - template - TVector2 Rotate(const TIntVector2& v1, Rt angle); - - /** - * Clockwise vector rotation. - * - * @param(v1) Vector to rotate - * - * @return Rotated vector - * - * @note Angle is not clamped - */ - - template - FORCEINLINE TVector2 ClockwiseRotate(const TIntVector2& v1, Rt angle); - - /** - * Component wise division of Vector - * - * @param(v1) Vector one - * @param(s) Vector two - * - * @note Truncates result instead of rounding - * @note Rt is the type of the reciprocal of s. - */ - - template - TIntVector2 DivideTrunc(const TIntVector2& v1, T s); - - - /** - * Component wise division of Vector - * - * @param(v1) Vector one - * @param(s) Vector two - * - * @return Floating point vector - */ - - template - TVector2 DivideFloat(const TIntVector2& v1, T s); + TIntVector2(TIntVector2&& v); + + /** + * Convert other type of vector + */ + + template + explicit TIntVector2(const TIntVector2& v) : x((T)v.x), y((T)v.y) {}; + + template + explicit TIntVector2(const TVector2& v) : x((T)v.x), y((T)v.y) {}; + + /** + * Construct Vector from xy components. + * + * @param x X component + * @param y Y component + */ + + TIntVector2(const T x, const T y); + + /** + * Construct Vector from two component array. + * + * @param comp Array of components + */ + + TIntVector2(const T* comp); + + /** + * Construct Vector from 3D integer Vector's xy. + * + * @param v 3D IntVector to copy from + */ + + TIntVector2(const TIntVector3& v); + + /** + * Construct Vector from 4D integer Vector's xy. + * + * @param v 4D IntVector to copy from + */ + + //TIntVector2(const TIntVector4& v); + + /** + * Construct Vector from 2D Point's xy. + * + * @param v 2D Point to copy from + */ + + //TIntVector2(const TIntPoint2& v); + + + /** + * Constructs a vector pointing from start to end. + * + * @param(start) Startingpoint + * @param(end) Endpoint + */ + + TIntVector2(const TIntPoint2& start, const TIntPoint2& end); + }; + + // ======================== // + // IntVector2 operators // + // ======================== // + + + /** + * Addition operation on same TIntVector2 (this) by a floating point value. + * + * @param(v1) Vector to add to + * @param(s) Floating point to add + */ + + template + TIntVector2 operator+= (TIntVector2& v1, T s); + + /** + * Addition operation on same TIntVector2 (this) by a another TIntVector2. + * + * @param(v1) Vector to add to + * @param(v2) Vector to add + */ + + template + TIntVector2 operator+= (TIntVector2& v1, const TIntVector2& v2); + + /** + * Substraction operation on same TIntVector2 (this) by a floating point. + * + * @param(v1) Vector to substract from + * @param(v2) Floating point to substract + */ + + template + TIntVector2 operator-= (TIntVector2& v1, T s); + + /** + * Substraction operation on same TIntVector2 (this) by a another TIntVector2. + * + * @param(v1) Vector to substract from + * @param(v2) Vector to substract + */ + + template + TIntVector2 operator-= (TIntVector2& v1, const TIntVector2& v2); + + /** + * Multiplication of TIntVector2 (this) with a floating point. + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + */ + + template + TIntVector2 operator*= (TIntVector2& v1, T s); + + /** + * Devision of Vector (this) by floating point. + * + * @param(v1) Vector to divide with + * @param(s Floating point to divide with + */ + + template + TIntVector2 operator/= (TIntVector2& v1, T s) = delete; + + /** + * Scale of Vector by floating point. (> Creates a new TIntVector2) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + * + * @return Result Vector + */ + + template + TIntVector2 operator* (const TIntVector2& v1, T s); + + /** + * Division of Vector by floating point. (> Creates another TIntVector2) + * + * @see [FUNC]DivideFloat + * + * @param(v1) Vector to multiply with + * @param(s Floating point to divide with + * + * @return Result Vector + * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. + */ + + template + TIntVector2 operator/ (const TIntVector2& v1, T s) = delete; + + /** + * Scale of Vector by floating point. (> Creates a new TIntVector2) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + * + * @return Result Vector + */ + + template + inline TIntVector2 operator* (T s, const TIntVector2& v1); + + /** + * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.) + * + * @see [FUNC]DivideFloat + * + * @param(v1) Vector to multiply with + * @param(s Floating point to divide with + * + * @return Result Vector + * + * @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading. + */ + + template + inline TIntVector2 operator/ (T s, const TIntVector2& v1) = delete; + + /** + * Dot product between two Vectors. + * + * @see [FUNC]DotP + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @result Dot product + */ + + template + Rt operator* (const TIntVector2& v1, const TIntVector2& v2); + + /** + * Componentwise addition of Vector with floating point. + * + * @param(v1) Vector to add to + * @param(s Floating point to add + * + * @return Result Vector + */ + + template + TIntVector2 operator+ (const TIntVector2& v1, T s); + + /** + * Componentwise addition of Vector with floating point. + * + * @param(v1) Vector to add to + * @param(s Floating point to add + * + * @return Result Vector + */ + + template + TIntVector2 operator+ (const TIntVector2& v1, const TIntVector2& v2); + + /** + * Componentwise substraction of Vector with floating point. + * + * @param(v1) Vector to substract from + * @param(s Floating point to substract + * + * @return Result Vector + */ + + template + TIntVector2 operator- (const TIntVector2& v1, T s); + + /** + * Componentwise substraction of Vector with Vector. + * + * @param(v1) Vector to substract from + * @param(s Floating point to substract + * + * @return Result Vector + */ + + template + TIntVector2 operator- (const TIntVector2& v1, const TIntVector2& v2); + + /** + * Negate Vector. + * + * @param(v1) Vector to negate + */ + + template + void operator- (TIntVector2& v1); + + /** + * Compare Vector for equality. + * + * @see [FUNC]Equals + * + * @param(v1) Vector to negate + * + * @return true if equal, false if inequal + */ + + template + bool operator== (const TIntVector2& v1, const TIntVector2& v2); + + + /** + * Compare Vector for inequality. + * + * @see [FUNC]Equals + * + * @param(v1) Vector to negate + * + * @return true if inequal, false if equal + */ + + template + bool operator!= (const TIntVector2& v1, const TIntVector2& v2); + + // ============================================== // + // IntVector2 static function implementation // + // ============================================== // + + /** + * Magnitude of Vector + * + * @param(v1) Vector + * + * @return Size of Vector + */ + + template + Rt Magnitude(const TIntVector2& v1); + + /** + * @see [FUNC]Magnitude + */ + template + FORCEINLINE Rt Length(const TIntVector2& v1) { return Magnitude(v1); }; + + /** + * Square of magnitude of Vector + * + * @param(v1) Vector + * + * @return Magnitude without calculating square root + */ + + template + T SqrMagnitude(const TIntVector2& v1); + + /** + * @see [FUNC]SqrMagnitude + */ + template + FORCEINLINE T SqrLength(const TIntVector2& v1) { return SqrMagnitude(v1); }; + + + /** + * Divide vector and truncate result. + * + * @param(v1) Vector to divide + * @param(s) Number to divide with + * + * @note Rt is the type of the reciprocal of s. + */ + + template + TIntVector2 DivideTruncV(TIntVector2& v1, T s); + + /** + * Angle between to Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + Rt Angle(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Cosine of angle between to Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + Rt CosineAngle(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + */ + + template + TIntVector2 SignVectorV(TIntVector2& v1); + + /** + * Dot product of two Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + T DotP(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Creates Vector, with component wise largest values. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TIntVector2 MaxV(TIntVector2& v1, const TIntVector2& v2); + + /** + * Creates Vector, with component wise smallest values. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TIntVector2 MinV(TIntVector2& v1, const TIntVector2& v2); + + /** + * Gets perpendicular Vector to v1. + * + * @param(v1) Vector one + * + * @note Stores new Vector to v1 + */ + + template + TIntVector2 GetPerpendicularV(TIntVector2& v1); + + /** + * Gets perpendicular Vector to v1. + * + * @reg [FUNC]PerpendicularV + * + * @param(v1) Vector one + * + * @note Stores new Vector to v1 + */ + + template + TIntVector2 GetReversePerpendicularV(TIntVector2& v1); + + /** + * Component wise multiplication of Vector + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TIntVector2 ScaleV(TIntVector2& v1, const TIntVector2& v2); + + /** + * Copies one Vector two another + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TIntVector2 Set(TIntVector2& v1, const TIntVector2& v2); + + /** + * Sets components of a vector. + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TIntVector2 Set(TIntVector2& v1, T x, T y); + + + /** + * Negates Vector + * + * @param(v1) Vector one + */ + + template + TIntVector2 NegateV(TIntVector2& v1); + + /** + * Tests if vector is a unity vector. + * + * @param(v1) Vector one + * + * @return true if unit vector, false if not + */ + + template + inline bool IsNormalized(const TIntVector2& v1); + + /** + * Tests if 2 vectors are perpendicular to each other. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return true if perpendicular, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsPerpendicular(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Tests if 2 vectors are parallel to each other. (Angle is close to zero.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return true if parallel, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsParallel(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Tests if 2 vectors are coincident. (Are parallel and point in the same direction.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return true if coincident, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsCoincident(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Gets outer product of to vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Resulting matrix + */ + + //template + //Matrix2 OuterProduct(const TIntVector2& v1, const TIntVector2& v2); + + + // ============================================================= // + // IntVector2 static function implementation with return values // + // ============================================================= // + + + /** + * Reflects a vector on a normal + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * + * @return Reflected vector + */ + + template + TVector2 Reflect(const TIntVector2& v1, const TVector2& normal); + + /** + * Scales a vector component wise + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Reflected vector + */ + + template + TIntVector2 Scale(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Componentwise inverse of a vector + * + * @param(v1) Vector one + * + * @return Componentwise inverted, floating point vector + */ + + template + TVector2 CompInverse(const TIntVector2& v1); + + + /** + * Negates Vector + * + * @param(v1) Vector one + * + * @return Componentwise inverted vector + */ + + template + TIntVector2 Negate(const TIntVector2& v1); + + /** + * Gets the perpendicular vector of v1 + * + * @param(v1) Vector one + * + * @return Perpendicular vector + */ + + template + TIntVector2 GetPerpendicular(const TIntVector2& v1); + + /** + * Gets reverse of the perpendicular vector of v1 + * + * @param(v1) Vector one + * + * @return Reversed perpendicular vector + */ + + template + TIntVector2 GetReversePerpendicular(const TIntVector2& v1); + + /** + * Creates a new Vector by the component wise minimals of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Minimal vector + */ + + template + TIntVector2 Min(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Creates a new Vector by the component wise maxima of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Maximal vector + */ + + template + TIntVector2 Max(const TIntVector2& v1, const TIntVector2& v2); + + /** + * Creates a normalized instance of the vector + * + * @param(v1) Vector to normalize + * + * @return Unit vector + * @note Returns floating point vector. + */ + + template + TVector2 Normalize(const TIntVector2& v1); + + /** + * Creates a normalized instance of the vector + * + * @param(v1) Vector to normalize + * + * @return Unit vector + * @note Does not test for zero vector + * @note Returns floating point vector. + */ + + template + TVector2 UnsafeNormalize(const TIntVector2& v1); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + * + * @return Vector with signs as components + */ + + template + TIntVector2 SignVector(const TIntVector2& v1); + + /** + * Binds a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + * + * @return Bound, floating point vector + */ + + template + TVector2 BindToSquare(const TIntVector2& v1, T radius); + + /** + * Clamps a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + * + * @return Clamped, floating point vector. If the length of the vector fits the square, then the vector is returned. + */ + + template + TVector2 ClampToSquare(const TIntVector2& v1, T radius); + + /** + * Interpolates between to vectors. + * + * @param(startVec) Start vector (t = 0) + * @param(destVec) Destination vector (t = 1) + * @param(t) Interpolation value + * + * @return Interpolated vector + * + * @note Interpolation is clamped between 0 - 1. + */ + + template + TVector2 Lerp(const TIntVector2& startVec, const TIntVector2& destVec, Rt t); + + /** + * Interpolates between to vectors. + * + * @param(startVec) Start vector (t = 0) + * @param(destVec) Destination vector (t = 1) + * @param(t) Interpolation value + * + * @return Interpolated vector + * + * @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f + */ + + template + TVector2 LerpUnclamped(const TIntVector2& startVec, const TIntVector2& destVec, Rt t); + + /** + * Anti-clockwise vector rotation. + * + * @param(v1) Vector to rotate + * @param(angle) Angle to rotate + * + * @return Rotated vector + * + * @note Angle is not clamped + */ + + template + TVector2 Rotate(const TIntVector2& v1, Rt angle); + + /** + * Clockwise vector rotation. + * + * @param(v1) Vector to rotate + * + * @return Rotated vector + * + * @note Angle is not clamped + */ + + template + FORCEINLINE TVector2 ClockwiseRotate(const TIntVector2& v1, Rt angle); + + /** + * Component wise division of Vector + * + * @param(v1) Vector one + * @param(s) Vector two + * + * @note Truncates result instead of rounding + * @note Rt is the type of the reciprocal of s. + */ + + template + TIntVector2 DivideTrunc(const TIntVector2& v1, T s); + + + /** + * Component wise division of Vector + * + * @param(v1) Vector one + * @param(s) Vector two + * + * @return Floating point vector + */ + + template + TVector2 DivideFloat(const TIntVector2& v1, T s); } // phanes::core::math::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/IntVector3.h b/Engine/src/Runtime/Core/public/Math/IntVector3.h index 4da946f..292f4a6 100644 --- a/Engine/src/Runtime/Core/public/Math/IntVector3.h +++ b/Engine/src/Runtime/Core/public/Math/IntVector3.h @@ -26,939 +26,939 @@ namespace Phanes::Core::Math { - /** - * A 3D Vector with components x, y and z with integer precision. - */ + /** + * A 3D Vector with components x, y and z with integer precision. + */ - template - struct TIntVector3 { + template + struct TIntVector3 { - public: + public: - // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. + // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. - union - { + union + { - struct - { - /** X component of Vector - * - * @ref [FIELD]components - * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - T x; + struct + { + /** X component of Vector + * + * @ref [FIELD]components + * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + T x; - /** Y component of Vector - * - * @ref [FIELD]components - * - * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - T y; + /** Y component of Vector + * + * @ref [FIELD]components + * + * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + T y; - /** Z component of Vector - * - * @ref [FIELD]components - * - * @note Z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - T z; - }; + /** Z component of Vector + * + * @ref [FIELD]components + * + * @note Z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + T z; + }; - /** Components array holding the data - * - * @ref [FIELD]x - * @ref [FIELD]y - * @ref [FIELD]z - * - * @note Components are split into x, y and z. Access and manipulation is possible by these variables. - */ + /** Components array holding the data + * + * @ref [FIELD]x + * @ref [FIELD]y + * @ref [FIELD]z + * + * @note Components are split into x, y and z. Access and manipulation is possible by these variables. + */ - T comp[3]; + T comp[3]; - }; + }; - public: + public: - /** - * Default constructor without initialization - */ + /** + * Default constructor without initialization + */ - TIntVector3() = default; + TIntVector3() = default; - /** - * Copy constructor - */ + /** + * Copy constructor + */ - TIntVector3(const TIntVector3& v); + TIntVector3(const TIntVector3& v); - /** - * Move constructor - */ + /** + * Move constructor + */ - TIntVector3(TIntVector3&& v); + TIntVector3(TIntVector3&& v); - /** - * Convert other type of vector - */ + /** + * Convert other type of vector + */ - template - explicit TIntVector3(const TIntVector3& v) : x((T)v.x), y((T)v.y) {}; + template + explicit TIntVector3(const TIntVector3& v) : x((T)v.x), y((T)v.y) {}; - template - explicit TIntVector3(const TVector3& v) : x((T)v.x), y((T)v.y) {}; + template + explicit TIntVector3(const TVector3& v) : x((T)v.x), y((T)v.y) {}; - /** - * Construct Vector from xy components. - * - * @param x X component - * @param y Y component - * @param z Z component - */ + /** + * Construct Vector from xy components. + * + * @param x X component + * @param y Y component + * @param z Z component + */ - TIntVector3(const T x, const T y, const T z); + TIntVector3(const T x, const T y, const T z); - /** - * Construct Vector from two component array. - * - * @param comp Array of components - */ - - TIntVector3(const T* comp); - - /** - * Construct Vector from 3D integer Vector's xy. - * - * @param v 3D IntVector to copy from - */ - - TIntVector3(const TIntVector2& v); - - /** - * Construct Vector from 4D integer Vector's xy. - * - * @param v 4D IntVector to copy from - */ - - //TIntVector2(const TIntVector4& v); - - /** - * Construct Vector from 2D Point's xy. - * - * @param v 2D Point to copy from - */ - - //TIntVector2(const TIntPoint2& v); - - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ - - TIntVector3(const TIntPoint3& start, const TIntPoint3& end); - - }; - - - // ======================== // - // IntVector3 operators // - // ======================== // - - - /** - * Coponentwise addition of floating point to 3D vector - * - * @param(v1) vector to add to - * @param(s) floating point to add - */ - - template - inline TIntVector3 operator+= (TIntVector3& v1, T s); - - /** - * Coponentwise addition of 3D vector to 3D vector - * - * @param(v1) vector to add to - * @param(v2) vector to add - */ - - template - inline TIntVector3 operator+= (TIntVector3& v1, const TIntVector3& v2); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(s) floating point to substract - */ - - template - inline TIntVector3 operator-= (TIntVector3& v1, T s); - - /** - * Coponentwise substraction of 3D vector to 3D vector - * - * @param(v1) vector to substract from - * @param(v2) vector to substract with - */ - - template - inline TIntVector3 operator-= (TIntVector3& v1, const TIntVector3& v2); - - /** - * Dot product between two 3D Vectors - * - * @param(v1) vector one - * @param(s) floating point - */ - - template - inline TIntVector3 operator*= (TIntVector3& v1, T s); - - /** - * Coponentwise multiplication of 3D Vectors with floating point - * - * @param(v1) vector one - * @param(s) floating point - * - * @return Resulting vector - */ - - template - TIntVector3 operator* (const TIntVector3& v1, T s); - - /** - * Coponentwise multiplication of 3D Vectors with floating point - * - * @param(s) floating point - * @param(v2) vector - * - * @return Resultion vector - */ - - template - inline TIntVector3 operator* (T s, const TIntVector3& v1); - - /** - * Dot product between two 3D Vectors - * - * @param(v1) vector one - * @param(v2) vector two - * - * @return Dot product of Vectors - */ - - template - T operator* (const TIntVector3& v1, const TIntVector3& v2); - - /** - * Coponentwise addition of floating point to 3D vector - * - * @param(v1) vector to add to - * @param(s) floating point to add - * - * @return Resulting vector - */ - - template - TIntVector3 operator+ (const TIntVector3& v1, T s); - - /** - * Coponentwise addition of 3D vector to 3D vector - * - * @param(v1) vector to add to - * @param(v2) vector to add - * - * @return Resulting vector - */ - - template - TIntVector3 operator+ (const TIntVector3& v1, const TIntVector3& v2); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(s) floating point to substract - * - * @return Resulting vector - */ - - template - TIntVector3 operator- (const TIntVector3& v1, T s); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(v2) vector to substract with - * - * @return Resulting vector - */ - - template - TIntVector3 operator- (const TIntVector3& v1, const TIntVector3& v2); - - /** - * Negates vector - * - * @param(v1) Vector to negate - */ - - template - TIntVector3 operator- (TIntVector3& v1); - - /** - * Tests two 3D vectors for equality. - * - * @ref [FUNC]Equals - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return True if equal, false if not. - * - * @note Uses [MACRO]P_FLT_INAC - */ - - template - inline bool operator== (const TIntVector3& v1, const TIntVector3& v2); - - /** - * Tests two 3D vectors for inequality. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return True if inequal, false if not. - */ - - template - inline bool operator!= (const TIntVector3& v1, const TIntVector3& v2); - - // ============================================== // - // IntVector3 static function implementation // - // ============================================== // - - /** - * Gets magnitude of vector - * - * @param(v1) Vector - * - * @return Magnitude of vector - */ - - template - inline Rt Magnitude(const TIntVector3& v1); - - /** - * @see [FUNC]Magnitude - */ - - template - FORCEINLINE T Length(const TIntVector3& v1) { return Magnitude(v1); }; - - /** - * Gets square magnitude of vector - * - * @param(v1) Vector - * - * @return Square magnitude of vector - */ - - template - inline T SqrMagnitude(const TIntVector3& v1); - - /** - * @see SqrMagnitude - */ - - template - FORCEINLINE T SqrLength(const TIntVector3& v1) { return SqrMagnitude(v1); }; - - /** - * Gets angle between two vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Angle between vectors - */ - - template - Rt Angle(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Dot product of two vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Dot product of vectors - */ - - template - T DotP(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - * - * @return Vector with signs a components. - */ - - template - TIntVector3 SignVector(const TIntVector3& v1); - - /** - * Tests two vectors for equality. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy. - * - * @return True if equal, false if not. - */ - - template - inline bool Equals(const TIntVector3& v1, const TIntVector3& v2, T threshold = P_FLT_INAC); - - /** - * Calculates the cross product between two vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TIntVector3 CrossPV(TIntVector3& v1, const TIntVector3& v2); - - /** - * Gets the componentwise max of both vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TIntVector3 MaxV(TIntVector3& v1, const TIntVector3& v2); - - /** - * Gets the componentwise min of both vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TIntVector3 MinV(TIntVector3& v1, const TIntVector3& v2); - - /** - * Gets reversed vector. - * - * @param(v1) Vector one - * - * @note result is stored in v1. - */ - - template - TIntVector3 NegateV(TIntVector3& v1); - - /** - * Performes componentwise multiplication of two vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TIntVector3 ScaleV(TIntVector3& v1, const TIntVector3& v2); - - /** - * Copies v1 vector - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TIntVector3 Set(TIntVector3& v1, const TIntVector3& v2); - - /** - * Sets vector. - * - * @param(v1) Vector to copy to - * @param(x) X component - * @param(y) Y component - * @param(z) Z component - */ - - template - TIntVector3 Set(TIntVector3& v1, T x, T y, T z); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - */ - - template - TIntVector3 SignVectorV(TIntVector3& v1); - - - /** - * Gets scalar triple product ((v1 x v2) * v3). (Volume of parallelepiped.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @return Vector triple product - */ - - template - T ScalarTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); - - /** - * Gets the cosine of the angle between to vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Cosine of angle between vectors. - * @note Simply omits acos of angle. - */ - - template - T CosineAngle(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Gets vector triple product ((v1 x v2) x v3). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @note result is stored in v1 - */ - - template - TIntVector3 VectorTripleV(TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); - - /** - * Tests whether two vectors are perpendicular. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy - * - * @return True if perpendicular, false if not. - */ - - template - inline bool IsPerpendicular(const TIntVector3& v1, const TIntVector3& v2, T threshold = P_FLT_INAC); - - /** - * Tests whether two vectors are parallel. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) - * - * @return True if parallel, false if not. - */ - - template - inline bool IsParallel(const TIntVector3& v1, const TIntVector3& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Tests whether two vectors are coincident (Parallel and point in same direction). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) - * - * @return True if coincident, false if not. - */ - - template - inline bool IsCoincident(const TIntVector3& v1, const TIntVector3& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Tests whether v1 vectors is v1 unit vector. - * - * @param(v1) Vector - * @param(threshold) Allowed T inaccuracy - * - * @return True if unit vector, false if not. - */ - - template - inline bool IsNormalized(const TIntVector3& v1, T threshold = P_FLT_INAC); - - /** - * Tests if three vectors are coplanar - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * @param(threshold) Allowed T inaccuracy - * - * @return True if coplanar, false if not. - */ - - template - inline bool IsCoplanar(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3, T threshold = P_FLT_INAC); - - - /** - * Gets outer product of to vectors. - * - * @param a Vector one - * @param b Vector two - * - * @return Resulting matrix - */ - - //template - //Matrix3 OuterProduct(const IntVector3& a, const IntVector3& b); - - - // ================================================================ // - // IntVector3 static function implementation with return values // - // ================================================================ // - - /** - * Normalized vector - * - * @param(v1) vector to normalize - * - * @return Normalized vector - */ - - template - TVector3 Normalize(const TIntVector3& v1); - - /** - * Normalizes vector - * - * @param(v1) Vector - * - * @note Does not test for zero vector - */ - - template - TVector3 UnsafeNormalize(const TIntVector3& v1); - - /** - * Reflects a vector on a surface - * - * @param(v1) Vector one - * @param(normal) Normal of surface - * - * @return Reflected vector - */ - - template - TVector3 Reflect(const TIntVector3& v1, const TVector3& normal); - - - /** - * Performes perspective divide on vector. - * - * @param(v1) vector to perspective divide - * - * @return Perspective divided vector - */ - - template - TVector3 PerspectiveDivide(const TIntVector3& v1); - - /** - * Gets cross product between two vectors. - * - * @param(v1) vector one - * @param(v2) vector two - * - * @return Cross product of v1 and v2 - */ - - template - TIntVector3 CrossP(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Linearly interpolates between two vectors. - * - * @param(start) Starting vector - * @param(dest) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Cross product of v1 and v2 - */ - - template - TVector3 Lerp(const TIntVector3& start, const TIntVector3& dest, Rt t); - - /** - * Linearly interpolates between two vectors. - * - * @param(v1) Starting vector - * @param(dest) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Cross product of v1 and v2 - * @note Does not clamp t between 0.0 and 1.0. - */ - - template - TVector3 LerpUnclamped(const TIntVector3& start, const TIntVector3& dest, Rt t); - - /** - * Creates a new Vector by the componentwise max of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector of componentwise max - */ - - template - TIntVector3 Max(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Creates a new Vector by the componentwise min of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector of componentwise min - */ - - template - TIntVector3 Min(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Gets reversed vector. - * - * @param(v1) Vector one - * - * @note result is stored in v1. - */ - - template - TIntVector3 Negate(const TIntVector3& v1); - - /** - * Multiplies vector componentwise. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector with componentwise products - */ - - template - TIntVector3 Scale(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Clamps vector to a range of magnitudes. - * - * @param(v1) Vector to clamp - * @param(min) Min magnitude - * @param(max) Max magnitude - * - * @return Clamped vector - */ - - template - TVector3 ClampMagnitude(const TIntVector3& v1, T min, T max); - - /** - * Binds vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @result Vector clamped in cube. - */ - - template - TVector3 BoundToCube(const TIntVector3 v1, T cubeRadius) {}; - - /** - * Clamps vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @result Vector clamped in cube. - */ - - template - TVector3 ClampToCube(const TIntVector3 v1, T cubeRadius) {}; - - /** - * Scales vector two specific magnitude. - * - * @param(v1) Vector - * - * @note It's faster to use operator* or operator*= for naturaly normalized vectors. - */ - - template - TVector3 ScaleToMagnitude(const TIntVector3& v1, T magnitude); - - /** - * Clamps vector into cube. - * - * @param(v1) Vector - * - * @result Vector with inverted components. - */ - - template - TVector3 CompInverse(const TIntVector3& v1); - - /** - * Reflect by plane - * - * @param(v1) Vector to mirror - * @param(plane) Plane to mirror on - * - * @return Mirrored vector - */ - - template - FORCEINLINE TVector3 ReflectFromPlane(const TIntVector3& v1, const TPlane& plane); - - /** - * Reflect by plane - * - * @param(v1) Vector to mirror - * @param(plane) Normal of plane - * - * @return Mirrored vector - */ - - template - FORCEINLINE TVector3 ReflectFromPlane(const TIntVector3& v1, const TVector3& normal); - - /** - * Rotates vector around axis - * - * @param(v1) Vector to mirror - * @param(axisNormal) Axis to rotate around - * - * @return Rotated vector - * @note Calculates vector rotation with Rodrigues-Rotation - */ - - template - TVector3 RotateAroundAxis(const TIntVector3& v1, const TVector3& axisNormal, Rt angle); - - /** - * Gets vector triple product ((v1 x v2) x v3). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @return Vector triple product - */ - - template - TIntVector3 VectorTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); - - /** - * Projects vector v1 onto v2 - * - * @param(v1) Vector to project - * @param(v2) Vector to project on - * - * @return Projected vector - */ - - template - TVector3 Project(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Rejects vector v1 from v2 - * - * @param(v1) Vector to reject - * @param(v2) Vector to reject from - * - * @return Rejected vector - */ - - template - TVector3 Reject(const TIntVector3& v1, const TIntVector3& v2); - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(normal) Normal of the plane - * - * @return Projected vector - * @note Simply rejects the vector from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlane(const TIntVector3& v1, const TVector3& normal); - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(normal) Plane - * - * @return Projected vector - * @note Simply rejects the vector from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlane(const TIntVector3& v1, const TPlane& plane); - - /** - * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. - * - * @param(v1) Starting vector - * @param(v2) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Interpolated unit vector - */ - - template - TVector3 Slerp(const TIntVector3& v1, const TIntVector3& v2, Rt t) {}; - - /** - * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. - * - * @param(v1) Starting vector - * @param(v2) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Interpolated unit vector. - * @note Does not clamp s between 0.0 and 1.0. - */ - - template - TVector3 SlerpUnclamped(const TIntVector3& v1, const TIntVector3& v2, Rt t) {}; + /** + * Construct Vector from two component array. + * + * @param comp Array of components + */ + + TIntVector3(const T* comp); + + /** + * Construct Vector from 3D integer Vector's xy. + * + * @param v 3D IntVector to copy from + */ + + TIntVector3(const TIntVector2& v); + + /** + * Construct Vector from 4D integer Vector's xy. + * + * @param v 4D IntVector to copy from + */ + + //TIntVector2(const TIntVector4& v); + + /** + * Construct Vector from 2D Point's xy. + * + * @param v 2D Point to copy from + */ + + //TIntVector2(const TIntPoint2& v); + + + /** + * Constructs a vector pointing from start to end. + * + * @param(start) Startingpoint + * @param(end) Endpoint + */ + + TIntVector3(const TIntPoint3& start, const TIntPoint3& end); + + }; + + + // ======================== // + // IntVector3 operators // + // ======================== // + + + /** + * Coponentwise addition of floating point to 3D vector + * + * @param(v1) vector to add to + * @param(s) floating point to add + */ + + template + inline TIntVector3 operator+= (TIntVector3& v1, T s); + + /** + * Coponentwise addition of 3D vector to 3D vector + * + * @param(v1) vector to add to + * @param(v2) vector to add + */ + + template + inline TIntVector3 operator+= (TIntVector3& v1, const TIntVector3& v2); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(s) floating point to substract + */ + + template + inline TIntVector3 operator-= (TIntVector3& v1, T s); + + /** + * Coponentwise substraction of 3D vector to 3D vector + * + * @param(v1) vector to substract from + * @param(v2) vector to substract with + */ + + template + inline TIntVector3 operator-= (TIntVector3& v1, const TIntVector3& v2); + + /** + * Dot product between two 3D Vectors + * + * @param(v1) vector one + * @param(s) floating point + */ + + template + inline TIntVector3 operator*= (TIntVector3& v1, T s); + + /** + * Coponentwise multiplication of 3D Vectors with floating point + * + * @param(v1) vector one + * @param(s) floating point + * + * @return Resulting vector + */ + + template + TIntVector3 operator* (const TIntVector3& v1, T s); + + /** + * Coponentwise multiplication of 3D Vectors with floating point + * + * @param(s) floating point + * @param(v2) vector + * + * @return Resultion vector + */ + + template + inline TIntVector3 operator* (T s, const TIntVector3& v1); + + /** + * Dot product between two 3D Vectors + * + * @param(v1) vector one + * @param(v2) vector two + * + * @return Dot product of Vectors + */ + + template + T operator* (const TIntVector3& v1, const TIntVector3& v2); + + /** + * Coponentwise addition of floating point to 3D vector + * + * @param(v1) vector to add to + * @param(s) floating point to add + * + * @return Resulting vector + */ + + template + TIntVector3 operator+ (const TIntVector3& v1, T s); + + /** + * Coponentwise addition of 3D vector to 3D vector + * + * @param(v1) vector to add to + * @param(v2) vector to add + * + * @return Resulting vector + */ + + template + TIntVector3 operator+ (const TIntVector3& v1, const TIntVector3& v2); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(s) floating point to substract + * + * @return Resulting vector + */ + + template + TIntVector3 operator- (const TIntVector3& v1, T s); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(v2) vector to substract with + * + * @return Resulting vector + */ + + template + TIntVector3 operator- (const TIntVector3& v1, const TIntVector3& v2); + + /** + * Negates vector + * + * @param(v1) Vector to negate + */ + + template + TIntVector3 operator- (TIntVector3& v1); + + /** + * Tests two 3D vectors for equality. + * + * @ref [FUNC]Equals + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return True if equal, false if not. + * + * @note Uses [MACRO]P_FLT_INAC + */ + + template + inline bool operator== (const TIntVector3& v1, const TIntVector3& v2); + + /** + * Tests two 3D vectors for inequality. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return True if inequal, false if not. + */ + + template + inline bool operator!= (const TIntVector3& v1, const TIntVector3& v2); + + // ============================================== // + // IntVector3 static function implementation // + // ============================================== // + + /** + * Gets magnitude of vector + * + * @param(v1) Vector + * + * @return Magnitude of vector + */ + + template + inline Rt Magnitude(const TIntVector3& v1); + + /** + * @see [FUNC]Magnitude + */ + + template + FORCEINLINE T Length(const TIntVector3& v1) { return Magnitude(v1); }; + + /** + * Gets square magnitude of vector + * + * @param(v1) Vector + * + * @return Square magnitude of vector + */ + + template + inline T SqrMagnitude(const TIntVector3& v1); + + /** + * @see SqrMagnitude + */ + + template + FORCEINLINE T SqrLength(const TIntVector3& v1) { return SqrMagnitude(v1); }; + + /** + * Gets angle between two vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Angle between vectors + */ + + template + Rt Angle(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Dot product of two vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Dot product of vectors + */ + + template + T DotP(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + * + * @return Vector with signs a components. + */ + + template + TIntVector3 SignVector(const TIntVector3& v1); + + /** + * Tests two vectors for equality. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy. + * + * @return True if equal, false if not. + */ + + template + inline bool Equals(const TIntVector3& v1, const TIntVector3& v2, T threshold = P_FLT_INAC); + + /** + * Calculates the cross product between two vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TIntVector3 CrossPV(TIntVector3& v1, const TIntVector3& v2); + + /** + * Gets the componentwise max of both vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TIntVector3 MaxV(TIntVector3& v1, const TIntVector3& v2); + + /** + * Gets the componentwise min of both vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TIntVector3 MinV(TIntVector3& v1, const TIntVector3& v2); + + /** + * Gets reversed vector. + * + * @param(v1) Vector one + * + * @note result is stored in v1. + */ + + template + TIntVector3 NegateV(TIntVector3& v1); + + /** + * Performes componentwise multiplication of two vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TIntVector3 ScaleV(TIntVector3& v1, const TIntVector3& v2); + + /** + * Copies v1 vector + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TIntVector3 Set(TIntVector3& v1, const TIntVector3& v2); + + /** + * Sets vector. + * + * @param(v1) Vector to copy to + * @param(x) X component + * @param(y) Y component + * @param(z) Z component + */ + + template + TIntVector3 Set(TIntVector3& v1, T x, T y, T z); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + */ + + template + TIntVector3 SignVectorV(TIntVector3& v1); + + + /** + * Gets scalar triple product ((v1 x v2) * v3). (Volume of parallelepiped.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @return Vector triple product + */ + + template + T ScalarTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); + + /** + * Gets the cosine of the angle between to vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Cosine of angle between vectors. + * @note Simply omits acos of angle. + */ + + template + T CosineAngle(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Gets vector triple product ((v1 x v2) x v3). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @note result is stored in v1 + */ + + template + TIntVector3 VectorTripleV(TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); + + /** + * Tests whether two vectors are perpendicular. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy + * + * @return True if perpendicular, false if not. + */ + + template + inline bool IsPerpendicular(const TIntVector3& v1, const TIntVector3& v2, T threshold = P_FLT_INAC); + + /** + * Tests whether two vectors are parallel. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) + * + * @return True if parallel, false if not. + */ + + template + inline bool IsParallel(const TIntVector3& v1, const TIntVector3& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Tests whether two vectors are coincident (Parallel and point in same direction). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) + * + * @return True if coincident, false if not. + */ + + template + inline bool IsCoincident(const TIntVector3& v1, const TIntVector3& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Tests whether v1 vectors is v1 unit vector. + * + * @param(v1) Vector + * @param(threshold) Allowed T inaccuracy + * + * @return True if unit vector, false if not. + */ + + template + inline bool IsNormalized(const TIntVector3& v1, T threshold = P_FLT_INAC); + + /** + * Tests if three vectors are coplanar + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * @param(threshold) Allowed T inaccuracy + * + * @return True if coplanar, false if not. + */ + + template + inline bool IsCoplanar(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3, T threshold = P_FLT_INAC); + + + /** + * Gets outer product of to vectors. + * + * @param a Vector one + * @param b Vector two + * + * @return Resulting matrix + */ + + //template + //Matrix3 OuterProduct(const IntVector3& a, const IntVector3& b); + + + // ================================================================ // + // IntVector3 static function implementation with return values // + // ================================================================ // + + /** + * Normalized vector + * + * @param(v1) vector to normalize + * + * @return Normalized vector + */ + + template + TVector3 Normalize(const TIntVector3& v1); + + /** + * Normalizes vector + * + * @param(v1) Vector + * + * @note Does not test for zero vector + */ + + template + TVector3 UnsafeNormalize(const TIntVector3& v1); + + /** + * Reflects a vector on a surface + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * + * @return Reflected vector + */ + + template + TVector3 Reflect(const TIntVector3& v1, const TVector3& normal); + + + /** + * Performes perspective divide on vector. + * + * @param(v1) vector to perspective divide + * + * @return Perspective divided vector + */ + + template + TVector3 PerspectiveDivide(const TIntVector3& v1); + + /** + * Gets cross product between two vectors. + * + * @param(v1) vector one + * @param(v2) vector two + * + * @return Cross product of v1 and v2 + */ + + template + TIntVector3 CrossP(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Linearly interpolates between two vectors. + * + * @param(start) Starting vector + * @param(dest) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Cross product of v1 and v2 + */ + + template + TVector3 Lerp(const TIntVector3& start, const TIntVector3& dest, Rt t); + + /** + * Linearly interpolates between two vectors. + * + * @param(v1) Starting vector + * @param(dest) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Cross product of v1 and v2 + * @note Does not clamp t between 0.0 and 1.0. + */ + + template + TVector3 LerpUnclamped(const TIntVector3& start, const TIntVector3& dest, Rt t); + + /** + * Creates a new Vector by the componentwise max of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector of componentwise max + */ + + template + TIntVector3 Max(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Creates a new Vector by the componentwise min of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector of componentwise min + */ + + template + TIntVector3 Min(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Gets reversed vector. + * + * @param(v1) Vector one + * + * @note result is stored in v1. + */ + + template + TIntVector3 Negate(const TIntVector3& v1); + + /** + * Multiplies vector componentwise. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector with componentwise products + */ + + template + TIntVector3 Scale(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Clamps vector to a range of magnitudes. + * + * @param(v1) Vector to clamp + * @param(min) Min magnitude + * @param(max) Max magnitude + * + * @return Clamped vector + */ + + template + TVector3 ClampMagnitude(const TIntVector3& v1, T min, T max); + + /** + * Binds vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @result Vector clamped in cube. + */ + + template + TVector3 BoundToCube(const TIntVector3 v1, T cubeRadius) {}; + + /** + * Clamps vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @result Vector clamped in cube. + */ + + template + TVector3 ClampToCube(const TIntVector3 v1, T cubeRadius) {}; + + /** + * Scales vector two specific magnitude. + * + * @param(v1) Vector + * + * @note It's faster to use operator* or operator*= for naturaly normalized vectors. + */ + + template + TVector3 ScaleToMagnitude(const TIntVector3& v1, T magnitude); + + /** + * Clamps vector into cube. + * + * @param(v1) Vector + * + * @result Vector with inverted components. + */ + + template + TVector3 CompInverse(const TIntVector3& v1); + + /** + * Reflect by plane + * + * @param(v1) Vector to mirror + * @param(plane) Plane to mirror on + * + * @return Mirrored vector + */ + + template + FORCEINLINE TVector3 ReflectFromPlane(const TIntVector3& v1, const TPlane& plane); + + /** + * Reflect by plane + * + * @param(v1) Vector to mirror + * @param(plane) Normal of plane + * + * @return Mirrored vector + */ + + template + FORCEINLINE TVector3 ReflectFromPlane(const TIntVector3& v1, const TVector3& normal); + + /** + * Rotates vector around axis + * + * @param(v1) Vector to mirror + * @param(axisNormal) Axis to rotate around + * + * @return Rotated vector + * @note Calculates vector rotation with Rodrigues-Rotation + */ + + template + TVector3 RotateAroundAxis(const TIntVector3& v1, const TVector3& axisNormal, Rt angle); + + /** + * Gets vector triple product ((v1 x v2) x v3). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @return Vector triple product + */ + + template + TIntVector3 VectorTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3); + + /** + * Projects vector v1 onto v2 + * + * @param(v1) Vector to project + * @param(v2) Vector to project on + * + * @return Projected vector + */ + + template + TVector3 Project(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Rejects vector v1 from v2 + * + * @param(v1) Vector to reject + * @param(v2) Vector to reject from + * + * @return Rejected vector + */ + + template + TVector3 Reject(const TIntVector3& v1, const TIntVector3& v2); + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(normal) Normal of the plane + * + * @return Projected vector + * @note Simply rejects the vector from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlane(const TIntVector3& v1, const TVector3& normal); + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(normal) Plane + * + * @return Projected vector + * @note Simply rejects the vector from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlane(const TIntVector3& v1, const TPlane& plane); + + /** + * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. + * + * @param(v1) Starting vector + * @param(v2) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Interpolated unit vector + */ + + template + TVector3 Slerp(const TIntVector3& v1, const TIntVector3& v2, Rt t) {}; + + /** + * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. + * + * @param(v1) Starting vector + * @param(v2) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Interpolated unit vector. + * @note Does not clamp s between 0.0 and 1.0. + */ + + template + TVector3 SlerpUnclamped(const TIntVector3& v1, const TIntVector3& v2, Rt t) {}; } // phanes::core::math::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h b/Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h index 8017a5a..910862e 100644 --- a/Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h +++ b/Engine/src/Runtime/Core/public/Math/MathAbstractTypes.h @@ -5,24 +5,24 @@ namespace Phanes::Core::Math::Internal { - template - struct AVector { - public: + template + struct AVector { + public: - /** - * List of n components of the vector - */ + /** + * List of n components of the vector + */ - T comp[D]; + T comp[D]; - }; + }; - template - struct AMatrix { - public: - T fields[n][m]; + template + struct AMatrix { + public: + T fields[n][m]; - }; + }; }; // Phanes::Core::Math::abstract::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/MathCommon.h b/Engine/src/Runtime/Core/public/Math/MathCommon.h index dfa3983..16745ce 100644 --- a/Engine/src/Runtime/Core/public/Math/MathCommon.h +++ b/Engine/src/Runtime/Core/public/Math/MathCommon.h @@ -21,76 +21,76 @@ namespace Phanes::Core::Math { - /** - * Clamps a value between minimum and maximum - * - * @param value Value to clamp - * @param low Minimum - * @param high Maximum - * - * @return Minimum, if value is to small / Maximum, if value is to large / value, if value is in range. - */ + /** + * Clamps a value between minimum and maximum + * + * @param value Value to clamp + * @param low Minimum + * @param high Maximum + * + * @return Minimum, if value is to small / Maximum, if value is to large / value, if value is in range. + */ - template - T Clamp(T value, T low, T high); + template + T Clamp(T value, T low, T high); - /** - * Gets the larger of two values - * - * @param x - * @param y - * - * @return Larger value - */ + /** + * Gets the larger of two values + * + * @param x + * @param y + * + * @return Larger value + */ - template - inline T Max(T x, T y); + template + inline T Max(T x, T y); - /** - * Gets the smaller of two values - * - * @param x - * @param y - * - * @return Smaller value - */ + /** + * Gets the smaller of two values + * + * @param x + * @param y + * + * @return Smaller value + */ - template - inline T Min(T x, T y); + template + inline T Min(T x, T y); - /** - * Swaps the values of two variables - * - * @param x - * @param y - */ + /** + * Swaps the values of two variables + * + * @param x + * @param y + */ - template - inline void Swap(T& x, T& y); + template + inline void Swap(T& x, T& y); - /** - * Test two numbers for equality - * - * @param x - */ - template - bool Equals(T x, T y, T threshold = P_FLT_INAC); + /** + * Test two numbers for equality + * + * @param x + */ + template + bool Equals(T x, T y, T threshold = P_FLT_INAC); - /** - * Calculates the reciprocal of the square root of n using the algorithm of A Quake III - * - * @param n Number to calculate - * - * @return Inverse square root of n - * - * @note a simple 1.0f / sqrtf(x) is faster than this algorithm. Use for research purpose only. - */ + /** + * Calculates the reciprocal of the square root of n using the algorithm of A Quake III + * + * @param n Number to calculate + * + * @return Inverse square root of n + * + * @note a simple 1.0f / sqrtf(x) is faster than this algorithm. Use for research purpose only. + */ - template - float FastInvSqrt(T n); + template + float FastInvSqrt(T n); } // phanes diff --git a/Engine/src/Runtime/Core/public/Math/MathFwd.h b/Engine/src/Runtime/Core/public/Math/MathFwd.h index 7915bda..3f9f523 100644 --- a/Engine/src/Runtime/Core/public/Math/MathFwd.h +++ b/Engine/src/Runtime/Core/public/Math/MathFwd.h @@ -18,85 +18,85 @@ 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; } // 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/MathTypeConversion.h b/Engine/src/Runtime/Core/public/Math/MathTypeConversion.h index 448baf9..f444f71 100644 --- a/Engine/src/Runtime/Core/public/Math/MathTypeConversion.h +++ b/Engine/src/Runtime/Core/public/Math/MathTypeConversion.h @@ -24,53 +24,53 @@ namespace Phanes::Core::Math { - // =================================================== // - // std::to_string wrapper // - // // - // This is, to make using ToString more general // - // and allow usage of one function instead of two, // - // for converting a mathmatical type to a string. // - // =================================================== // + // =================================================== // + // std::to_string wrapper // + // // + // This is, to make using ToString more general // + // and allow usage of one function instead of two, // + // for converting a mathmatical type to a string. // + // =================================================== // - FORCEINLINE std::string ToString(long long val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(long long val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(double val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(double val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(float val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(float val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(int val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(int val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(long val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(long val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(long double val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(long double val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(unsigned long long val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(unsigned long long val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(unsigned int val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(unsigned int val) { return std::to_string(val); }; - FORCEINLINE std::string ToString(unsigned long val) { return std::to_string(val); }; + FORCEINLINE std::string ToString(unsigned long val) { return std::to_string(val); }; - // ============ // - // ToString // - // ============ // + // ============ // + // ToString // + // ============ // - template - std::string ToString(const TVector2& v); + template + std::string ToString(const TVector2& v); - template - std::string ToString(const TIntVector2& v); + template + std::string ToString(const TIntVector2& v); - template - std::string ToString(const TVector3& v); + template + std::string ToString(const TVector3& v); - template - std::string ToString(const TIntVector3& v); + template + std::string ToString(const TIntVector3& v); - //std::string toString(const Vector4& v); + //std::string toString(const Vector4& v); - //std::string toString(const Matrix2& v); + //std::string toString(const Matrix2& v); - //std::string toString(const Matrix3& v); + //std::string toString(const Matrix3& v); } diff --git a/Engine/src/Runtime/Core/public/Math/MathUnitConversion.h b/Engine/src/Runtime/Core/public/Math/MathUnitConversion.h index 7cd89cc..6cab5b2 100644 --- a/Engine/src/Runtime/Core/public/Math/MathUnitConversion.h +++ b/Engine/src/Runtime/Core/public/Math/MathUnitConversion.h @@ -11,111 +11,111 @@ namespace Phanes::Core::Math::UnitConversion { - /** - * Converts degrees to radians. - * - * @param(deg) Angle in degress (°) - * - * @return Angle in radians - */ + /** + * Converts degrees to radians. + * + * @param(deg) Angle in degress (°) + * + * @return Angle in radians + */ - template - inline T DegToRad(T deg); + template + inline T DegToRad(T deg); - /** - * Converts radians to degrees. - * - * @param(rad) Angle in radians (rad) - * - * @return Angle in degrees - */ + /** + * Converts radians to degrees. + * + * @param(rad) Angle in radians (rad) + * + * @return Angle in degrees + */ - template - inline T RadToDeg(T rad); + template + inline T RadToDeg(T rad); - /** - * Converts degrees to gradian. - * - * @param(deg) Angle in degress (°) - * - * @return Angle in gradian - */ + /** + * Converts degrees to gradian. + * + * @param(deg) Angle in degress (°) + * + * @return Angle in gradian + */ - template - inline T DegToGradian(T deg); + template + inline T DegToGradian(T deg); - /** - * Converts gradian to degrees. - * - * @param(rad) Angle in gradians (g) - * - * @return Angle in degrees - */ + /** + * Converts gradian to degrees. + * + * @param(rad) Angle in gradians (g) + * + * @return Angle in degrees + */ - template - inline T GradianToDeg(T g); + template + inline T GradianToDeg(T g); - /** - * Converts radians to gradians. - * - * @param(deg) Angle in radians (rad) - * - * @return Angle in gradians - */ + /** + * Converts radians to gradians. + * + * @param(deg) Angle in radians (rad) + * + * @return Angle in gradians + */ - template - inline T RadToGradian(T rad); + template + inline T RadToGradian(T rad); - /** - * Converts gradian to radians. - * - * @param(rad) Angle in gradians (g) - * - * @return Angle in radians - */ + /** + * Converts gradian to radians. + * + * @param(rad) Angle in gradians (g) + * + * @return Angle in radians + */ - template - inline T GradianToRad(T g); + template + inline T GradianToRad(T g); } // phanes::core::math::typeconversion namespace Phanes::Core::Math::UnitLiterals { - // ============================================== // - // unit conversion with user-defined literals // - // ============================================== // + // ============================================== // + // unit conversion with user-defined literals // + // ============================================== // - /** - * Convert deg to rad. - * - * @param(_x) Angle in degress - */ + /** + * Convert deg to rad. + * + * @param(_x) Angle in degress + */ - double operator ""_deg(long double _x) - { - return _x * P_PI_180_FLT; - } + double operator ""_deg(long double _x) + { + return _x * P_PI_180_FLT; + } - /** - * Convert rad to rad. - * - * @param(_x) Angle in degress - */ + /** + * Convert rad to rad. + * + * @param(_x) Angle in degress + */ - double operator ""_rad(long double _x) - { - return _x; - } + double operator ""_rad(long double _x) + { + return _x; + } - /** - * Convert gradian to rad. - * - * @param(_x) Angle in degress - */ + /** + * Convert gradian to rad. + * + * @param(_x) Angle in degress + */ - double operator ""_g(long double _x) - { - return _x * P_PI_FLT / 200; - } + double operator ""_g(long double _x) + { + return _x * P_PI_FLT / 200; + } } \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/Math/Matrix2.h b/Engine/src/Runtime/Core/public/Math/Matrix2.h index 8526941..21a10a7 100644 --- a/Engine/src/Runtime/Core/public/Math/Matrix2.h +++ b/Engine/src/Runtime/Core/public/Math/Matrix2.h @@ -9,144 +9,144 @@ #define MATRIX2_H namespace Phanes::Core::Math { - - // 2x2 Matrix defined in column-major order. - // Accessed by M[Row][Col]. + + // 2x2 Matrix defined in column-major order. + // Accessed by M[Row][Col]. - template - struct alignas(4) TMatrix2 - { - public: + template + struct alignas(4) TMatrix2 + { + public: - alignas(4) T m[2][2]; + alignas(4) T m[2][2]; - public: + public: - TMatrix2() = default; + TMatrix2() = default; - /** - * Copy constructor. - */ + /** + * Copy constructor. + */ - TMatrix2(const TMatrix2& m); + TMatrix2(const TMatrix2& m); - /** - * Move constructor. - */ + /** + * Move constructor. + */ - TMatrix2(TMatrix2&& m); + TMatrix2(TMatrix2&& m); - /** - * Construct Matrix from 2d array. - * - * @param(fields) 2D Array with column major order. - */ + /** + * Construct Matrix from 2d array. + * + * @param(fields) 2D Array with column major order. + */ - TMatrix2(T fields[2][2]); + TMatrix2(T fields[2][2]); - /** - * Construct Matrix from parameters. - * - * @param(n00) M[0][0] - * @param(n10) M[1][0] - * @param(n01) M[0][1] - * @param(n11) M[1][1] - * - * @note nXY = n[Row][Col] - */ + /** + * Construct Matrix from parameters. + * + * @param(n00) M[0][0] + * @param(n10) M[1][0] + * @param(n01) M[0][1] + * @param(n11) M[1][1] + * + * @note nXY = n[Row][Col] + */ - TMatrix2(T n00, T n10, T n01, T n11); + TMatrix2(T n00, T n10, T n01, T n11); - /** - * Construct Matrix from two 2d vector columns. - * - * @param(v1) Column zero - * @param(v2) Column one - */ + /** + * Construct Matrix from two 2d vector columns. + * + * @param(v1) Column zero + * @param(v2) Column one + */ - TMatrix2(const TVector2& v1, const TVector2& v2); + TMatrix2(const TVector2& v1, const TVector2& v2); - public: + public: - FORCEINLINE T& operator() (int n, int m); - FORCEINLINE TVector2& operator[] (int m); + FORCEINLINE T& operator() (int n, int m); + FORCEINLINE TVector2& operator[] (int m); - FORCEINLINE const T& operator() (int n, int m) const; - FORCEINLINE const TVector2& operator[] (int m) const; - }; + FORCEINLINE const T& operator() (int n, int m) const; + FORCEINLINE const TVector2& operator[] (int m) const; + }; - // ==================== // - // Matrix2 operator // - // ==================== // - - template - void operator+= (TMatrix2& m1, T s); + // ==================== // + // Matrix2 operator // + // ==================== // + + template + void operator+= (TMatrix2& m1, T s); - template - void operator+= (TMatrix2& m1, const TMatrix2& m2); - - template - void operator-= (TMatrix2& m1, T s); - - template - void operator-= (TMatrix2& m1, const TMatrix2& m2); - - template - void operator*= (TMatrix2& m1, T s); - - template - void operator*= (TMatrix2& m1, const TMatrix2& m2); + template + void operator+= (TMatrix2& m1, const TMatrix2& m2); + + template + void operator-= (TMatrix2& m1, T s); + + template + void operator-= (TMatrix2& m1, const TMatrix2& m2); + + template + void operator*= (TMatrix2& m1, T s); + + template + void operator*= (TMatrix2& m1, const TMatrix2& m2); - template - TMatrix2 operator+ (const TMatrix2& m1, T s); - - template - TMatrix2 operator+ (const TMatrix2& m1, const TMatrix2& m2); + template + TMatrix2 operator+ (const TMatrix2& m1, T s); + + template + TMatrix2 operator+ (const TMatrix2& m1, const TMatrix2& m2); - template - TMatrix2 operator- (const TMatrix2& m1, T s); - - template - TMatrix2 operator- (const TMatrix2& m1, const TMatrix2& m2); + template + TMatrix2 operator- (const TMatrix2& m1, T s); + + template + TMatrix2 operator- (const TMatrix2& m1, const TMatrix2& m2); - template - TMatrix2 operator* (const TMatrix2& m1, T s); - - template - TMatrix2 operator* (const TMatrix2& m1, const TMatrix2& m2); - - template - TVector2 operator* (const TMatrix2& m1, const TVector2& v); + template + TMatrix2 operator* (const TMatrix2& m1, T s); + + template + TMatrix2 operator* (const TMatrix2& m1, const TMatrix2& m2); + + template + TVector2 operator* (const TMatrix2& m1, const TVector2& v); - template - bool operator== (const TMatrix2& m1, const TMatrix2& m2); + template + bool operator== (const TMatrix2& m1, const TMatrix2& m2); - // =============================== // - // Matrix function definition // - // =============================== // + // =============================== // + // Matrix function definition // + // =============================== // - template - T Determinant(const Matrix2& m1); + template + T Determinant(const Matrix2& m1); - template - void InverseV(TMatrix2& m1); + template + void InverseV(TMatrix2& m1); - template - void TransposeV(TMatrix2& m1); + template + void TransposeV(TMatrix2& m1); - // =============== // - // WITH RETURN // - // =============== // + // =============== // + // WITH RETURN // + // =============== // - template - TMatrix2 Inverse(TMatrix2& m1); + template + TMatrix2 Inverse(TMatrix2& m1); - template - TMatrix2 Transpose(const TMatrix2& m1); + template + TMatrix2 Transpose(const TMatrix2& m1); - template - bool IsIndentityMatrix(const TMatrix2& m1, T threshold = P_FLT_INAC); + template + bool IsIndentityMatrix(const TMatrix2& m1, T threshold = P_FLT_INAC); } // Phanes::Core::Math diff --git a/Engine/src/Runtime/Core/public/Math/Plane.h b/Engine/src/Runtime/Core/public/Math/Plane.h index baf8822..be790bd 100644 --- a/Engine/src/Runtime/Core/public/Math/Plane.h +++ b/Engine/src/Runtime/Core/public/Math/Plane.h @@ -8,14 +8,16 @@ namespace Phanes::Core::Math { - // Plane in 3D space, defined as: P: ax + by + cz = d; + // Plane in 3D space, defined as: P: ax + by + cz = d; - template - struct TPlane - { - public: - TVector3 normal; - T d; - }; + template + struct TPlane + { + public: + TVector3 normal; + T d; + }; -} // Phanes::Core::Math \ No newline at end of file +} // Phanes::Core::Math + + \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/Math/Point.h b/Engine/src/Runtime/Core/public/Math/Point.h index f732f1e..58a6397 100644 --- a/Engine/src/Runtime/Core/public/Math/Point.h +++ b/Engine/src/Runtime/Core/public/Math/Point.h @@ -20,164 +20,164 @@ namespace Phanes::Core::Math { - /** - * A 2D Point with components x and y with float precision. - */ + /** + * A 2D Point with components x and y with float precision. + */ - template - struct TPoint2 : public TVector2 { - static_assert(std::is_floating_point_v, "T must be a floating point"); + template + struct TPoint2 : public TVector2 { + static_assert(std::is_floating_point_v, "T must be a floating point"); - using TVector2::TVector2; + using TVector2::TVector2; - using Real = T; + using Real = T; - /** - * Creates Point2 from Point3's xy - * - * @param a Point3 one - */ + /** + * Creates Point2 from Point3's xy + * + * @param a Point3 one + */ - TPoint2(const TPoint3& p) - { - this->x = p.x; - this->y = p.y; - } + TPoint2(const TPoint3& p) + { + this->x = p.x; + this->y = p.y; + } - /** - * Creates Point2 from Point4's xy - * - * @param a Point4 one - */ + /** + * Creates Point2 from Point4's xy + * + * @param a Point4 one + */ - TPoint2(const TPoint4& p) - { - this->x = p.x; - this->y = p.y; - } - }; + TPoint2(const TPoint4& p) + { + this->x = p.x; + this->y = p.y; + } + }; - /** - * Calculates distance between two points. - * - * @param(p1) Point one - * @param(p2) Point two - * - * @return Distance between two points. - */ + /** + * Calculates distance between two points. + * + * @param(p1) Point one + * @param(p2) Point two + * + * @return Distance between two points. + */ - template - T Distance(const TPoint2& p1, const TPoint2& p2); + template + T Distance(const TPoint2& p1, const TPoint2& p2); - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /** - * A 3D Point with components x and y with float precision. - */ + /** + * A 3D Point with components x and y with float precision. + */ - template - struct TPoint3 : public TVector3 { - static_assert(std::is_floating_point_v(T), "T must be a floating point"); + template + struct TPoint3 : public TVector3 { + static_assert(std::is_floating_point_v(T), "T must be a floating point"); - using TVector3::TVector3; + using TVector3::TVector3; - using Real = T; + using Real = T; - /** - * Creates Point3 from Point2's xy and zero - * - * @param a Point2 one - */ + /** + * Creates Point3 from Point2's xy and zero + * + * @param a Point2 one + */ - TPoint3(const TPoint2& p) - { - this->x = p.x; - this->y = p.y; - this->z = 0; - } + TPoint3(const TPoint2& p) + { + this->x = p.x; + this->y = p.y; + this->z = 0; + } - /** - * Creates Point3 from Point4's xyz - * - * @param a Point4 one - */ + /** + * Creates Point3 from Point4's xyz + * + * @param a Point4 one + */ - TPoint3(const TPoint4& p) - { - this->x = p.x; - this->y = p.y; - this->z = p.z; - } - }; + TPoint3(const TPoint4& p) + { + this->x = p.x; + this->y = p.y; + this->z = p.z; + } + }; - /** - * Calculates distance between two points. - * - * @param(p1) Point one - * @param(p2) Point two - * - * @return Distance between two points. - */ + /** + * Calculates distance between two points. + * + * @param(p1) Point one + * @param(p2) Point two + * + * @return Distance between two points. + */ - template - T Distance(const TPoint3& p1, const TPoint3& p2); + template + T Distance(const TPoint3& p1, const TPoint3& p2); - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /** - * A 4D Point with components x and y with float precision. - */ + /** + * A 4D Point with components x and y with float precision. + */ - //template - //struct TPoint4 : public TVector4 { - // static_assert(std::is_floating_point_v(T), "T must be a floating point"); + //template + //struct TPoint4 : public TVector4 { + // static_assert(std::is_floating_point_v(T), "T must be a floating point"); - // using TVector4::TVector4; + // using TVector4::TVector4; - // /** - // * Creates Point4 from Point2's xy and the last two zero - // * - // * @param a Point2 one - // */ + // /** + // * 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; - // } + // 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 - // */ + // /** + // * 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; - // } - //}; + // 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. - // */ + ///** + // * 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); } // phanes::core::math::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/Vector2.h b/Engine/src/Runtime/Core/public/Math/Vector2.h index 0d2913b..06c25c2 100644 --- a/Engine/src/Runtime/Core/public/Math/Vector2.h +++ b/Engine/src/Runtime/Core/public/Math/Vector2.h @@ -23,911 +23,911 @@ namespace Phanes::Core::Math { - /** - * A 2D Vector with components x and y with floating point precision. - */ - - - template - struct TVector2 { + /** + * A 2D Vector with components x and y with floating point precision. + */ + + + template + struct TVector2 { - public: + public: - using Real = T; + using Real = T; - // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. + // Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa. - union - { - - struct - { - /** X component of Vector - * - * @see [FIELD]components - * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real x; - - /** Y component of Vector - * - * @see [FIELD]components - * - * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real y; - }; + union + { + + struct + { + /** X component of Vector + * + * @see [FIELD]components + * @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + Real x; + + /** Y component of Vector + * + * @see [FIELD]components + * + * @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience. + */ + Real y; + }; - /** Components array holding the data - * - * @see [FIELD]x - * @see [FIELD]y - * - * @note Components are split into x and y. Access and manipulation is possible by these variables. - */ + /** Components array holding the data + * + * @see [FIELD]x + * @see [FIELD]y + * + * @note Components are split into x and y. Access and manipulation is possible by these variables. + */ - Real comp[2]; + Real comp[2]; - }; + }; - public: + public: - /** - * Default constructor without initialization - */ + /** + * Default constructor without initialization + */ - TVector2() = default; - - /** - * Copy constructor - */ + TVector2() = default; + + /** + * Copy constructor + */ - TVector2(const TVector2& v); + TVector2(const TVector2& v); - /** - * Move constructor - */ + /** + * Move constructor + */ - TVector2(TVector2&& v); + TVector2(TVector2&& v); - /** - * Convert other type of vector - */ + /** + * Convert other type of vector + */ - template - explicit TVector2(const TVector2& v) : x((T)v.x), y((T)v.y) {}; + template + explicit TVector2(const TVector2& v) : x((T)v.x), y((T)v.y) {}; - template - explicit TVector2(const TIntVector2& v) : x((T)v.x), y((T)v.y) {}; + template + explicit TVector2(const TIntVector2& v) : x((T)v.x), y((T)v.y) {}; - /** - * Construct Vector from xy components. - * - * @param(x) X component - * @param(y) Y component - */ - - TVector2(const Real x, const Real y); + /** + * Construct Vector from xy components. + * + * @param(x) X component + * @param(y) Y component + */ + + TVector2(const Real x, const Real y); - /** - * Construct Vector from two component array. - * - * @param(comp) Array of components - */ - - explicit TVector2(const Real* comp); - - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ + /** + * Construct Vector from two component array. + * + * @param(comp) Array of components + */ + + explicit TVector2(const Real* comp); + + + /** + * Constructs a vector pointing from start to end. + * + * @param(start) Startingpoint + * @param(end) Endpoint + */ - TVector2(const TPoint2& start, const TPoint2& end); + TVector2(const TPoint2& start, const TPoint2& end); - /** - * Construct Vector from 3D Vector's xy. - * - * @param(v) 3D Vector to copy from - */ - - explicit TVector2(const TVector3& v); - - /** - * Construct Vector from 4D Vector's xy. - * - * @param(v) 4D Vector to copy from - */ - - //TVector2(const TVector4& v); + /** + * Construct Vector from 3D Vector's xy. + * + * @param(v) 3D Vector to copy from + */ + + explicit TVector2(const TVector3& v); + + /** + * Construct Vector from 4D Vector's xy. + * + * @param(v) 4D Vector to copy from + */ + + //TVector2(const TVector4& v); - /** - * Construct Vector from 2D integer Vector's xy. - * - * @param(v) 2D IntVector to copy from - */ + /** + * Construct Vector from 2D integer Vector's xy. + * + * @param(v) 2D IntVector to copy from + */ - //TVector2(const TIntVector2& v); + //TVector2(const TIntVector2& v); - /** - * Construct Vector from 3D integer Vector's xy. - * - * @param(v) 3D IntVector to copy from - */ + /** + * Construct Vector from 3D integer Vector's xy. + * + * @param(v) 3D IntVector to copy from + */ - //TVector2(const TIntVector3& v); + //TVector2(const TIntVector3& v); - /** - * Construct Vector from 4D integer Vector's xy. - * - * @param(v) 4D IntVector to copy from - */ + /** + * Construct Vector from 4D integer Vector's xy. + * + * @param(v) 4D IntVector to copy from + */ - //TVector2(const TIntVector4& v); + //TVector2(const TIntVector4& v); - /** - * Construct Vector from 2D Point's xy. - * - * @param(v) 2D Point to copy from - */ - - //TVector2(const TPoint2& v); - - - }; - - // ====================== // - // TVector2 operators // - // ====================== // - - /** - * Addition operation on same TVector2 (this) by a floating point value. - * - * @param(v1) Vector to add to - * @param(s) Floating point to add - */ - - template - TVector2 operator+= (TVector2& v1, T s); - - /** - * Addition operation on same TVector2 (this) by a another TVector2. - * - * @param(v1) Vector to add to - * @param(v2) Vector to add - */ - - template - TVector2 operator+= (TVector2& v1, const TVector2& v2); - - /** - * Substraction operation on same TVector2 (this) by a floating point. - * - * @param(v1) Vector to substract from - * @param(v2) Floating point to substract - */ - - template - TVector2 operator-= (TVector2& v1, T s); - - /** - * Substraction operation on same TVector2 (this) by a another TVector2. - * - * @param(v1) Vector to substract from - * @param(v2) Vector to substract - */ - - template - TVector2 operator-= (TVector2& v1, const TVector2& v2); - - /** - * Multiplication of TVector2 (this) with a floating point. - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - */ - - template - TVector2 operator*= (TVector2& v1, T s); - - /** - * Devision of Vector (this) by floating point. - * - * @param(v1) Vector to divide with - * @param(s Floating point to divide with - */ - - template - TVector2 operator/= (TVector2& v1, T s); - - /** - * Scale of Vector by floating point. (> Creates a new TVector2) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - * - * @return Result Vector - */ - - template - TVector2 operator* (const TVector2& v1, T s); - - /** - * Division of Vector by floating point. (> Creates another TVector2) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to divide with - * - * @return Result Vector - */ - - template - TVector2 operator/ (const TVector2& v1, T s); - - /** - * Scale of Vector by floating point. (> Creates a new TVector2) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to multiply with - * - * @return Result Vector - */ - - template - inline TVector2 operator* (T s, const TVector2& v1); - - /** - * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.) - * - * @param(v1) Vector to multiply with - * @param(s Floating point to divide with - * - * @return Result Vector - */ - - template - inline TVector2 operator/ (T s, const TVector2& v1); - - /** - * Dot product between two Vectors. - * - * @see [FUNC]DotP - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @result Dot product - */ - - template - T operator* (const TVector2& v1, const TVector2& v2); - - /** - * Componentwise addition of Vector with floating point. - * - * @param(v1) Vector to add to - * @param(s Floating point to add - * - * @return Result Vector - */ - - template - TVector2 operator+ (const TVector2& v1, T s); - - /** - * Componentwise addition of Vector with floating point. - * - * @param(v1) Vector to add to - * @param(s Floating point to add - * - * @return Result Vector - */ - - template - TVector2 operator+ (const TVector2& v1, const TVector2& v2); - - /** - * Componentwise substraction of Vector with floating point. - * - * @param(v1) Vector to substract from - * @param(s Floating point to substract - * - * @return Result Vector - */ - - template - TVector2 operator- (const TVector2& v1, T s); - - /** - * Componentwise substraction of Vector with Vector. - * - * @param(v1) Vector to substract from - * @param(s Floating point to substract - * - * @return Result Vector - */ - - template - TVector2 operator- (const TVector2& v1, const TVector2& v2); - - /** - * Negate Vector. - * - * @param(v1) Vector to negate - */ - - template - void operator- (TVector2& v1); - - - /** - * Compare Vector for equality. - * - * @see [FUNC]Equals - * - * @param(v1) Vector to negate - * - * @return true if equal, false if inequal - */ - - template - bool operator== (const TVector2& v1, const TVector2& v2); - - - /** - * Compare Vector for inequality. - * - * @see [FUNC]Equals - * - * @param(v1) Vector to negate - * - * @return true if inequal, false if equal - */ - - template - bool operator!= (const TVector2& v1, const TVector2& v2); - - - // ============================================ // - // TVector2 static function implementation // - // ============================================ // - - /** - * Magnitude of Vector - * - * @param(v1) Vector - * - * @return Size of Vector - */ - - template - T Magnitude(const TVector2& v1); - - /** - * @see [FUNC]Magnitude - */ - template - FORCEINLINE T Length(const TVector2& v1) { return Magnitude(v1); }; - - /** - * Square of magnitude of Vector - * - * @param(v1) Vector - * - * @return Magnitude without calculating square root - */ - - template - T SqrMagnitude(const TVector2& v1); - - /** - * @see [FUNC]SqrMagnitude - */ - template - FORCEINLINE T SqrLength(const TVector2& v1) { return SqrMagnitude(v1); }; - - /** - * Normalize Vector - * - * @param(v1) Vector - */ - - template - TVector2 NormalizeV(TVector2& v1); - - /** - * Normalize Vector - * - * @param(v1) Vector - * - * @note Does not look for zero vector. - */ - - template - TVector2 UnsafeNormalizeV(TVector2& v1); - - /** - * Angle between to Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - T Angle(const TVector2& v1, const TVector2& v2); - - /** - * Cosine of angle between to Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - T CosineAngle(const TVector2& v1, const TVector2& v2); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - */ - - template - TVector2 SignVectorV(TVector2& v1); - - /** - * Binds a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - */ - - template - TVector2 BindToSquareV(TVector2& v1, T radius); - - /** - * Clamps a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - */ - - template - TVector2 ClampToSquareV(TVector2& v1, T radius); - - /** - * Dot product of two Vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - */ - - template - T DotP(const TVector2& v1, const TVector2& v2); - - /** - * Creates Vector, with component wise largest values. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TVector2 MaxV (TVector2& v1, const TVector2& v2); - - /** - * Creates Vector, with component wise smallest values. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TVector2 MinV (TVector2& v1, const TVector2& v2); - - /** - * Gets perpendicular Vector to v1. - * - * @param(v1) Vector one - * - * @note Stores new Vector to v1 - */ - - template - TVector2 GetPerpendicularV (TVector2& v1); - - /** - * Gets perpendicular Vector to v1. - * - * @reg [FUNC]PerpendicularV - * - * @param(v1) Vector one - * - * @note Stores new Vector to v1 - */ - - template - TVector2 GetReversePerpendicularV (TVector2& v1); - - /** - * Component wise multiplication of Vector - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note Stores new Vector to v1 - */ - - template - TVector2 ScaleV(TVector2& v1, const TVector2& v2); - - /** - * Componentwise inverse of Vector - * - * @param(v1) Vector one - * - * @note Stores new Vector to v1 - */ - - template - TVector2 CompInverseV(TVector2& v1); - - /** - * Reflect Vector by normal vector. - * - * @param(v1) Vector one - * @param(normal) Normal of surface - * - * @note Stores new Vector to v1 - */ - - template - TVector2 ReflectV (TVector2& v1, const TVector2& normal); - - /** - * Copies one Vector two another - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TVector2 Set(TVector2& v1, const TVector2& v2); - - /** - * Sets components of a vector. - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TVector2 Set(TVector2& v1, T x, T y); - - /** - * Anti-clockwise vector rotation. - * - * @param(v1) Vector to rotate - * - * @note Angle is not clamped - */ - - template - TVector2 RotateV(TVector2& v1, T angle); - - - /** - * Clockwise vector rotation. - * - * @param(v1) Vector to rotate - * - * @note Angle is not clamped - */ - - template - FORCEINLINE TVector2 ClockwiseRotateV(TVector2& v1, T angle); - - /** - * Negates Vector - * - * @param(v1) Vector one - */ - - template - TVector2 NegateV(TVector2& v1); - - /** - * Tests if vector is a unity vector. - * - * @param(v1) Vector one - * @param(threshold) Threshold to zero - * - * @return true if unit vector, false if not - */ - - template - inline bool IsNormalized(const TVector2& v1, T threshold = P_FLT_INAC); - - /** - * Tests if 2 vectors are perpendicular to each other. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Threshold to zero - * - * @return true if perpendicular, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsPerpendicular(const TVector2& v1, const TVector2& v2, T threshold = P_FLT_INAC); - - /** - * Tests if 2 vectors are parallel to each other. (Angle is close to zero.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(t) threshold Threshold from one (e.g. 0.98f) - * - * @return true if parallel, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsParallel(const TVector2& v1, const TVector2& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Tests if 2 vectors are coincident. (Are parallel and point in the same direction.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) from one (e.g. 0.98f) - * - * @return true if coincident, false if not - * - * @note Requires v1 and v2 to be normal vectors. - */ - - template - inline bool IsCoincident(const TVector2& v1, const TVector2& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Gets outer product of to vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Resulting matrix - */ - - // - //Matrix2 OuterProduct(const TVector2& v1, const TVector2& v2); - - - // ============================================================== // - // TVector2 static function implementation with return values // - // ============================================================== // - - - /** - * Reflects a vector on a normal - * - * @param(v1) Vector one - * @param(normal) Normal of surface - * - * @return Reflected vector - */ - - template - TVector2 Reflect(const TVector2& v1, const TVector2& normal); - - /** - * Scales a vector component wise - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Reflected vector - */ - - template - TVector2 Scale(const TVector2& v1, const TVector2& v2); - - /** - * Componentwise inverse of a vector - * - * @param(v1) Vector one - * - * @return Componentwise inverted vector - */ - - template - TVector2 CompInverse(const TVector2& v1); - - - /** - * Negates Vector - * - * @param(v1) Vector one - * - * @return Componentwise inverted vector - */ - - template - TVector2 Negate(const TVector2& v1); - - /** - * Gets the perpendicular vector of v1 - * - * @param(v1) Vector one - * - * @return Perpendicular vector - */ - - template - TVector2 GetPerpendicular(const TVector2& v1); - - /** - * Gets reverse of the perpendicular vector of v1 - * - * @param(v1) Vector one - * - * @return Reversed perpendicular vector - */ - - template - TVector2 GetReversePerpendicular(const TVector2& v1); - - /** - * Creates a new Vector by the component wise minimals of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Minimal vector - */ - - template - TVector2 Min(const TVector2& v1, const TVector2& v2); - - /** - * Creates a new Vector by the component wise maxima of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Maximal vector - */ - - template - TVector2 Max(const TVector2& v1, const TVector2& v2); - - /** - * Creates a normalized instance of the vector - * - * @param(v1) Vector to normalize - * - * @return Unit vector - */ - - template - TVector2 Normalize(const TVector2& v1); - - /** - * Creates a normalized instance of the vector - * - * @param(v1) Vector to normalize - * - * @return Unit vector - * @note Does not test for zero vector - */ - - template - TVector2 UnsafeNormalize(const TVector2& v1); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - * - * @return Vector with signs as components - */ - - template - TVector2 SignVector(const TVector2& v1); - - /** - * Binds a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - * - * @return Bound vector - */ - - template - TVector2 BindToSquare(const TVector2& v1, T radius); - - /** - * Clamps a vector to a square with a radius - * - * @param(v1) Vector one - * @param(radius) Radius of square (=> Distance from middle to center of each site.) - * - * @return Clamped vector. If the length of the vector fits the square, then the vector is returned. - */ - - template - TVector2 ClampToSquare(const TVector2& v1, T radius); - - /** - * Interpolates between to vectors. - * - * @param(startVec) Start vector (t = 0) - * @param(destVec) Destination vector (t = 1) - * @param(t) Interpolation value - * - * @return Interpolated vector - * - * @note Interpolation is clamped between 0 - 1. - */ - - template - TVector2 Lerp(const TVector2& startVec, const TVector2& destVec, T t); - - /** - * Interpolates between to vectors. - * - * @param(startVec) Start vector (t = 0) - * @param(destVec) Destination vector (t = 1) - * @param(t) Interpolation value - * - * @return Interpolated vector - * - * @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f - */ - - template - TVector2 LerpUnclamped(const TVector2& startVec, const TVector2& destVec, T t); - - /** - * Anti-clockwise vector rotation. - * - * @param(v1) Vector to rotate - * @param(angle) Angle to rotate - * - * @return Rotated vector - * - * @note Angle is not clamped - */ - - template - TVector2 Rotate(const TVector2& v1, T angle); - - /** - * Clockwise vector rotation. - * - * @param(v1) Vector to rotate - * - * @return Rotated vector - * - * @note Angle is not clamped - */ - - template - TVector2 ClockwiseRotate(const TVector2& v1, T angle); + /** + * Construct Vector from 2D Point's xy. + * + * @param(v) 2D Point to copy from + */ + + //TVector2(const TPoint2& v); + + + }; + + // ====================== // + // TVector2 operators // + // ====================== // + + /** + * Addition operation on same TVector2 (this) by a floating point value. + * + * @param(v1) Vector to add to + * @param(s) Floating point to add + */ + + template + TVector2 operator+= (TVector2& v1, T s); + + /** + * Addition operation on same TVector2 (this) by a another TVector2. + * + * @param(v1) Vector to add to + * @param(v2) Vector to add + */ + + template + TVector2 operator+= (TVector2& v1, const TVector2& v2); + + /** + * Substraction operation on same TVector2 (this) by a floating point. + * + * @param(v1) Vector to substract from + * @param(v2) Floating point to substract + */ + + template + TVector2 operator-= (TVector2& v1, T s); + + /** + * Substraction operation on same TVector2 (this) by a another TVector2. + * + * @param(v1) Vector to substract from + * @param(v2) Vector to substract + */ + + template + TVector2 operator-= (TVector2& v1, const TVector2& v2); + + /** + * Multiplication of TVector2 (this) with a floating point. + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + */ + + template + TVector2 operator*= (TVector2& v1, T s); + + /** + * Devision of Vector (this) by floating point. + * + * @param(v1) Vector to divide with + * @param(s Floating point to divide with + */ + + template + TVector2 operator/= (TVector2& v1, T s); + + /** + * Scale of Vector by floating point. (> Creates a new TVector2) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + * + * @return Result Vector + */ + + template + TVector2 operator* (const TVector2& v1, T s); + + /** + * Division of Vector by floating point. (> Creates another TVector2) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to divide with + * + * @return Result Vector + */ + + template + TVector2 operator/ (const TVector2& v1, T s); + + /** + * Scale of Vector by floating point. (> Creates a new TVector2) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to multiply with + * + * @return Result Vector + */ + + template + inline TVector2 operator* (T s, const TVector2& v1); + + /** + * Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.) + * + * @param(v1) Vector to multiply with + * @param(s Floating point to divide with + * + * @return Result Vector + */ + + template + inline TVector2 operator/ (T s, const TVector2& v1); + + /** + * Dot product between two Vectors. + * + * @see [FUNC]DotP + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @result Dot product + */ + + template + T operator* (const TVector2& v1, const TVector2& v2); + + /** + * Componentwise addition of Vector with floating point. + * + * @param(v1) Vector to add to + * @param(s Floating point to add + * + * @return Result Vector + */ + + template + TVector2 operator+ (const TVector2& v1, T s); + + /** + * Componentwise addition of Vector with floating point. + * + * @param(v1) Vector to add to + * @param(s Floating point to add + * + * @return Result Vector + */ + + template + TVector2 operator+ (const TVector2& v1, const TVector2& v2); + + /** + * Componentwise substraction of Vector with floating point. + * + * @param(v1) Vector to substract from + * @param(s Floating point to substract + * + * @return Result Vector + */ + + template + TVector2 operator- (const TVector2& v1, T s); + + /** + * Componentwise substraction of Vector with Vector. + * + * @param(v1) Vector to substract from + * @param(s Floating point to substract + * + * @return Result Vector + */ + + template + TVector2 operator- (const TVector2& v1, const TVector2& v2); + + /** + * Negate Vector. + * + * @param(v1) Vector to negate + */ + + template + void operator- (TVector2& v1); + + + /** + * Compare Vector for equality. + * + * @see [FUNC]Equals + * + * @param(v1) Vector to negate + * + * @return true if equal, false if inequal + */ + + template + bool operator== (const TVector2& v1, const TVector2& v2); + + + /** + * Compare Vector for inequality. + * + * @see [FUNC]Equals + * + * @param(v1) Vector to negate + * + * @return true if inequal, false if equal + */ + + template + bool operator!= (const TVector2& v1, const TVector2& v2); + + + // ============================================ // + // TVector2 static function implementation // + // ============================================ // + + /** + * Magnitude of Vector + * + * @param(v1) Vector + * + * @return Size of Vector + */ + + template + T Magnitude(const TVector2& v1); + + /** + * @see [FUNC]Magnitude + */ + template + FORCEINLINE T Length(const TVector2& v1) { return Magnitude(v1); }; + + /** + * Square of magnitude of Vector + * + * @param(v1) Vector + * + * @return Magnitude without calculating square root + */ + + template + T SqrMagnitude(const TVector2& v1); + + /** + * @see [FUNC]SqrMagnitude + */ + template + FORCEINLINE T SqrLength(const TVector2& v1) { return SqrMagnitude(v1); }; + + /** + * Normalize Vector + * + * @param(v1) Vector + */ + + template + TVector2 NormalizeV(TVector2& v1); + + /** + * Normalize Vector + * + * @param(v1) Vector + * + * @note Does not look for zero vector. + */ + + template + TVector2 UnsafeNormalizeV(TVector2& v1); + + /** + * Angle between to Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + T Angle(const TVector2& v1, const TVector2& v2); + + /** + * Cosine of angle between to Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + T CosineAngle(const TVector2& v1, const TVector2& v2); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + */ + + template + TVector2 SignVectorV(TVector2& v1); + + /** + * Binds a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + */ + + template + TVector2 BindToSquareV(TVector2& v1, T radius); + + /** + * Clamps a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + */ + + template + TVector2 ClampToSquareV(TVector2& v1, T radius); + + /** + * Dot product of two Vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + */ + + template + T DotP(const TVector2& v1, const TVector2& v2); + + /** + * Creates Vector, with component wise largest values. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TVector2 MaxV (TVector2& v1, const TVector2& v2); + + /** + * Creates Vector, with component wise smallest values. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TVector2 MinV (TVector2& v1, const TVector2& v2); + + /** + * Gets perpendicular Vector to v1. + * + * @param(v1) Vector one + * + * @note Stores new Vector to v1 + */ + + template + TVector2 GetPerpendicularV (TVector2& v1); + + /** + * Gets perpendicular Vector to v1. + * + * @reg [FUNC]PerpendicularV + * + * @param(v1) Vector one + * + * @note Stores new Vector to v1 + */ + + template + TVector2 GetReversePerpendicularV (TVector2& v1); + + /** + * Component wise multiplication of Vector + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note Stores new Vector to v1 + */ + + template + TVector2 ScaleV(TVector2& v1, const TVector2& v2); + + /** + * Componentwise inverse of Vector + * + * @param(v1) Vector one + * + * @note Stores new Vector to v1 + */ + + template + TVector2 CompInverseV(TVector2& v1); + + /** + * Reflect Vector by normal vector. + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * + * @note Stores new Vector to v1 + */ + + template + TVector2 ReflectV (TVector2& v1, const TVector2& normal); + + /** + * Copies one Vector two another + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TVector2 Set(TVector2& v1, const TVector2& v2); + + /** + * Sets components of a vector. + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TVector2 Set(TVector2& v1, T x, T y); + + /** + * Anti-clockwise vector rotation. + * + * @param(v1) Vector to rotate + * + * @note Angle is not clamped + */ + + template + TVector2 RotateV(TVector2& v1, T angle); + + + /** + * Clockwise vector rotation. + * + * @param(v1) Vector to rotate + * + * @note Angle is not clamped + */ + + template + FORCEINLINE TVector2 ClockwiseRotateV(TVector2& v1, T angle); + + /** + * Negates Vector + * + * @param(v1) Vector one + */ + + template + TVector2 NegateV(TVector2& v1); + + /** + * Tests if vector is a unity vector. + * + * @param(v1) Vector one + * @param(threshold) Threshold to zero + * + * @return true if unit vector, false if not + */ + + template + inline bool IsNormalized(const TVector2& v1, T threshold = P_FLT_INAC); + + /** + * Tests if 2 vectors are perpendicular to each other. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Threshold to zero + * + * @return true if perpendicular, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsPerpendicular(const TVector2& v1, const TVector2& v2, T threshold = P_FLT_INAC); + + /** + * Tests if 2 vectors are parallel to each other. (Angle is close to zero.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(t) threshold Threshold from one (e.g. 0.98f) + * + * @return true if parallel, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsParallel(const TVector2& v1, const TVector2& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Tests if 2 vectors are coincident. (Are parallel and point in the same direction.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) from one (e.g. 0.98f) + * + * @return true if coincident, false if not + * + * @note Requires v1 and v2 to be normal vectors. + */ + + template + inline bool IsCoincident(const TVector2& v1, const TVector2& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Gets outer product of to vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Resulting matrix + */ + + // + //Matrix2 OuterProduct(const TVector2& v1, const TVector2& v2); + + + // ============================================================== // + // TVector2 static function implementation with return values // + // ============================================================== // + + + /** + * Reflects a vector on a normal + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * + * @return Reflected vector + */ + + template + TVector2 Reflect(const TVector2& v1, const TVector2& normal); + + /** + * Scales a vector component wise + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Reflected vector + */ + + template + TVector2 Scale(const TVector2& v1, const TVector2& v2); + + /** + * Componentwise inverse of a vector + * + * @param(v1) Vector one + * + * @return Componentwise inverted vector + */ + + template + TVector2 CompInverse(const TVector2& v1); + + + /** + * Negates Vector + * + * @param(v1) Vector one + * + * @return Componentwise inverted vector + */ + + template + TVector2 Negate(const TVector2& v1); + + /** + * Gets the perpendicular vector of v1 + * + * @param(v1) Vector one + * + * @return Perpendicular vector + */ + + template + TVector2 GetPerpendicular(const TVector2& v1); + + /** + * Gets reverse of the perpendicular vector of v1 + * + * @param(v1) Vector one + * + * @return Reversed perpendicular vector + */ + + template + TVector2 GetReversePerpendicular(const TVector2& v1); + + /** + * Creates a new Vector by the component wise minimals of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Minimal vector + */ + + template + TVector2 Min(const TVector2& v1, const TVector2& v2); + + /** + * Creates a new Vector by the component wise maxima of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Maximal vector + */ + + template + TVector2 Max(const TVector2& v1, const TVector2& v2); + + /** + * Creates a normalized instance of the vector + * + * @param(v1) Vector to normalize + * + * @return Unit vector + */ + + template + TVector2 Normalize(const TVector2& v1); + + /** + * Creates a normalized instance of the vector + * + * @param(v1) Vector to normalize + * + * @return Unit vector + * @note Does not test for zero vector + */ + + template + TVector2 UnsafeNormalize(const TVector2& v1); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + * + * @return Vector with signs as components + */ + + template + TVector2 SignVector(const TVector2& v1); + + /** + * Binds a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + * + * @return Bound vector + */ + + template + TVector2 BindToSquare(const TVector2& v1, T radius); + + /** + * Clamps a vector to a square with a radius + * + * @param(v1) Vector one + * @param(radius) Radius of square (=> Distance from middle to center of each site.) + * + * @return Clamped vector. If the length of the vector fits the square, then the vector is returned. + */ + + template + TVector2 ClampToSquare(const TVector2& v1, T radius); + + /** + * Interpolates between to vectors. + * + * @param(startVec) Start vector (t = 0) + * @param(destVec) Destination vector (t = 1) + * @param(t) Interpolation value + * + * @return Interpolated vector + * + * @note Interpolation is clamped between 0 - 1. + */ + + template + TVector2 Lerp(const TVector2& startVec, const TVector2& destVec, T t); + + /** + * Interpolates between to vectors. + * + * @param(startVec) Start vector (t = 0) + * @param(destVec) Destination vector (t = 1) + * @param(t) Interpolation value + * + * @return Interpolated vector + * + * @note Interpolation is not clamped. Make shure t is between 0.0f and 1.0f + */ + + template + TVector2 LerpUnclamped(const TVector2& startVec, const TVector2& destVec, T t); + + /** + * Anti-clockwise vector rotation. + * + * @param(v1) Vector to rotate + * @param(angle) Angle to rotate + * + * @return Rotated vector + * + * @note Angle is not clamped + */ + + template + TVector2 Rotate(const TVector2& v1, T angle); + + /** + * Clockwise vector rotation. + * + * @param(v1) Vector to rotate + * + * @return Rotated vector + * + * @note Angle is not clamped + */ + + template + TVector2 ClockwiseRotate(const TVector2& v1, T angle); } // phanes::core::math::coretypes diff --git a/Engine/src/Runtime/Core/public/Math/Vector3.h b/Engine/src/Runtime/Core/public/Math/Vector3.h index e9a390a..aea16e0 100644 --- a/Engine/src/Runtime/Core/public/Math/Vector3.h +++ b/Engine/src/Runtime/Core/public/Math/Vector3.h @@ -30,1160 +30,1160 @@ namespace Phanes::Core::Math { - // Basic 3D vector (x, y, z) + // Basic 3D vector (x, y, z) - template - struct TVector3 { - public: - - using Real = T; - - union - { - struct - { + template + struct TVector3 { + public: + + using Real = T; + + union + { + struct + { - /** X component of vector - * - * @ref [FIELD]components - * @note x does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real x; + /** X component of vector + * + * @ref [FIELD]components + * @note x does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. + */ + Real x; - /** Y component of vector - * - * @ref [FIELD]components - * - * @note y does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real y; + /** Y component of vector + * + * @ref [FIELD]components + * + * @note y does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. + */ + Real y; - /** Z component of vector - * - * @ref [FIELD]components - * - * @note Z does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. - */ - Real z; + /** Z component of vector + * + * @ref [FIELD]components + * + * @note Z does not hold the component, but is v1 reference two the second item in the components array. The varibale exists wholly for convenience. + */ + Real z; - }; + }; - /** Components array holding the data - * - * @ref [FIELD]x - * @ref [FIELD]y - * @ref [FIELD]z - * - * @note Components are split into x, y and z. Access and manipulation is possible by these variables. - */ + /** Components array holding the data + * + * @ref [FIELD]x + * @ref [FIELD]y + * @ref [FIELD]z + * + * @note Components are split into x, y and z. Access and manipulation is possible by these variables. + */ - Real comp[3]; - }; + Real comp[3]; + }; - public: - - /** - * Default contructor without initialization - */ - - TVector3() = default; - - - /** - * Copy contructor - */ - - TVector3(const TVector3& v); - - - /** - * Move contructor - */ - - TVector3(TVector3&& v); - - /** - * Convert other type of vector - */ - - template - explicit TVector3(const TVector3& v) : x((T)v.x), y((T)v.y) {}; - - - template - explicit TVector3(const TIntVector3& v) : x((T)v.x), y((T)v.y) {}; - - /** - * Construct vector from xy components. - * - * @param x X component - * @param y Y component - * @param z Z component - */ - - TVector3(const Real x, const Real y, const Real z); - - - /** - * Contructor vector from two component array - * - * @param comp Array of components - */ - - TVector3(const Real* comp); - - /** - * Constructs a vector pointing from start to end. - * - * @param(start) Startingpoint - * @param(end) Endpoint - */ - - TVector3(const TPoint3& start, const TPoint3& end); - - }; - - - - - // ====================== // - // TVector3 operators // - // ====================== // - - /** - * Coponentwise addition of floating point to 3D vector - * - * @param(v1) vector to add to - * @param(s) floating point to add - */ - - template - inline TVector3 operator+= (TVector3& v1, T s); - - /** - * Coponentwise addition of 3D vector to 3D vector - * - * @param(v1) vector to add to - * @param(v2) vector to add - */ - - template - inline TVector3 operator+= (TVector3& v1, const TVector3& v2); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(s) floating point to substract - */ - - template - inline TVector3 operator-= (TVector3& v1, T s); - - /** - * Coponentwise substraction of 3D vector to 3D vector - * - * @param(v1) vector to substract from - * @param(v2) vector to substract with - */ - - template - inline TVector3 operator-= (TVector3& v1, const TVector3& v2); - - /** - * Dot product between two 3D Vectors - * - * @param(v1) vector one - * @param(s) floating point - */ - - template - inline TVector3 operator*= (TVector3& v1, T s); - - /** - * Coponentwise division of 3D vector with floating point - * - * @param(v1) vector divide - * @param(s) floating point to divide with - */ - - template - inline TVector3 operator/= (TVector3& v1, T s); - - /** - * Coponentwise multiplication of 3D Vectors with floating point - * - * @param(v1) vector one - * @param(s) floating point - * - * @return Resulting vector - */ - - template - TVector3 operator* (const TVector3& v1, T s); - - /** - * Coponentwise division of 3D Vectors with floating point - * - * @param(v1) vector one - * @param(s) floating point - * - * @return Resulting vector - */ - - template - TVector3 operator/ (const TVector3& v1, T s); - - /** - * Coponentwise multiplication of 3D Vectors with floating point - * - * @param(s) floating point - * @param(v2) vector - * - * @return Resultion vector - */ - - template - inline TVector3 operator* (T s, const TVector3& v1); - - /** - * Coponentwise multiplication of 3D Vectors with floating point - * - * @param(s) floating point - * @param(v1) vector - * - * @return Resultion vector - */ - - template - inline TVector3 operator/ (T s, const TVector3& v1); - - /** - * Dot product between two 3D Vectors - * - * @param(v1) vector one - * @param(v2) vector two - * - * @return Dot product of Vectors - */ - - template - T operator* (const TVector3& v1, const TVector3& v2); - - /** - * Coponentwise addition of floating point to 3D vector - * - * @param(v1) vector to add to - * @param(s) floating point to add - * - * @return Resulting vector - */ - - template - TVector3 operator+ (const TVector3& v1, T s); - - /** - * Coponentwise addition of 3D vector to 3D vector - * - * @param(v1) vector to add to - * @param(v2) vector to add - * - * @return Resulting vector - */ - - template - TVector3 operator+ (const TVector3& v1, const TVector3& v2); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(s) floating point to substract - * - * @return Resulting vector - */ - - template - TVector3 operator- (const TVector3& v1, T s); - - /** - * Coponentwise substraction of floating point of 3D vector - * - * @param(v1) vector to substract from - * @param(v2) vector to substract with - * - * @return Resulting vector - */ - - template - TVector3 operator- (const TVector3& v1, const TVector3& v2); - - /** - * Negates vector - * - * @param(v1) Vector to negate - */ - - template - TVector3 operator- (TVector3& v1); - - /** - * Tests two 3D vectors for equality. - * - * @ref [FUNC]Equals - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return True if equal, false if not. - * - * @note Uses [MACRO]P_FLT_INAC - */ - - template - inline bool operator== (const TVector3& v1, const TVector3& v2); - - /** - * Tests two 3D vectors for inequality. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return True if inequal, false if not. - */ - - template - inline bool operator!= (const TVector3& v1, const TVector3& v2); - - - // ==================================== // - // TVector3 function implementation // - // ==================================== // - - /** - * Gets magnitude of vector - * - * @param(v1) Vector - * - * @return Magnitude of vector - */ - - template - inline T Magnitude(const TVector3& v1); - - /** - * @see [FUNC]Magnitude - */ - - template - FORCEINLINE T Length(const TVector3& v1) { return Magnitude(v1); }; - - /** - * Gets square magnitude of vector - * - * @param(v1) Vector - * - * @return Square magnitude of vector - */ - - template - inline T SqrMagnitude(const TVector3& v1); - - /** - * @see SqrMagnitude - */ - - template - FORCEINLINE T SqrLength(const TVector3& v1); - - /** - * Normalizes vector - * - * @param(v1) Vector - * - * @note Result is stored in v1 - */ - - template - TVector3 NormalizeV(TVector3& v1); - - /** - * Normalizes vector - * - * @param(v1) Vector - * - * @note Does not test for zero vector - */ - - template - TVector3 UnsafeNormalizeV(TVector3& v1); - - /** - * Reflects a vector on a surface - * - * @param(v1) Vector one - * @param(normal) Normal of surface - */ - - template - TVector3 ReflectV(TVector3& v1, const TVector3& normal); - - /** - * Gets angle between two vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Angle between vectors - */ - - template - T Angle(const TVector3& v1, const TVector3& v2); - - /** - * Dot product of two vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Dot product of vectors - */ - - template - T DotP(const TVector3& v1, const TVector3& v2); - - /** - * Orthogonalizes three vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector two - */ - - template - void Orthogonalize(TVector3& v1, TVector3& v2, TVector3& v3); - - /** - * Orthogonalizes three vectors and turns them into unit vectors. Usefull for making sure coordinate axis are still orthogonal. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector two - * - * @note Usefull for making sure coordinate axis are still orthogonal. - */ - - template - void OrthoNormalize(TVector3& v1, TVector3& v2, TVector3& v3); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - * - * @return Vector with signs a components. - */ - - template - TVector3 SignVector(const TVector3& v1); - - /** - * Tests two vectors for equality. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy. - * - * @return True if equal, false if not. - */ - - template - inline bool Equals(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC); - - /** - * Performs perspective divide on vector. - * - * @param(v1) Vector - */ - - template - TVector3 PerspectiveDivideV(TVector3& v1); - - /** - * Calculates the cross product between two vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TVector3 CrossPV(TVector3& v1, const TVector3& v2); - - /** - * Gets the componentwise max of both vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TVector3 MaxV(TVector3& v1, const TVector3& v2); - - /** - * Gets the componentwise min of both vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TVector3 MinV(TVector3& v1, const TVector3& v2); - - /** - * Gets reversed vector. - * - * @param(v1) Vector one - * - * @note result is stored in v1. - */ - - template - TVector3 NegateV(TVector3& v1); - - /** - * Performes componentwise multiplication of two vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @note result is stored in v1. - */ - - template - TVector3 ScaleV(TVector3& v1, const TVector3& v2); - - /** - * Projects vector v1 onto v2 - * - * @param(v1) Vector to project - * @param(v2) Vector to project on - * - * @note result is stored in v1. - */ - - template - TVector3 ProjectV(TVector3& v1, const TVector3& v2); - - /** - * Rejects vector v1 from v2 - * - * @param(v1) Vector to reject - * @param(v2) Vector to reject from - * - * @note result is stored in v1. - */ - - template - TVector3 RejectV(TVector3& v1, const TVector3& v2); - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(normal) Normal of the plane - * - * @note result is stored in v1. - * @note Simply rejects v1 from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlaneV(TVector3& v1, const TVector3& normal); - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(normal) Plane - * - * @note result is stored in v1. - * @note Simply rejects v1 from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlaneV(TVector3& v1, const TPlane& plane); - - /** - * Copies v1 vector - * - * @param(v1) Vector to copy to - * @param(v2) Vector to copy - */ - - template - TVector3 Set(TVector3& v1, const TVector3& v2); - - /** - * Sets vector. - * - * @param(v1) Vector to copy to - * @param(x) X component - * @param(y) Y component - * @param(z) Z component - */ - - template - TVector3 Set(TVector3& v1, T x, T y, T z); - - /** - * Clamps vector to a range of magnitudes. - * - * @param(v1) Vector to clamp - * @param(min) Min magnitude - * @param(max) Max magnitude - * - * @note Result is stored in v1 - */ - - template - TVector3 ClampMagnitudeV(TVector3& v1, T min, T max); - - /** - * Inverts the components of vector. - * - * @param(v1) Vector - * - * @note Result is stored in v1 - */ - - template - TVector3 CompInverseV(TVector3& v1); - - /** - * Binds vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @note result is stored in v1. - */ - - template - TVector3 BoundToCubeV(TVector3 v1, T cubeRadius) {}; - - /** - * Clamps vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @note result is stored in v1. - */ - - template - TVector3 ClampToCubeV(TVector3 v1, T cubeRadius) {}; - - /** - * Reflect by plane - * - * @param(v1) Vector to mirror - * @param(plane) Plane to mirror on - * - * @note result is stored in v1. - */ - - template - FORCEINLINE TVector3 ReflectFromPlaneV(TVector3& v1, const TPlane& plane); - - /** - * Reflect by plane - * - * @param(v1) Vector to mirror - * @param(plane) Plane to mirror on - * - * @note result is stored in v1. - */ - - template - FORCEINLINE TVector3 ReflectFromPlaneV(TVector3& v1, const TVector3& normal); - - /** - * Rotates vector around axis - * - * @param(v1) Vector to mirror - * @param(axisNormal) Axis to rotate around. - * - * @note result is stored in v1. - */ - - template - TVector3 RotateAroundAxisV(TVector3& v1, const TVector3& axisNormal, T angle); - - /** - * Scales vector two specific magnitude. - * - * @param(v1) Vector - * - * @note It's faster to use operator* or operator*= for naturaly normalized vectors. - */ - - template - TVector3 ScaleToMagnitudeV(TVector3& v1, T magnitude); - - /** - * Returns signs of components in vector: -1 / +1 / 0. - * - * @param(v1) Vector one - */ - - template - TVector3 SignVectorV(TVector3& v1); - - - /** - * Gets scalar triple product ((v1 x v2) * v3). (Volume of parallelepiped.) - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @return Vector triple product - */ - - template - T ScalarTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3); - - /** - * Gets the cosine of the angle between to vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Cosine of angle between vectors. - * @note Simply omits acos of angle. - */ - - template - T CosineAngle(const TVector3& v1, const TVector3& v2); - - /** - * Gets vector triple product ((v1 x v2) x v3). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @note result is stored in v1 - */ - - template - TVector3 VectorTripleV(TVector3& v1, const TVector3& v2, const TVector3& v3); - - /** - * Tests whether two vectors are perpendicular. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy - * - * @return True if perpendicular, false if not. - */ - - template - inline bool IsPerpendicular(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC); - - /** - * Tests whether two vectors are parallel. - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) - * - * @return True if parallel, false if not. - */ - - template - inline bool IsParallel(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Tests whether two vectors are coincident (Parallel and point in same direction). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) - * - * @return True if coincident, false if not. - */ - - template - inline bool IsCoincident(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC); - - /** - * Tests whether v1 vectors is v1 unit vector. - * - * @param(v1) Vector - * @param(threshold) Allowed T inaccuracy - * - * @return True if unit vector, false if not. - */ - - template - inline bool IsNormalized(const TVector3& v1, T threshold = P_FLT_INAC); - - /** - * Tests if three vectors are coplanar - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * @param(threshold) Allowed T inaccuracy - * - * @return True if coplanar, false if not. - */ - - template - inline bool IsCoplanar(const TVector3& v1, const TVector3& v2, const TVector3& v3, T threshold = P_FLT_INAC); - - /** - * Gets outer product of to vectors. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Resulting matrix - */ - - // - //Matrix3 OuterProduct(const TVector3& v1, const TVector3& v2); - - // ============ // - // WITH RETURN: // - // ============ // - - /** - * Normalized vector - * - * @param(v1) vector to normalize - * - * @return Normalized vector - */ - - template - TVector3 Normalize(const TVector3& v1); - - /** - * Normalizes vector - * - * @param(v1) Vector - * - * @note Does not test for zero vector - */ - - template - TVector3 UnsafeNormalize(const TVector3& v1); - - /** - * Reflects a vector on a surface - * - * @param(v1) Vector one - * @param(normal) Normal of surface - * - * @return Reflected vector - */ - - template - TVector3 Reflect(const TVector3& v1, const TVector3& normal); - - - /** - * Performes perspective divide on vector. - * - * @param(v1) vector to perspective divide - * - * @return Perspective divided vector - */ - - template - TVector3 PerspectiveDivide(const TVector3& v1); - - /** - * Gets cross product between two vectors. - * - * @param(v1) vector one - * @param(v2) vector two - * - * @return Cross product of v1 and v2 - */ - - template - TVector3 CrossP(const TVector3& v1, const TVector3& v2); - - /** - * Linearly interpolates between two vectors. - * - * @param(start) Starting vector - * @param(dest) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Cross product of v1 and v2 - */ - - template - TVector3 Lerp(const TVector3& start, const TVector3& dest, T t); - - /** - * Linearly interpolates between two vectors. - * - * @param(v1) Starting vector - * @param(dest) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Cross product of v1 and v2 - * @note Does not clamp t between 0.0 and 1.0. - */ - - template - TVector3 LerpUnclamped(const TVector3& start, const TVector3& dest, T t); - - /** - * Creates a new Vector by the componentwise max of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector of componentwise max - */ - - template - TVector3 Max(const TVector3& v1, const TVector3& v2); - - /** - * Creates a new Vector by the componentwise min of both vectors - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector of componentwise min - */ - - template - TVector3 Min(const TVector3& v1, const TVector3& v2); - - /** - * Gets reversed vector. - * - * @param(v1) Vector one - * - * @note result is stored in v1. - */ - - template - TVector3 Negate(const TVector3& v1); - - /** - * Multiplies vector componentwise. - * - * @param(v1) Vector one - * @param(v2) Vector two - * - * @return Vector with componentwise products - */ - - template - TVector3 Scale(const TVector3& v1, const TVector3& v2); - - /** - * Clamps vector to a range of magnitudes. - * - * @param(v1) Vector to clamp - * @param(min) Min magnitude - * @param(max) Max magnitude - * - * @return Clamped vector - */ - - template - TVector3 ClampMagnitude(const TVector3& v1, T min, T max); - - /** - * Binds vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @result Vector clamped in cube. - */ - - template - TVector3 BoundToCube(const TVector3& v1, T cubeRadius) {}; - - /** - * Clamps vector into cube. - * - * @param(v1) Vector to clamp - * @param(cubeRadius) Radius of the cube - * - * @result Vector clamped in cube. - */ - - template - TVector3 ClampToCube(const TVector3& v1, T cubeRadius) {}; - - /** - * Scales vector two specific magnitude. - * - * @param(v1) Vector - * - * @note It's faster to use operator* or operator*= for naturaly normalized vectors. - */ - - template - TVector3 ScaleToMagnitude(const TVector3& v1, T magnitude); - - /** - * Clamps vector into cube. - * - * @param(v1) Vector - * - * @result Vector with inverted components. - */ - - template - TVector3 CompInverse(const TVector3& v1); - - - /** - * Reflect from plane - * - * @param(v1) Vector to mirror - * @param(plane) Plane to mirror on - * - * @return Reflected vector - */ - - template - FORCEINLINE TVector3 ReflectFromPlane(const TVector3& v1, const TPlane& plane); - - /** - * Reflect from plane - * - * @param(v1) Vector to mirror - * @param(plane) Normal of plane - * - * @return Reflected vector - */ - - template - FORCEINLINE TVector3 ReflectFromPlane(const TVector3& v1, const TVector3& normal); - - /** - * Rotates vector around axis - * - * @param(v1) Vector to mirror - * @param(axisNormal) Axis to rotate around - * - * @return Rotated vector - * @note Calculates vector rotation with Rodrigues-Rotation - */ - - template - TVector3 RotateAroundAxis(const TVector3& v1, const TVector3& axisNormal, T angle); - - /** - * Gets vector triple product ((v1 x v2) x v3). - * - * @param(v1) Vector one - * @param(v2) Vector two - * @param(v3) Vector three - * - * @return Vector triple product - */ - - template - TVector3 VectorTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3); - - /** - * Projects vector v1 onto v2 - * - * @param(v1) Vector to project - * @param(v2) Vector to project on - * - * @return Projected vector - */ - - template - TVector3 Project(const TVector3& v1, const TVector3& v2); - - /** - * Rejects vector v1 from v2 - * - * @param(v1) Vector to reject - * @param(v2) Vector to reject from - * - * @return Rejected vector - */ - - template - TVector3 Reject(const TVector3& v1, const TVector3& v2); - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(normal) Normal of the plane - * - * @return Projected vector - * @note Simply rejects the vector from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlane(const TVector3& v1, const TVector3& normal); - - - /** - * Projects vector onto plane - * - * @param(v1) Vector to reject - * @param(plane) Plane - * - * @return Projected vector - * @note Simply rejects the vector from normal - */ - - template - FORCEINLINE TVector3 ProjectOntoPlane(const TVector3& v1, const TPlane& plane); - - /** - * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. - * - * @param(v1) Starting vector - * @param(v2) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Interpolated unit vector - */ - - template - TVector3 Slerp(const TVector3& v1, const TVector3& v2, T t) {}; - - /** - * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. - * - * @param(v1) Starting vector - * @param(v2) Destination vector - * @param(t) 0.0 to 1.0 interpolation value - * - * @return Interpolated unit vector. - * @note Does not clamp s between 0.0 and 1.0. - */ - - template - TVector3 SlerpUnclamped(const TVector3& v1, const TVector3& v2, T t) {}; + public: + + /** + * Default contructor without initialization + */ + + TVector3() = default; + + + /** + * Copy contructor + */ + + TVector3(const TVector3& v); + + + /** + * Move contructor + */ + + TVector3(TVector3&& v); + + /** + * Convert other type of vector + */ + + template + explicit TVector3(const TVector3& v) : x((T)v.x), y((T)v.y) {}; + + + template + explicit TVector3(const TIntVector3& v) : x((T)v.x), y((T)v.y) {}; + + /** + * Construct vector from xy components. + * + * @param x X component + * @param y Y component + * @param z Z component + */ + + TVector3(const Real x, const Real y, const Real z); + + + /** + * Contructor vector from two component array + * + * @param comp Array of components + */ + + TVector3(const Real* comp); + + /** + * Constructs a vector pointing from start to end. + * + * @param(start) Startingpoint + * @param(end) Endpoint + */ + + TVector3(const TPoint3& start, const TPoint3& end); + + }; + + + + + // ====================== // + // TVector3 operators // + // ====================== // + + /** + * Coponentwise addition of floating point to 3D vector + * + * @param(v1) vector to add to + * @param(s) floating point to add + */ + + template + inline TVector3 operator+= (TVector3& v1, T s); + + /** + * Coponentwise addition of 3D vector to 3D vector + * + * @param(v1) vector to add to + * @param(v2) vector to add + */ + + template + inline TVector3 operator+= (TVector3& v1, const TVector3& v2); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(s) floating point to substract + */ + + template + inline TVector3 operator-= (TVector3& v1, T s); + + /** + * Coponentwise substraction of 3D vector to 3D vector + * + * @param(v1) vector to substract from + * @param(v2) vector to substract with + */ + + template + inline TVector3 operator-= (TVector3& v1, const TVector3& v2); + + /** + * Dot product between two 3D Vectors + * + * @param(v1) vector one + * @param(s) floating point + */ + + template + inline TVector3 operator*= (TVector3& v1, T s); + + /** + * Coponentwise division of 3D vector with floating point + * + * @param(v1) vector divide + * @param(s) floating point to divide with + */ + + template + inline TVector3 operator/= (TVector3& v1, T s); + + /** + * Coponentwise multiplication of 3D Vectors with floating point + * + * @param(v1) vector one + * @param(s) floating point + * + * @return Resulting vector + */ + + template + TVector3 operator* (const TVector3& v1, T s); + + /** + * Coponentwise division of 3D Vectors with floating point + * + * @param(v1) vector one + * @param(s) floating point + * + * @return Resulting vector + */ + + template + TVector3 operator/ (const TVector3& v1, T s); + + /** + * Coponentwise multiplication of 3D Vectors with floating point + * + * @param(s) floating point + * @param(v2) vector + * + * @return Resultion vector + */ + + template + inline TVector3 operator* (T s, const TVector3& v1); + + /** + * Coponentwise multiplication of 3D Vectors with floating point + * + * @param(s) floating point + * @param(v1) vector + * + * @return Resultion vector + */ + + template + inline TVector3 operator/ (T s, const TVector3& v1); + + /** + * Dot product between two 3D Vectors + * + * @param(v1) vector one + * @param(v2) vector two + * + * @return Dot product of Vectors + */ + + template + T operator* (const TVector3& v1, const TVector3& v2); + + /** + * Coponentwise addition of floating point to 3D vector + * + * @param(v1) vector to add to + * @param(s) floating point to add + * + * @return Resulting vector + */ + + template + TVector3 operator+ (const TVector3& v1, T s); + + /** + * Coponentwise addition of 3D vector to 3D vector + * + * @param(v1) vector to add to + * @param(v2) vector to add + * + * @return Resulting vector + */ + + template + TVector3 operator+ (const TVector3& v1, const TVector3& v2); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(s) floating point to substract + * + * @return Resulting vector + */ + + template + TVector3 operator- (const TVector3& v1, T s); + + /** + * Coponentwise substraction of floating point of 3D vector + * + * @param(v1) vector to substract from + * @param(v2) vector to substract with + * + * @return Resulting vector + */ + + template + TVector3 operator- (const TVector3& v1, const TVector3& v2); + + /** + * Negates vector + * + * @param(v1) Vector to negate + */ + + template + TVector3 operator- (TVector3& v1); + + /** + * Tests two 3D vectors for equality. + * + * @ref [FUNC]Equals + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return True if equal, false if not. + * + * @note Uses [MACRO]P_FLT_INAC + */ + + template + inline bool operator== (const TVector3& v1, const TVector3& v2); + + /** + * Tests two 3D vectors for inequality. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return True if inequal, false if not. + */ + + template + inline bool operator!= (const TVector3& v1, const TVector3& v2); + + + // ==================================== // + // TVector3 function implementation // + // ==================================== // + + /** + * Gets magnitude of vector + * + * @param(v1) Vector + * + * @return Magnitude of vector + */ + + template + inline T Magnitude(const TVector3& v1); + + /** + * @see [FUNC]Magnitude + */ + + template + FORCEINLINE T Length(const TVector3& v1) { return Magnitude(v1); }; + + /** + * Gets square magnitude of vector + * + * @param(v1) Vector + * + * @return Square magnitude of vector + */ + + template + inline T SqrMagnitude(const TVector3& v1); + + /** + * @see SqrMagnitude + */ + + template + FORCEINLINE T SqrLength(const TVector3& v1); + + /** + * Normalizes vector + * + * @param(v1) Vector + * + * @note Result is stored in v1 + */ + + template + TVector3 NormalizeV(TVector3& v1); + + /** + * Normalizes vector + * + * @param(v1) Vector + * + * @note Does not test for zero vector + */ + + template + TVector3 UnsafeNormalizeV(TVector3& v1); + + /** + * Reflects a vector on a surface + * + * @param(v1) Vector one + * @param(normal) Normal of surface + */ + + template + TVector3 ReflectV(TVector3& v1, const TVector3& normal); + + /** + * Gets angle between two vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Angle between vectors + */ + + template + T Angle(const TVector3& v1, const TVector3& v2); + + /** + * Dot product of two vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Dot product of vectors + */ + + template + T DotP(const TVector3& v1, const TVector3& v2); + + /** + * Orthogonalizes three vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector two + */ + + template + void Orthogonalize(TVector3& v1, TVector3& v2, TVector3& v3); + + /** + * Orthogonalizes three vectors and turns them into unit vectors. Usefull for making sure coordinate axis are still orthogonal. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector two + * + * @note Usefull for making sure coordinate axis are still orthogonal. + */ + + template + void OrthoNormalize(TVector3& v1, TVector3& v2, TVector3& v3); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + * + * @return Vector with signs a components. + */ + + template + TVector3 SignVector(const TVector3& v1); + + /** + * Tests two vectors for equality. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy. + * + * @return True if equal, false if not. + */ + + template + inline bool Equals(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC); + + /** + * Performs perspective divide on vector. + * + * @param(v1) Vector + */ + + template + TVector3 PerspectiveDivideV(TVector3& v1); + + /** + * Calculates the cross product between two vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TVector3 CrossPV(TVector3& v1, const TVector3& v2); + + /** + * Gets the componentwise max of both vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TVector3 MaxV(TVector3& v1, const TVector3& v2); + + /** + * Gets the componentwise min of both vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TVector3 MinV(TVector3& v1, const TVector3& v2); + + /** + * Gets reversed vector. + * + * @param(v1) Vector one + * + * @note result is stored in v1. + */ + + template + TVector3 NegateV(TVector3& v1); + + /** + * Performes componentwise multiplication of two vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @note result is stored in v1. + */ + + template + TVector3 ScaleV(TVector3& v1, const TVector3& v2); + + /** + * Projects vector v1 onto v2 + * + * @param(v1) Vector to project + * @param(v2) Vector to project on + * + * @note result is stored in v1. + */ + + template + TVector3 ProjectV(TVector3& v1, const TVector3& v2); + + /** + * Rejects vector v1 from v2 + * + * @param(v1) Vector to reject + * @param(v2) Vector to reject from + * + * @note result is stored in v1. + */ + + template + TVector3 RejectV(TVector3& v1, const TVector3& v2); + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(normal) Normal of the plane + * + * @note result is stored in v1. + * @note Simply rejects v1 from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlaneV(TVector3& v1, const TVector3& normal); + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(normal) Plane + * + * @note result is stored in v1. + * @note Simply rejects v1 from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlaneV(TVector3& v1, const TPlane& plane); + + /** + * Copies v1 vector + * + * @param(v1) Vector to copy to + * @param(v2) Vector to copy + */ + + template + TVector3 Set(TVector3& v1, const TVector3& v2); + + /** + * Sets vector. + * + * @param(v1) Vector to copy to + * @param(x) X component + * @param(y) Y component + * @param(z) Z component + */ + + template + TVector3 Set(TVector3& v1, T x, T y, T z); + + /** + * Clamps vector to a range of magnitudes. + * + * @param(v1) Vector to clamp + * @param(min) Min magnitude + * @param(max) Max magnitude + * + * @note Result is stored in v1 + */ + + template + TVector3 ClampMagnitudeV(TVector3& v1, T min, T max); + + /** + * Inverts the components of vector. + * + * @param(v1) Vector + * + * @note Result is stored in v1 + */ + + template + TVector3 CompInverseV(TVector3& v1); + + /** + * Binds vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @note result is stored in v1. + */ + + template + TVector3 BoundToCubeV(TVector3 v1, T cubeRadius) {}; + + /** + * Clamps vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @note result is stored in v1. + */ + + template + TVector3 ClampToCubeV(TVector3 v1, T cubeRadius) {}; + + /** + * Reflect by plane + * + * @param(v1) Vector to mirror + * @param(plane) Plane to mirror on + * + * @note result is stored in v1. + */ + + template + FORCEINLINE TVector3 ReflectFromPlaneV(TVector3& v1, const TPlane& plane); + + /** + * Reflect by plane + * + * @param(v1) Vector to mirror + * @param(plane) Plane to mirror on + * + * @note result is stored in v1. + */ + + template + FORCEINLINE TVector3 ReflectFromPlaneV(TVector3& v1, const TVector3& normal); + + /** + * Rotates vector around axis + * + * @param(v1) Vector to mirror + * @param(axisNormal) Axis to rotate around. + * + * @note result is stored in v1. + */ + + template + TVector3 RotateAroundAxisV(TVector3& v1, const TVector3& axisNormal, T angle); + + /** + * Scales vector two specific magnitude. + * + * @param(v1) Vector + * + * @note It's faster to use operator* or operator*= for naturaly normalized vectors. + */ + + template + TVector3 ScaleToMagnitudeV(TVector3& v1, T magnitude); + + /** + * Returns signs of components in vector: -1 / +1 / 0. + * + * @param(v1) Vector one + */ + + template + TVector3 SignVectorV(TVector3& v1); + + + /** + * Gets scalar triple product ((v1 x v2) * v3). (Volume of parallelepiped.) + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @return Vector triple product + */ + + template + T ScalarTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3); + + /** + * Gets the cosine of the angle between to vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Cosine of angle between vectors. + * @note Simply omits acos of angle. + */ + + template + T CosineAngle(const TVector3& v1, const TVector3& v2); + + /** + * Gets vector triple product ((v1 x v2) x v3). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @note result is stored in v1 + */ + + template + TVector3 VectorTripleV(TVector3& v1, const TVector3& v2, const TVector3& v3); + + /** + * Tests whether two vectors are perpendicular. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy + * + * @return True if perpendicular, false if not. + */ + + template + inline bool IsPerpendicular(const TVector3& v1, const TVector3& v2, T threshold = P_FLT_INAC); + + /** + * Tests whether two vectors are parallel. + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) + * + * @return True if parallel, false if not. + */ + + template + inline bool IsParallel(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Tests whether two vectors are coincident (Parallel and point in same direction). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(threshold) Allowed T inaccuracy from one (e.g. 0.98f) + * + * @return True if coincident, false if not. + */ + + template + inline bool IsCoincident(const TVector3& v1, const TVector3& v2, T threshold = 1.0f - P_FLT_INAC); + + /** + * Tests whether v1 vectors is v1 unit vector. + * + * @param(v1) Vector + * @param(threshold) Allowed T inaccuracy + * + * @return True if unit vector, false if not. + */ + + template + inline bool IsNormalized(const TVector3& v1, T threshold = P_FLT_INAC); + + /** + * Tests if three vectors are coplanar + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * @param(threshold) Allowed T inaccuracy + * + * @return True if coplanar, false if not. + */ + + template + inline bool IsCoplanar(const TVector3& v1, const TVector3& v2, const TVector3& v3, T threshold = P_FLT_INAC); + + /** + * Gets outer product of to vectors. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Resulting matrix + */ + + // + //Matrix3 OuterProduct(const TVector3& v1, const TVector3& v2); + + // ============ // + // WITH RETURN: // + // ============ // + + /** + * Normalized vector + * + * @param(v1) vector to normalize + * + * @return Normalized vector + */ + + template + TVector3 Normalize(const TVector3& v1); + + /** + * Normalizes vector + * + * @param(v1) Vector + * + * @note Does not test for zero vector + */ + + template + TVector3 UnsafeNormalize(const TVector3& v1); + + /** + * Reflects a vector on a surface + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * + * @return Reflected vector + */ + + template + TVector3 Reflect(const TVector3& v1, const TVector3& normal); + + + /** + * Performes perspective divide on vector. + * + * @param(v1) vector to perspective divide + * + * @return Perspective divided vector + */ + + template + TVector3 PerspectiveDivide(const TVector3& v1); + + /** + * Gets cross product between two vectors. + * + * @param(v1) vector one + * @param(v2) vector two + * + * @return Cross product of v1 and v2 + */ + + template + TVector3 CrossP(const TVector3& v1, const TVector3& v2); + + /** + * Linearly interpolates between two vectors. + * + * @param(start) Starting vector + * @param(dest) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Cross product of v1 and v2 + */ + + template + TVector3 Lerp(const TVector3& start, const TVector3& dest, T t); + + /** + * Linearly interpolates between two vectors. + * + * @param(v1) Starting vector + * @param(dest) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Cross product of v1 and v2 + * @note Does not clamp t between 0.0 and 1.0. + */ + + template + TVector3 LerpUnclamped(const TVector3& start, const TVector3& dest, T t); + + /** + * Creates a new Vector by the componentwise max of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector of componentwise max + */ + + template + TVector3 Max(const TVector3& v1, const TVector3& v2); + + /** + * Creates a new Vector by the componentwise min of both vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector of componentwise min + */ + + template + TVector3 Min(const TVector3& v1, const TVector3& v2); + + /** + * Gets reversed vector. + * + * @param(v1) Vector one + * + * @note result is stored in v1. + */ + + template + TVector3 Negate(const TVector3& v1); + + /** + * Multiplies vector componentwise. + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Vector with componentwise products + */ + + template + TVector3 Scale(const TVector3& v1, const TVector3& v2); + + /** + * Clamps vector to a range of magnitudes. + * + * @param(v1) Vector to clamp + * @param(min) Min magnitude + * @param(max) Max magnitude + * + * @return Clamped vector + */ + + template + TVector3 ClampMagnitude(const TVector3& v1, T min, T max); + + /** + * Binds vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @result Vector clamped in cube. + */ + + template + TVector3 BoundToCube(const TVector3& v1, T cubeRadius) {}; + + /** + * Clamps vector into cube. + * + * @param(v1) Vector to clamp + * @param(cubeRadius) Radius of the cube + * + * @result Vector clamped in cube. + */ + + template + TVector3 ClampToCube(const TVector3& v1, T cubeRadius) {}; + + /** + * Scales vector two specific magnitude. + * + * @param(v1) Vector + * + * @note It's faster to use operator* or operator*= for naturaly normalized vectors. + */ + + template + TVector3 ScaleToMagnitude(const TVector3& v1, T magnitude); + + /** + * Clamps vector into cube. + * + * @param(v1) Vector + * + * @result Vector with inverted components. + */ + + template + TVector3 CompInverse(const TVector3& v1); + + + /** + * Reflect from plane + * + * @param(v1) Vector to mirror + * @param(plane) Plane to mirror on + * + * @return Reflected vector + */ + + template + FORCEINLINE TVector3 ReflectFromPlane(const TVector3& v1, const TPlane& plane); + + /** + * Reflect from plane + * + * @param(v1) Vector to mirror + * @param(plane) Normal of plane + * + * @return Reflected vector + */ + + template + FORCEINLINE TVector3 ReflectFromPlane(const TVector3& v1, const TVector3& normal); + + /** + * Rotates vector around axis + * + * @param(v1) Vector to mirror + * @param(axisNormal) Axis to rotate around + * + * @return Rotated vector + * @note Calculates vector rotation with Rodrigues-Rotation + */ + + template + TVector3 RotateAroundAxis(const TVector3& v1, const TVector3& axisNormal, T angle); + + /** + * Gets vector triple product ((v1 x v2) x v3). + * + * @param(v1) Vector one + * @param(v2) Vector two + * @param(v3) Vector three + * + * @return Vector triple product + */ + + template + TVector3 VectorTriple(const TVector3& v1, const TVector3& v2, const TVector3& v3); + + /** + * Projects vector v1 onto v2 + * + * @param(v1) Vector to project + * @param(v2) Vector to project on + * + * @return Projected vector + */ + + template + TVector3 Project(const TVector3& v1, const TVector3& v2); + + /** + * Rejects vector v1 from v2 + * + * @param(v1) Vector to reject + * @param(v2) Vector to reject from + * + * @return Rejected vector + */ + + template + TVector3 Reject(const TVector3& v1, const TVector3& v2); + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(normal) Normal of the plane + * + * @return Projected vector + * @note Simply rejects the vector from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlane(const TVector3& v1, const TVector3& normal); + + + /** + * Projects vector onto plane + * + * @param(v1) Vector to reject + * @param(plane) Plane + * + * @return Projected vector + * @note Simply rejects the vector from normal + */ + + template + FORCEINLINE TVector3 ProjectOntoPlane(const TVector3& v1, const TPlane& plane); + + /** + * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. + * + * @param(v1) Starting vector + * @param(v2) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Interpolated unit vector + */ + + template + TVector3 Slerp(const TVector3& v1, const TVector3& v2, T t) {}; + + /** + * Interpolate vector v1 to desitnation v2 using v1 constant s. The magnitude of the vector stays the same throughout the interpolation. + * + * @param(v1) Starting vector + * @param(v2) Destination vector + * @param(t) 0.0 to 1.0 interpolation value + * + * @return Interpolated unit vector. + * @note Does not clamp s between 0.0 and 1.0. + */ + + template + TVector3 SlerpUnclamped(const TVector3& v1, const TVector3& v2, T t) {}; } // phanes diff --git a/Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h b/Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h index df8a620..73eb5cd 100644 --- a/Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h +++ b/Engine/src/Runtime/Core/public/OSAL/PlatformTypes.h @@ -14,9 +14,9 @@ namespace Phanes::Core::Types #ifdef P_WIN_BUILD - // MSCV++ specific types + // MSCV++ specific types - typedef FLOAT128 float128; + typedef FLOAT128 float128; //#elif P_UNIX_BUILD // @@ -27,86 +27,86 @@ namespace Phanes::Core::Types #endif - // Specific types size - // - // 8-Bit integer - typedef int8_t int8; + // Specific types size + // + // 8-Bit integer + typedef int8_t int8; - // 16-Bit integer - typedef int16_t int16; + // 16-Bit integer + typedef int16_t int16; - // 32-Bit integer - typedef int32_t int32; + // 32-Bit integer + typedef int32_t int32; - // 64-Bit integer - typedef int64_t int64; + // 64-Bit integer + typedef int64_t int64; - // 8-Bit unsigned integer - typedef uint8_t uint8; + // 8-Bit unsigned integer + typedef uint8_t uint8; - // 16-Bit unsigned integer - typedef uint16_t uint16; + // 16-Bit unsigned integer + typedef uint16_t uint16; - // 32-Bit unsigned integer - typedef uint32_t uint32; + // 32-Bit unsigned integer + typedef uint32_t uint32; - // 64-Bit unsigned integer - typedef uint64_t uint64; + // 64-Bit unsigned integer + typedef uint64_t uint64; - // At least N bit types - // - // At least 8-Bit integer - typedef int_least8_t lint8; + // At least N bit types + // + // At least 8-Bit integer + typedef int_least8_t lint8; - // At least 16-Bit integer - typedef int_least16_t lint16; + // At least 16-Bit integer + typedef int_least16_t lint16; - // At least 32-Bit integer - typedef int_least32_t lint32; + // At least 32-Bit integer + typedef int_least32_t lint32; - // At least 64-Bit integer - typedef int_least64_t lint64; + // At least 64-Bit integer + typedef int_least64_t lint64; - // At least 8-Bit integer - typedef uint_least8_t ulint8; + // At least 8-Bit integer + typedef uint_least8_t ulint8; - // At least 16-Bit integer - typedef uint_least16_t ulint16; + // At least 16-Bit integer + typedef uint_least16_t ulint16; - // At least 32-Bit integer - typedef uint_least32_t ulint32; + // At least 32-Bit integer + typedef uint_least32_t ulint32; - // At least 64-Bit integer - typedef uint_least64_t ulint64; + // At least 64-Bit integer + typedef uint_least64_t ulint64; - // Fast N bit types - // - // Fast 8-bit integer - typedef int_fast8_t fint8; + // Fast N bit types + // + // Fast 8-bit integer + typedef int_fast8_t fint8; - // At least 16-Bit integer - typedef int_fast16_t fint16; + // At least 16-Bit integer + typedef int_fast16_t fint16; - // At least 32-Bit integer - typedef int_fast32_t fint32; + // At least 32-Bit integer + typedef int_fast32_t fint32; - // At least 64-Bit integer - typedef int_fast64_t fint64; + // At least 64-Bit integer + typedef int_fast64_t fint64; - // At least 8-Bit integer - typedef uint_fast8_t ufint8; + // At least 8-Bit integer + typedef uint_fast8_t ufint8; - // At least 16-Bit integer - typedef uint_fast16_t ufint16; + // At least 16-Bit integer + typedef uint_fast16_t ufint16; - // At least 32-Bit integer - typedef uint_fast32_t ufint32; + // At least 32-Bit integer + typedef uint_fast32_t ufint32; - // At least 64-Bit integer - typedef uint_fast64_t ufint64; + // At least 64-Bit integer + typedef uint_fast64_t ufint64; } \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/StartingPoint/EntryPoint.h b/Engine/src/Runtime/Core/public/StartingPoint/EntryPoint.h index f927b6c..7671fd0 100644 --- a/Engine/src/Runtime/Core/public/StartingPoint/EntryPoint.h +++ b/Engine/src/Runtime/Core/public/StartingPoint/EntryPoint.h @@ -7,11 +7,11 @@ extern Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreateP int main(int argc, char** argv) { - auto phanes_game = Phanes::Core::Application::CreatePhanesGame(); + auto phanes_game = Phanes::Core::Application::CreatePhanesGame(); - phanes_game->Run(); + phanes_game->Run(); - delete phanes_game; + delete phanes_game; } #endif \ No newline at end of file diff --git a/Engine/src/Runtime/Core/public/StartingPoint/StartingPoint.h b/Engine/src/Runtime/Core/public/StartingPoint/StartingPoint.h index 6ff97b5..034f9ef 100644 --- a/Engine/src/Runtime/Core/public/StartingPoint/StartingPoint.h +++ b/Engine/src/Runtime/Core/public/StartingPoint/StartingPoint.h @@ -6,26 +6,26 @@ namespace Phanes::Core::Application { - class PhanesGame - { + class PhanesGame + { - public: + public: - PhanesGame(); - virtual ~PhanesGame(); + PhanesGame(); + virtual ~PhanesGame(); - /** - * PhanesEngine main loop. - */ - void Run(); + /** + * PhanesEngine main loop. + */ + void Run(); - }; + }; - /** - * Function to be overwriten by client. - */ + /** + * Function to be overwriten by client. + */ - PhanesGame* CreatePhanesGame(); + PhanesGame* CreatePhanesGame(); } \ No newline at end of file diff --git a/Engine/src/Runtime/PhanesEnginePCH.h b/Engine/src/Runtime/PhanesEnginePCH.h index f597e32..7df62fb 100644 --- a/Engine/src/Runtime/PhanesEnginePCH.h +++ b/Engine/src/Runtime/PhanesEnginePCH.h @@ -6,22 +6,22 @@ #define NOMAXMIN #ifndef PHANES_CORE_PCH_H - + - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #ifdef P_WIN_BUILD + #ifdef P_WIN_BUILD - #include + #include - #endif + #endif #endif // !PHANES_CORE_PCH_H diff --git a/Samples/DevPlayground/DevPlayground.cpp b/Samples/DevPlayground/DevPlayground.cpp index ca9a737..a1ca5c1 100644 --- a/Samples/DevPlayground/DevPlayground.cpp +++ b/Samples/DevPlayground/DevPlayground.cpp @@ -7,5 +7,5 @@ class DevPlayground : public Phanes::Core::Application::PhanesGame {}; Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreatePhanesGame() { - return new DevPlayground(); + return new DevPlayground(); } \ No newline at end of file diff --git a/Tests/TestProject/Main.cpp b/Tests/TestProject/Main.cpp index b2e79f7..9f86376 100644 --- a/Tests/TestProject/Main.cpp +++ b/Tests/TestProject/Main.cpp @@ -4,9 +4,9 @@ namespace PMath = Phanes::Core::Math; int main() { - float t = 2; - PMath::Clamp(t, 2.0f, 4.0f); + float t = 2; + PMath::Clamp(t, 2.0f, 4.0f); - return 0; + return 0; } \ No newline at end of file