From 5b13eeec40bfdb4d5d55359215db2cb6889ef1cd Mon Sep 17 00:00:00 2001 From: scorpioblood <77296181+scorpioblood@users.noreply.github.com> Date: Sat, 18 May 2024 23:56:46 +0200 Subject: [PATCH] Exclude private/Math from push. --- .gitignore | 7 +- .../Runtime/Core/private/Math/IntVector3.cpp | 514 ------------------ .../Core/private/Math/MathUnitConversion.cpp | 60 -- 3 files changed, 2 insertions(+), 579 deletions(-) delete mode 100644 Engine/src/Runtime/Core/private/Math/IntVector3.cpp delete mode 100644 Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp diff --git a/.gitignore b/.gitignore index a7ee7c2..f07e379 100644 --- a/.gitignore +++ b/.gitignore @@ -7,13 +7,10 @@ external/ # Temporary excludes -Matrix2d.cpp -Matrix3.cpp -Matrix4.cpp -Vector4.cpp +Core/private/Math/ -Matrix3.h Matrix4.h +IntVector4.h Vector4.h ############################################################################################ diff --git a/Engine/src/Runtime/Core/private/Math/IntVector3.cpp b/Engine/src/Runtime/Core/private/Math/IntVector3.cpp deleted file mode 100644 index 4e8d81f..0000000 --- a/Engine/src/Runtime/Core/private/Math/IntVector3.cpp +++ /dev/null @@ -1,514 +0,0 @@ -// ============================== // -// TIntVector2 implementation // -// ============================== // - - -#include "PhanesEnginePCH.h" - -#include "Core/public/Math/IntVector3.h" - -#include "Core/public/Math/IntPoint.h" -#include "Core/public/Math/Plane.h" - - -template -inline Phanes::Core::Math::TIntVector3::TIntVector3(const T x, const T y, const T z) -{ - this->x = x; - this->y = y; - this->z = z; -} - -template -Phanes::Core::Math::TIntVector3::TIntVector3(const T* comp) -{ - static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector3.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::TIntVector3::TIntVector3(const TIntVector2& v) -{ - this->x = v.x; - this->y = v.y; - this->z = (T)0; -} - -template -Phanes::Core::Math::TIntVector3::TIntVector3(const TIntPoint3& start, const TIntPoint3& end) -{ - this->x = end.x - start.x; - this->y = end.y - start.y; - this->z = end.z - start.z; -} - -template -Phanes::Core::Math::TIntVector3::TIntVector3(const TIntVector3& v) -{ - memcpy(this->comp, comp, sizeof(T) * 3); -} - -template -Phanes::Core::Math::TIntVector3::TIntVector3(TIntVector3&& v) -{ - this->comp = v.comp; - v.comp = nullptr; -} - -// ========================= // -// TIntVector3 operators // -// ========================= // - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator+=(TIntVector3& v1, T s) -{ - v1.x += s; - v1.y += s; - v1.z += s; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator+=(TIntVector3& v1, const TIntVector3& v2) -{ - v1.x += v2.x; - v1.y += v2.y; - v1.z += v2.z; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator-=(TIntVector3& v1, T s) -{ - v1.x -= s; - v1.y -= s; - v1.z -= s; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator-=(TIntVector3& v1, const TIntVector3& v2) -{ - v1.x -= v2.x; - v1.y -= v2.y; - v1.z -= v2.z; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator*=(TIntVector3& v1, T s) -{ - v1.x *= s; - v1.y *= s; - v1.z *= s; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator*(const TIntVector3& v1, T s) -{ - return TIntVector3(v1.x * s.v1.y * s, v1.z * s); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator*(T s, const TIntVector3& v1) -{ - return v1 * s; -} - -template -T Phanes::Core::Math::operator*(const TIntVector3& v1, const TIntVector3& v2) -{ - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator+(const TIntVector3& v1, T s) -{ - return TIntVector3(v1.x + s.v1.y + s, v1.z + s); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator+(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator-(const TIntVector3& v1, T s) -{ - return TIntVector3(v1.x - s.v1.y - s, v1.z - s); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator-(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::operator-(TIntVector3& v1) -{ - v1.x = -v1.x; - v1.y = -v1.y; - v1.z = -v1.z; - - return v1; -} - -template -bool Phanes::Core::Math::operator==(const TIntVector3& v1, const TIntVector3& 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); -} - -template -bool Phanes::Core::Math::operator!=(const TIntVector3& v1, const TIntVector3& 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); -} - -// ======================================= // -// TIntVector3 function implementation // -// ======================================= // - -template -Rt Phanes::Core::Math::Magnitude(const TIntVector3& v1) -{ - return sqrt(DotP(v1, v1)); -} - -template -T Phanes::Core::Math::SqrMagnitude(const TIntVector3& v1) -{ - return DotP(v1, v1); -} - -template -Rt Phanes::Core::Math::Angle(const TIntVector3& v1, const TIntVector3& v2) -{ - return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2))); -} - -template -T Phanes::Core::Math::DotP(const TIntVector3& v1, const TIntVector3& v2) -{ - return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::VectorTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3) -{ - return CrossP(CrossP(v1, v2), v3); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::SignVector(const TIntVector3& 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); - - - return v1; -} - -template -bool Phanes::Core::Math::Equals(const TIntVector3& v1, const TIntVector3& v2, T threshold) -{ - return (abs(v1.x - v2.x) < threshold && abs(v1.y - v2.y) < threshold && abs(v1.z - v2.z) < threshold); -} - - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::CrossPV(TIntVector3& v1, const TIntVector3& v2) -{ - 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); - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::MaxV(TIntVector3& v1, const TIntVector3& v2) -{ - v1.x = Max(v1.x, v2.x); - v1.y = Max(v1.y, v2.y); - v1.z = Max(v1.z, v2.z); - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::MinV(TIntVector3& v1, const TIntVector3& v2) -{ - v1.x = Min(v1.x, v2.x); - v1.y = Min(v1.y, v2.y); - v1.z = Min(v1.z, v2.z); - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::NegateV(TIntVector3& v1) -{ - v1.x = -v1.x; - v1.y = -v1.y; - v1.z = -v1.z; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::ScaleV(TIntVector3& v1, const TIntVector3& v2) -{ - v1.x *= v2.x; - v1.y *= v2.y; - v1.z *= v2.z; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::Set(TIntVector3& v1, const TIntVector3& v2) -{ - v1 = v2; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::Set(TIntVector3& v1, T x, T y, T z) -{ - v1.x = x; - v1.y = y; - v1.z = z; - - return v1; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::SignVectorV(TIntVector3& v1) -{ - v1.x = (v1.x > 0) ? 1 : 0; - v1.y = (v1.y > 0) ? 1 : 0; - v1.z = (v1.z > 0) ? 1 : 0; - - return v1; -} - -template -T Phanes::Core::Math::ScalarTriple(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3) -{ - return CrossP(v1, v2) * v3; -} - -template -T Phanes::Core::Math::CosineAngle(const TIntVector3& v1, const TIntVector3& v2) -{ - return (v1 * v2) / (Magnitude(v1) * Magnitude(v2)); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::VectorTripleV(TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3) -{ - CrossPV(CrossPV(v1, v2), v3); - - return v1; -} - -template -bool Phanes::Core::Math::IsPerpendicular(const TIntVector3& v1, const TIntVector3& v2, T threshold) -{ - return (abs(DotP(v1, v2)) < threshold); -} - -template -bool Phanes::Core::Math::IsParallel(const TIntVector3& v1, const TIntVector3& v2, T threshold) -{ - return (abs(DotP(v1, v2)) > threshold); -} - -template -bool Phanes::Core::Math::IsCoincident(const TIntVector3& v1, const TIntVector3& v2, T threshold) -{ - return (DotP(v1, v2) > threshold); -} - -template -bool Phanes::Core::Math::IsNormalized(const TIntVector3& v1, T threshold) -{ - return (SqrMagnitude(v1) < threshold); -} - -template -bool Phanes::Core::Math::IsCoplanar(const TIntVector3& v1, const TIntVector3& v2, const TIntVector3& v3, T threshold) -{ - return (ScalarTriple(v1, v2, v3) < threshold); -} - - - -// =============== // -// With Return // -// =============== // - - - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::Normalize(const TIntVector3& v1) -{ - float vecNorm = Magnitude(v1); - return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm; -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::UnsafeNormalize(const TIntVector3& v1) -{ - return v1 / Magnitude(v1); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::Reflect(const TIntVector3& v1, const TVector3& normal) -{ - return v1 - (2 * (v1 * normal) * normal); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::PerspectiveDivide(const TIntVector3& v1) -{ - float _z = (T)1.0 / v1.z; - return TIntVector3(v1.x * _z, v1.y * _z, (T)0.0); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::CrossP(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3((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 TIntVector3& start, const TIntVector3& dest, Rt t) -{ - t = Clamp(t, (Rt)0.0, (Rt), 1.0); - return ((Rt)1.0 - t) * start + t * dest; -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::LerpUnclamped(const TIntVector3& start, const TIntVector3& dest, Rt t) -{ - return (1 - t) * start + t * dest; -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::Max(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3((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::TIntVector3 Phanes::Core::Math::Min(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3((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::TIntVector3 Phanes::Core::Math::Negate(const TIntVector3& v1) -{ - return TIntVector3(-v1.x, -v1.y, -v1.z); -} - -template -Phanes::Core::Math::TIntVector3 Phanes::Core::Math::Scale(const TIntVector3& v1, const TIntVector3& v2) -{ - return TIntVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ClampMagnitude(const TIntVector3& v1, T min, T max) -{ - Rt magnitude = Magnitude(v1); - - const TVector3 unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); - - Clamp(magnitude, min, max); - - return unitVec * magnitude; -} - - - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ScaleToMagnitude(const TIntVector3& v1, T magnitude) -{ - NormalizeV(v1) *= magnitude; - - return v1; -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::CompInverse(const TIntVector3& v1) -{ - return TIntVector3((Rt)1.0 / v1.x, (Rt)1.0 / v1.y, (Rt)1.0 / v1.z); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlane(const TIntVector3& v1, const TPlane& plane) -{ - return Reflect(v1, plane.normal); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ReflectFromPlane(const TIntVector3& v1, const TVector3& normal) -{ - return Reflect(v1, normal); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::RotateAroundAxis(const TIntVector3& v1, const TVector3& axisNormal, Rt angle) -{ - T sinAngle = sin(angle); - T cosAngle = cos(angle); - - return ((Rt)1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::Project(const TIntVector3& v1, const TIntVector3& v2) -{ - return (DotP(v1, v2) / DotP(v2, v2)) * v2; -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::Reject(const TIntVector3& v1, const TIntVector3& v2) -{ - return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2; -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlane(const TIntVector3& v1, const TVector3& normal) -{ - return Reject(v1, normal); -} - -template -Phanes::Core::Math::TVector3 Phanes::Core::Math::ProjectOntoPlane(const TIntVector3& v1, const TPlane& plane) -{ - return Reject(v1, plane.normal); -} \ No newline at end of file diff --git a/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp b/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp deleted file mode 100644 index 81f6b32..0000000 --- a/Engine/src/Runtime/Core/private/Math/MathUnitConversion.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "PhanesEnginePCH.h" - -#include "Core/public/Math/MathUnitConversion.h" - - -template -inline T Phanes::Core::Math::UnitConversion::DegToRad(T deg) -{ - return deg * P_PI_180_FLT; -} - -template -inline T Phanes::Core::Math::UnitConversion::RadToDeg(T rad) -{ - return rad * P_180_PI_FLT; -} - -template -inline T Phanes::Core::Math::UnitConversion::DegToGradian(T deg) -{ - return deg * 1.111111f; -} - -template -inline T Phanes::Core::Math::UnitConversion::GradianToDeg(T g) -{ - return g * 0.9f; -} - -template -inline T Phanes::Core::Math::UnitConversion::RadToGradian(T rad) -{ - return rad * 200 / P_PI_FLT; -} - -template -inline T Phanes::Core::Math::UnitConversion::GradianToRad(T g) -{ - return g * P_PI_FLT / 200; -} - - - -// Unit Literals - -double Phanes::Core::Math::UnitLiterals::operator""_deg(long double _x) -{ - return _x * P_PI_180_FLT; -} - -double Phanes::Core::Math::UnitLiterals::operator""_rad(long double _x) -{ - return _x; -} - -double Phanes::Core::Math::UnitLiterals::operator""_g(long double _x) -{ - return _x * P_PI_FLT / 200; -} -