Change tab to 2 spaces.

This commit is contained in:
scorpioblood 2024-05-13 23:11:29 +02:00
parent dee63c38e2
commit 3e58f65d28
30 changed files with 4853 additions and 4852 deletions

View File

@ -3,28 +3,28 @@
#ifdef P_WIN_BUILD #ifdef P_WIN_BUILD
#ifdef P_DEBUG #ifdef P_DEBUG
#define P_DEBUGBREAK DebugBreak(); #define P_DEBUGBREAK DebugBreak();
#else #else
#define P_DEBUGBREAK #define P_DEBUGBREAK
#endif // P_DEBUG #endif // P_DEBUG
#define FORCEINLINE __forceinline #define FORCEINLINE __forceinline
#elif defined(P_UNIX_BUILD) #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) #elif defined(P_ARM_BUILD)
#error Only Windows is supported at the moment. #error Only Windows is supported at the moment.
#else #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 #endif // P_WIN_BUILD

View File

@ -9,7 +9,7 @@
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2) Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2)
{ {
return Magnitude(p2 - p1); return Magnitude(p2 - p1);
} }
// ----- TIntPoint3 ------------------------------------------ // ----- TIntPoint3 ------------------------------------------
@ -18,5 +18,5 @@ Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2) Rt Phanes::Core::Math::Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2)
{ {
return Magnitude(p2 - p1); return Magnitude(p2 - p1);
} }

View File

@ -25,42 +25,42 @@
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T x, const T y) Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T x, const T y)
{ {
this->x = x; this->x = x;
this->y = y; this->y = y;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T* comp) Phanes::Core::Math::TIntVector2<T>::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."); 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); memcpy(this->comp, comp, sizeof(T) * 2);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntPoint2<T>& start, const TIntPoint2<T>& end) Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntPoint2<T>& start, const TIntPoint2<T>& end)
{ {
this->x = end.x - start.x; this->x = end.x - start.x;
this->y = end.y - start.y; this->y = end.y - start.y;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector3<T>& v) Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector3<T>& v)
{ {
this->x = v.x; this->x = v.x;
this->y = v.y; this->y = v.y;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector2<T>& v) Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector2<T>& v)
{ {
memcpy(this->comp, comp, sizeof(T) * 2); memcpy(this->comp, comp, sizeof(T) * 2);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v) Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v)
{ {
this->comp = v.comp; this->comp = v.comp;
v.comp = nullptr; v.comp = nullptr;
} }
@ -71,254 +71,254 @@ Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v)
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, T s)
{ {
v1.x += s; v1.x += s;
v1.y += s; v1.y += s;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1.x += v2.x; v1.x += v2.x;
v1.y += v2.y; v1.y += v2.y;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, T s)
{ {
v1.x -= s; v1.x -= s;
v1.y -= s; v1.y -= s;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1.x -= v2.x; v1.x -= v2.x;
v1.y -= v2.y; v1.y -= v2.y;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*=(TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*=(TIntVector2<T>& v1, T s)
{ {
v1.x *= s; v1.x *= s;
v1.y *= s; v1.y *= s;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(const TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(const TIntVector2<T>& v1, T s)
{ {
return TIntVector2<T>(v1.x * s, v1.y * s); return TIntVector2<T>(v1.x * s, v1.y * s);
} }
template<IntType T> template<IntType T>
inline Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(T s, const TIntVector2<T>& v1) inline Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*(T s, const TIntVector2<T>& v1)
{ {
return v1 * s; return v1 * s;
} }
template<IntType T, IntType Rt> template<IntType T, IntType Rt>
Rt Phanes::Core::Math::operator* (const TIntVector2<T>& v1, const TIntVector2<T>& v2) Rt Phanes::Core::Math::operator* (const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return v1.x * v2.x + v1.y * v2.y; return v1.x * v2.x + v1.y * v2.y;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, T s)
{ {
return TIntVector2<T>(v1.x + s, v1.y + s); return TIntVector2<T>(v1.x + s, v1.y + s);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return TIntVector2<T>(v1.x + v2.x, v1.y + v2.y); return TIntVector2<T>(v1.x + v2.x, v1.y + v2.y);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, T s)
{ {
return TIntVector2<T>(v1.x - s, v1.y - s); return TIntVector2<T>(v1.x - s, v1.y - s);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return TIntVector2<T>(v1.x - v2.x, v1.y - v2.y); return TIntVector2<T>(v1.x - v2.x, v1.y - v2.y);
} }
template<IntType T> template<IntType T>
void Phanes::Core::Math::operator-(TIntVector2<T>& v1) void Phanes::Core::Math::operator-(TIntVector2<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
} }
template<IntType T> template<IntType T>
bool Phanes::Core::Math::operator== (const TIntVector2<T>& v1, const TIntVector2<T>& v2) bool Phanes::Core::Math::operator== (const TIntVector2<T>& v1, const TIntVector2<T>& 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<IntType T> template<IntType T>
bool Phanes::Core::Math::operator!=(const TIntVector2<T>& v1, const TIntVector2<T>& v2) bool Phanes::Core::Math::operator!=(const TIntVector2<T>& v1, const TIntVector2<T>& 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<IntType T, IntType Rt> template<IntType T, IntType Rt>
Rt Phanes::Core::Math::Magnitude(const TIntVector2<T>& v1) Rt Phanes::Core::Math::Magnitude(const TIntVector2<T>& v1)
{ {
return sqrtf(v1.x * v1.x + v1.y * v1.y); return sqrtf(v1.x * v1.x + v1.y * v1.y);
} }
template<IntType T> template<IntType T>
T Phanes::Core::Math::SqrMagnitude(const TIntVector2<T>& v1) T Phanes::Core::Math::SqrMagnitude(const TIntVector2<T>& v1)
{ {
return v1.x * v1.x + v1.y * v1.y; return v1.x * v1.x + v1.y * v1.y;
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTruncV(TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTruncV(TIntVector2<T>& v1, T s)
{ {
Rt _s = (Rt)1.0 / s; Rt _s = (Rt)1.0 / s;
v1.x = trunc(v1.x * s); v1.x = trunc(v1.x * s);
v1.y = trunc(v1.y * s); v1.y = trunc(v1.y * s);
return v1; return v1;
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Angle(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Rt Phanes::Core::Math::Angle(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2));
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Phanes::Core::Math::CosineAngle(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Rt Phanes::Core::Math::CosineAngle(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return (v1 * v2) / Magnitude(v1) * Magnitude(v2); return (v1 * v2) / Magnitude(v1) * Magnitude(v2);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVectorV(TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVectorV(TIntVector2<T>& v1)
{ {
v1.x = (v1.x > 0) ? 1 : -1; v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1; v1.y = (v1.y > 0) ? 1 : -1;
return v1; return v1;
} }
template<IntType T> template<IntType T>
T Phanes::Core::Math::DotP(const TIntVector2<T>& v1, const TIntVector2<T>& v2) T Phanes::Core::Math::DotP(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return v1.x * v2.x + v1.y * v2.y; return v1.x * v2.x + v1.y * v2.y;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MaxV(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MaxV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1.x = Phanes::Core::Math::Max(v1.x, v2.x); v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
v1.y = Phanes::Core::Math::Max(v1.y, v2.y); v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MinV(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::MinV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1.x = Phanes::Core::Math::Min(v1.x, v2.x); v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
v1.y = Phanes::Core::Math::Min(v1.y, v2.y); v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicularV(TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicularV(TIntVector2<T>& v1)
{ {
T x = v1.x; T x = v1.x;
v1.x = v1.y; v1.x = v1.y;
v1.y = -v1.x; v1.y = -v1.x;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TIntVector2<T>& v1)
{ {
T x = v1.x; T x = v1.x;
v1.x = -v1.y; v1.x = -v1.y;
v1.y = v1.x; v1.y = v1.x;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::ScaleV(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::ScaleV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1.x *= v2.x; v1.x *= v2.x;
v1.y *= v2.y; v1.y *= v2.y;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
v1 = v2; v1 = v2;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, T x, T y) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, T x, T y)
{ {
v1.x = x; v1.x = x;
v1.y = y; v1.y = y;
return v1; return v1;
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::NegateV(TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::NegateV(TIntVector2<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
} }
template<IntType T> template<IntType T>
inline bool Phanes::Core::Math::IsNormalized(const TIntVector2<T>& v1) inline bool Phanes::Core::Math::IsNormalized(const TIntVector2<T>& v1)
{ {
return (SqrMagnitude(v1)); return (SqrMagnitude(v1));
} }
template<IntType T> template<IntType T>
inline bool Phanes::Core::Math::IsPerpendicular(const TIntVector2<T>& v1, const TIntVector2<T>& v2) inline bool Phanes::Core::Math::IsPerpendicular(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return (abs(DotP(v1, v2)) = 0); return (abs(DotP(v1, v2)) = 0);
} }
template<IntType T> template<IntType T>
inline bool Phanes::Core::Math::IsParallel(const TIntVector2<T>& v1, const TIntVector2<T>& v2) inline bool Phanes::Core::Math::IsParallel(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return (abs(DotP(v1, v2)) = 1); return (abs(DotP(v1, v2)) = 1);
} }
template<IntType T> template<IntType T>
inline bool Phanes::Core::Math::IsCoincident(const TIntVector2<T>& v1, const TIntVector2<T>& v2) inline bool Phanes::Core::Math::IsCoincident(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return (DotP(v1, v2) > 1); return (DotP(v1, v2) > 1);
} }
// //
@ -337,125 +337,125 @@ inline bool Phanes::Core::Math::IsCoincident(const TIntVector2<T>& v1, const TIn
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Reflect(const TIntVector2<T>& v1, const TVector2<Rt>& normal) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Reflect(const TIntVector2<T>& v1, const TVector2<Rt>& normal)
{ {
return TVector2<Rt>(v1 - (2 * (v1 * normal) * normal)); return TVector2<Rt>(v1 - (2 * (v1 * normal) * normal));
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Scale(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Scale(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return TIntVector2<T>(v1.x * v2.x, v1.y * v2.y); return TIntVector2<T>(v1.x * v2.x, v1.y * v2.y);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::CompInverse(const TIntVector2<T>& v1) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::CompInverse(const TIntVector2<T>& v1)
{ {
return TVector2<T>(1.0f / v1.x, 1.0f / v1.y); return TVector2<T>(1.0f / v1.x, 1.0f / v1.y);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Negate(const TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Negate(const TIntVector2<T>& v1)
{ {
return TIntVector2<T>(-v1.x, -v1.y); return TIntVector2<T>(-v1.x, -v1.y);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicular(const TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicular(const TIntVector2<T>& v1)
{ {
return TIntVector2<T>(v1.y, -v1.x); return TIntVector2<T>(v1.y, -v1.x);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TIntVector2<T>& v1)
{ {
return TIntVector2<T>(-v1.y, v1.x); return TIntVector2<T>(-v1.y, v1.x);
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Min(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Min(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return TIntVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); return TIntVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y));
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Max(const TIntVector2<T>& v1, const TIntVector2<T>& v2) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Max(const TIntVector2<T>& v1, const TIntVector2<T>& v2)
{ {
return TIntVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); return TIntVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y));
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Normalize(const TIntVector2<T>& v1) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Normalize(const TIntVector2<T>& v1)
{ {
float vecNorm = Magnitude(v1); float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm); return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::UnsafeNormalize(const TIntVector2<T>& v1) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::UnsafeNormalize(const TIntVector2<T>& v1)
{ {
return TVector2(v1 / Magnitude(v1)); return TVector2(v1 / Magnitude(v1));
} }
template<IntType T> template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVector(const TIntVector2<T>& v1) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVector(const TIntVector2<T>& v1)
{ {
return TIntVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); return TIntVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::BindToSquare(const TIntVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::BindToSquare(const TIntVector2<T>& v1, T radius)
{ {
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
return v1 * k; return v1 * k;
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClampToSquare(const TIntVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClampToSquare(const TIntVector2<T>& v1, T radius)
{ {
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f; float k = (prime > radius) ? abs(radius / prime) : 1.0f;
return TVector2(v1 * k); return TVector2(v1 * k);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Lerp(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Lerp(const TIntVector2<T>& startVec, const TIntVector2<T>& 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<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::LerpUnclamped(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::LerpUnclamped(const TIntVector2<T>& startVec, const TIntVector2<T>& destVec, Rt t)
{ {
return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec); return ((Rt)t * destVec) + (((Rt)1.0 - t) * startVec);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Rotate(const TIntVector2<T>& v1, Rt angle) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Rotate(const TIntVector2<T>& v1, Rt angle)
{ {
float sinAngle = sin(angle); float sinAngle = sin(angle);
float cosAngle = cos(angle); float cosAngle = cos(angle);
return TVector2<Rt>((Rt)v1.x * cosAngle - (Rt)v1.y * sinAngle, (Rt)v1.y * cosAngle + (Rt)v1.x * sinAngle); return TVector2<Rt>((Rt)v1.x * cosAngle - (Rt)v1.y * sinAngle, (Rt)v1.y * cosAngle + (Rt)v1.x * sinAngle);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClockwiseRotate(const TIntVector2<T>& v1, Rt angle) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::ClockwiseRotate(const TIntVector2<T>& v1, Rt angle)
{ {
return Rotate(v1, -angle); return Rotate(v1, -angle);
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTrunc(const TIntVector2<T>& v1, T s) Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTrunc(const TIntVector2<T>& v1, T s)
{ {
Rt _s = (Rt)1.0 / s; Rt _s = (Rt)1.0 / s;
return TIntVector2<T>(trunc(v1.x * _s), trunc(v1.y * _s)); return TIntVector2<T>(trunc(v1.x * _s), trunc(v1.y * _s));
} }
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::DivideFloat(const TIntVector2<T>& v1, T s) Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::DivideFloat(const TIntVector2<T>& v1, T s)
{ {
Rt _s = (Rt)1.0 / s; Rt _s = (Rt)1.0 / s;
return TIntVector2<T>((Rt)v1.x * _s, (Rt)v1.y * _s); return TIntVector2<T>((Rt)v1.x * _s, (Rt)v1.y * _s);
} }

View File

@ -177,8 +177,6 @@ bool Phanes::Core::Math::operator!=(const TIntVector3<T>& v1, const TIntVector3<
// TIntVector3 function implementation // // TIntVector3 function implementation //
// ======================================= // // ======================================= //
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Magnitude(const TIntVector3<T>& v1) Rt Phanes::Core::Math::Magnitude(const TIntVector3<T>& v1)
{ {

View File

@ -7,26 +7,26 @@
template<RealType T> template<RealType T>
std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector2<T>& v) { std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector2<T>& v) {
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")";
} }
template<IntType T> template<IntType T>
std::string Phanes::Core::Math::ToString(const TIntVector2<T>& v) std::string Phanes::Core::Math::ToString(const TIntVector2<T>& v)
{ {
return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")"; return "(" + std::to_string(v.x) + ", " + std::to_string(v.y) + ")";
} }
template<RealType T> template<RealType T>
std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector3<T>& v) { std::string Phanes::Core::Math::ToString(const Phanes::Core::Math::TVector3<T>& 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<IntType T> template<IntType T>
std::string Phanes::Core::Math::ToString(const TIntVector3<T>& v) std::string Phanes::Core::Math::ToString(const TIntVector3<T>& 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<typename T> //template<typename T>

View File

@ -2,6 +2,7 @@
#include "Core/public/Math/MathUnitConversion.h" #include "Core/public/Math/MathUnitConversion.h"
template<RealType T> template<RealType T>
inline T Phanes::Core::Math::UnitConversion::DegToRad(T deg) inline T Phanes::Core::Math::UnitConversion::DegToRad(T deg)
{ {

View File

@ -12,7 +12,7 @@
template<RealType T> template<RealType T>
T Phanes::Core::Math::Distance(const TPoint2<T>& p1, const TPoint2<T>& p2) T Phanes::Core::Math::Distance(const TPoint2<T>& p1, const TPoint2<T>& p2)
{ {
return Magnitude(p2 - p1); return Magnitude(p2 - p1);
} }
@ -21,7 +21,7 @@ T Phanes::Core::Math::Distance(const TPoint2<T>& p1, const TPoint2<T>& p2)
template<RealType T> template<RealType T>
T Phanes::Core::Math::Distance(const TPoint3<T>& p1, const TPoint3<T>& p2) T Phanes::Core::Math::Distance(const TPoint3<T>& p1, const TPoint3<T>& p2)
{ {
return Magnitude(p2 - p1); return Magnitude(p2 - p1);
} }

View File

@ -25,42 +25,42 @@
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const Real x, const Real y) Phanes::Core::Math::TVector2<T>::TVector2(const Real x, const Real y)
{ {
this->x = x; this->x = x;
this->y = y; this->y = y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const Real* comp) Phanes::Core::Math::TVector2<T>::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."); 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); memcpy(this->comp, comp, sizeof(T) * 2);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const TPoint2<Real>& start, const TPoint2<Real>& end) Phanes::Core::Math::TVector2<T>::TVector2(const TPoint2<Real>& start, const TPoint2<Real>& end)
{ {
this->x = end.x - start.x; this->x = end.x - start.x;
this->y = end.y - start.y; this->y = end.y - start.y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const TVector3<Real>& v) Phanes::Core::Math::TVector2<T>::TVector2(const TVector3<Real>& v)
{ {
this->x = v.x; this->x = v.x;
this->y = v.y; this->y = v.y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const TVector2<Real>& v) Phanes::Core::Math::TVector2<T>::TVector2(const TVector2<Real>& v)
{ {
memcpy(this->comp, comp, sizeof(T) * 2); memcpy(this->comp, comp, sizeof(T) * 2);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v) Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v)
{ {
this->comp = v.comp; this->comp = v.comp;
v.comp = nullptr; v.comp = nullptr;
} }
@ -107,340 +107,340 @@ Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v)
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, T s)
{ {
v1.x += s; v1.x += s;
v1.y += s; v1.y += s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1.x += v2.x; v1.x += v2.x;
v1.y += v2.y; v1.y += v2.y;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, T s)
{ {
v1.x -= s; v1.x -= s;
v1.y -= s; v1.y -= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1.x -= v2.x; v1.x -= v2.x;
v1.y -= v2.y; v1.y -= v2.y;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*=(TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*=(TVector2<T>& v1, T s)
{ {
v1.x *= s; v1.x *= s;
v1.y *= s; v1.y *= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/=(TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/=(TVector2<T>& v1, T s)
{ {
s = 1.0f / s; s = 1.0f / s;
v1.x *= s; v1.x *= s;
v1.y *= s; v1.y *= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(const TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(const TVector2<T>& v1, T s)
{ {
return TVector2<T>(v1.x * s, v1.y * s); return TVector2<T>(v1.x * s, v1.y * s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(const TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(const TVector2<T>& v1, T s)
{ {
s = 1.0f / s; s = 1.0f / s;
return TVector2<T>(v1.x * s, v1.y * s); return TVector2<T>(v1.x * s, v1.y * s);
} }
template<RealType T> template<RealType T>
inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(T s, const TVector2<T>& v1) inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*(T s, const TVector2<T>& v1)
{ {
return v1 * s; return v1 * s;
} }
template<RealType T> template<RealType T>
inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(T s, const TVector2<T>& v1) inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(T s, const TVector2<T>& v1)
{ {
s = 1.0f / s; s = 1.0f / s;
return v1 * s; return v1 * s;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::operator* (const TVector2<T>& v1, const TVector2<T>& v2) T Phanes::Core::Math::operator* (const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return v1.x * v2.x + v1.y * v2.y; return v1.x * v2.x + v1.y * v2.y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, T s)
{ {
return TVector2<T>(v1.x + s, v1.y + s); return TVector2<T>(v1.x + s, v1.y + s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return TVector2<T>(v1.x + v2.x, v1.y + v2.y); return TVector2<T>(v1.x + v2.x, v1.y + v2.y);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, T s) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, T s)
{ {
return TVector2<T>(v1.x - s, v1.y - s); return TVector2<T>(v1.x - s, v1.y - s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return TVector2<T>(v1.x - v2.x, v1.y - v2.y); return TVector2<T>(v1.x - v2.x, v1.y - v2.y);
} }
template<RealType T> template<RealType T>
void Phanes::Core::Math::operator-(TVector2<T>& v1) void Phanes::Core::Math::operator-(TVector2<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::operator== (const TVector2<T>& v1, const TVector2<T>& v2) bool Phanes::Core::Math::operator== (const TVector2<T>& v1, const TVector2<T>& 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<RealType T> template<RealType T>
bool Phanes::Core::Math::operator!=(const TVector2<T>& v1, const TVector2<T>& v2) bool Phanes::Core::Math::operator!=(const TVector2<T>& v1, const TVector2<T>& 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<RealType T> template<RealType T>
T Phanes::Core::Math::Magnitude(const TVector2<T>& v1) T Phanes::Core::Math::Magnitude(const TVector2<T>& v1)
{ {
return sqrtf(v1.x * v1.x + v1.y * v1.y); return sqrtf(v1.x * v1.x + v1.y * v1.y);
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::SqrMagnitude(const TVector2<T>& v1) T Phanes::Core::Math::SqrMagnitude(const TVector2<T>& v1)
{ {
return v1.x * v1.x + v1.y * v1.y; return v1.x * v1.x + v1.y * v1.y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NormalizeV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NormalizeV(TVector2<T>& v1)
{ {
float vecNorm = Magnitude(v1); float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalizeV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalizeV(TVector2<T>& v1)
{ {
v1 /= Magnitude(v1); v1 /= Magnitude(v1);
return v1; return v1;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::Angle(const TVector2<T>& v1, const TVector2<T>& v2) T Phanes::Core::Math::Angle(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2)); return acos((v1 * v2) / Magnitude(v1) * Magnitude(v2));
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::CosineAngle(const TVector2<T>& v1, const TVector2<T>& v2) T Phanes::Core::Math::CosineAngle(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return (v1 * v2) / Magnitude(v1) * Magnitude(v2); return (v1 * v2) / Magnitude(v1) * Magnitude(v2);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVectorV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVectorV(TVector2<T>& v1)
{ {
v1.x = (v1.x > 0) ? 1 : -1; v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1; v1.y = (v1.y > 0) ? 1 : -1;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquareV(TVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquareV(TVector2<T>& v1, T radius)
{ {
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
v1 *= k; v1 *= k;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquareV(TVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquareV(TVector2<T>& v1, T radius)
{ {
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f; float k = (prime > radius) ? abs(radius / prime) : 1.0f;
v1 *= k; v1 *= k;
return v1; return v1;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::DotP(const TVector2<T>& v1, const TVector2<T>& v2) T Phanes::Core::Math::DotP(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return v1.x * v2.x + v1.y * v2.y; return v1.x * v2.x + v1.y * v2.y;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MaxV(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MaxV(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1.x = Phanes::Core::Math::Max(v1.x, v2.x); v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
v1.y = Phanes::Core::Math::Max(v1.y, v2.y); v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MinV(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::MinV(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1.x = Phanes::Core::Math::Min(v1.x, v2.x); v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
v1.y = Phanes::Core::Math::Min(v1.y, v2.y); v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicularV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicularV(TVector2<T>& v1)
{ {
T x = v1.x; T x = v1.x;
v1.x = v1.y; v1.x = v1.y;
v1.y = -v1.x; v1.y = -v1.x;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TVector2<T>& v1)
{ {
T x = v1.x; T x = v1.x;
v1.x = -v1.y; v1.x = -v1.y;
v1.y = v1.x; v1.y = v1.x;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ScaleV(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ScaleV(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1.x *= v2.x; v1.x *= v2.x;
v1.y *= v2.y; v1.y *= v2.y;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverseV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverseV(TVector2<T>& v1)
{ {
v1.x = 1.0f / v1.x; v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y; v1.y = 1.0f / v1.y;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ReflectV(TVector2<T>& v1, const TVector2<T>& normal) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ReflectV(TVector2<T>& v1, const TVector2<T>& normal)
{ {
Set(v1, v1 - (2 * (v1 * normal) * normal)); Set(v1, v1 - (2 * (v1 * normal) * normal));
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, const TVector2<T>& v2)
{ {
v1 = v2; v1 = v2;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, T x, T y) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, T x, T y)
{ {
v1.x = x; v1.x = x;
v1.y = y; v1.y = y;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::RotateV(TVector2<T>& v1, T angle) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::RotateV(TVector2<T>& v1, T angle)
{ {
float sinAngle = sin(angle); float sinAngle = sin(angle);
float cosAngle = cos(angle); float cosAngle = cos(angle);
Set(v1, Set(v1,
v1.x * cosAngle - v1.y * sinAngle, v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle v1.y * cosAngle + v1.x * sinAngle
); );
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotateV(TVector2<T>& v1, T angle) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotateV(TVector2<T>& v1, T angle)
{ {
RotateV(v1, -angle); RotateV(v1, -angle);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NegateV(TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NegateV(TVector2<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
} }
template<RealType T> template<RealType T>
inline bool Phanes::Core::Math::IsNormalized(const TVector2<T>& v1, T threshold) inline bool Phanes::Core::Math::IsNormalized(const TVector2<T>& v1, T threshold)
{ {
return (SqrMagnitude(v1) < threshold); return (SqrMagnitude(v1) < threshold);
} }
template<RealType T> template<RealType T>
inline bool Phanes::Core::Math::IsPerpendicular(const TVector2<T>& v1, const TVector2<T>& v2, T threshold) inline bool Phanes::Core::Math::IsPerpendicular(const TVector2<T>& v1, const TVector2<T>& v2, T threshold)
{ {
return (abs(DotP(v1, v2)) < threshold); return (abs(DotP(v1, v2)) < threshold);
} }
template<RealType T> template<RealType T>
inline bool Phanes::Core::Math::IsParallel(const TVector2<T>& v1, const TVector2<T>& v2, T threshold) inline bool Phanes::Core::Math::IsParallel(const TVector2<T>& v1, const TVector2<T>& v2, T threshold)
{ {
return (abs(DotP(v1,v2)) > threshold); return (abs(DotP(v1,v2)) > threshold);
} }
template<RealType T> template<RealType T>
inline bool Phanes::Core::Math::IsCoincident(const TVector2<T>& v1, const TVector2<T>& v2, T threshold) inline bool Phanes::Core::Math::IsCoincident(const TVector2<T>& v1, const TVector2<T>& 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<T>& v1, const TVecto
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Reflect(const TVector2<T>& v1, const TVector2<T>& normal) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Reflect(const TVector2<T>& v1, const TVector2<T>& normal)
{ {
return TVector2<T>(v1 - (2 * (v1 * normal) * normal)); return TVector2<T>(v1 - (2 * (v1 * normal) * normal));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Scale(const TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Scale(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return TVector2<T>(v1.x * v2.x, v1.y * v2.y); return TVector2<T>(v1.x * v2.x, v1.y * v2.y);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverse(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverse(const TVector2<T>& v1)
{ {
return TVector2<T>(1.0f / v1.x, 1.0f / v1.y); return TVector2<T>(1.0f / v1.x, 1.0f / v1.y);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Negate(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Negate(const TVector2<T>& v1)
{ {
return TVector2<T>(-v1.x, -v1.y); return TVector2<T>(-v1.x, -v1.y);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicular(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicular(const TVector2<T>& v1)
{ {
return TVector2<T>(v1.y, -v1.x); return TVector2<T>(v1.y, -v1.x);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicular(const TVector2<T>& v1)
{ {
return TVector2<T>(-v1.y, v1.x); return TVector2<T>(-v1.y, v1.x);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Min(const TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Min(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return TVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y)); return TVector2<T>(Phanes::Core::Math::Min(v1.x, v2.x), Phanes::Core::Math::Min(v1.y, v2.y));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Max(const TVector2<T>& v1, const TVector2<T>& v2) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Max(const TVector2<T>& v1, const TVector2<T>& v2)
{ {
return TVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y)); return TVector2<T>(Phanes::Core::Math::Max(v1.x, v2.x), Phanes::Core::Math::Max(v1.y, v2.y));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Normalize(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Normalize(const TVector2<T>& v1)
{ {
float vecNorm = Magnitude(v1); float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm); return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalize(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalize(const TVector2<T>& v1)
{ {
return (v1 / Magnitude(v1)); return (v1 / Magnitude(v1));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVector(const TVector2<T>& v1) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVector(const TVector2<T>& v1)
{ {
return TVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1); return TVector2<T>((v1.x > 0) ? 1 : -1, (v1.y > 0) ? 1 : -1);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquare(const TVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::BindToSquare(const TVector2<T>& v1, T radius)
{ {
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y); float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
return v1 * k; return v1 * k;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquare(const TVector2<T>& v1, T radius) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClampToSquare(const TVector2<T>& v1, T radius)
{ {
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y; float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f; float k = (prime > radius) ? abs(radius / prime) : 1.0f;
return v1 * k; return v1 * k;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Lerp(const TVector2<T>& startVec, const TVector2<T>& destVec, T t) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Lerp(const TVector2<T>& startVec, const TVector2<T>& destVec, T 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 (t * destVec) + ((1 - t) * startVec); return (t * destVec) + ((1 - t) * startVec);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::LerpUnclamped(const TVector2<T>& startVec, const TVector2<T>& destVec, T t) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::LerpUnclamped(const TVector2<T>& startVec, const TVector2<T>& destVec, T t)
{ {
return (t * destVec) + ((1 - t) * startVec); return (t * destVec) + ((1 - t) * startVec);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Rotate(const TVector2<T>& v1, T angle) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Rotate(const TVector2<T>& v1, T angle)
{ {
float sinAngle = sin(angle); float sinAngle = sin(angle);
float cosAngle = cos(angle); float cosAngle = cos(angle);
return TVector2<T>(v1.x * cosAngle - v1.y * sinAngle, return TVector2<T>(v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle); v1.y * cosAngle + v1.x * sinAngle);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotate(const TVector2<T>& v1, T angle) Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ClockwiseRotate(const TVector2<T>& v1, T angle)
{ {
return Rotate(v1, -angle); return Rotate(v1, -angle);
} }

View File

@ -12,37 +12,37 @@
template<RealType T> template<RealType T>
inline Phanes::Core::Math::TVector3<T>::TVector3(const Real x, const Real y, const Real z) inline Phanes::Core::Math::TVector3<T>::TVector3(const Real x, const Real y, const Real z)
{ {
this->x = x; this->x = x;
this->y = y; this->y = y;
this->z = z; this->z = z;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T>::TVector3(const Real* comp) Phanes::Core::Math::TVector3<T>::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."); 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); memcpy(this->comp, comp, sizeof(T) * 3);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T>::TVector3(const TPoint3<T>& start, const TPoint3<T>& end) Phanes::Core::Math::TVector3<T>::TVector3(const TPoint3<T>& start, const TPoint3<T>& end)
{ {
this->x = end.x - start.x; this->x = end.x - start.x;
this->y = end.y - start.y; this->y = end.y - start.y;
this->z = end.z - start.z; this->z = end.z - start.z;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T>::TVector3(const TVector3<Real>& v) Phanes::Core::Math::TVector3<T>::TVector3(const TVector3<Real>& v)
{ {
memcpy(this->comp, comp, sizeof(T) * 3); memcpy(this->comp, comp, sizeof(T) * 3);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v) Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v)
{ {
this->comp = v.comp; this->comp = v.comp;
v.comp = nullptr; v.comp = nullptr;
} }
@ -55,139 +55,139 @@ Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v)
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, T s)
{ {
v1.x += s; v1.x += s;
v1.y += s; v1.y += s;
v1.z += s; v1.z += s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, const TVector3<T>& v2)
{ {
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 v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, T s)
{ {
v1.x -= s; v1.x -= s;
v1.y -= s; v1.y -= s;
v1.z -= s; v1.z -= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, const TVector3<T>& v2)
{ {
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 v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*=(TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*=(TVector3<T>& v1, T s)
{ {
v1.x *= s; v1.x *= s;
v1.y *= s; v1.y *= s;
v1.z *= s; v1.z *= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/=(TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/=(TVector3<T>& v1, T s)
{ {
s = (T)1.0 / s; s = (T)1.0 / s;
v1.x *= s; v1.x *= s;
v1.y *= s; v1.y *= s;
v1.z *= s; v1.z *= s;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(const TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(const TVector3<T>& v1, T s)
{ {
return TVector3<T>(v1.x * s. v1.y * s, v1.z * s); return TVector3<T>(v1.x * s. v1.y * s, v1.z * s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(const TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(const TVector3<T>& v1, T s)
{ {
s = (T)1.0 / s; s = (T)1.0 / s;
return TVector3<T>(v1.x * s.v1.y * s, v1.z * s); return TVector3<T>(v1.x * s.v1.y * s, v1.z * s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(T s, const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(T s, const TVector3<T>& v1)
{ {
return v1 * s; return v1 * s;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(T s, const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(T s, const TVector3<T>& v1)
{ {
return v1 / s; return v1 / s;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::operator*(const TVector3<T>& v1, const TVector3<T>& v2) T Phanes::Core::Math::operator*(const TVector3<T>& v1, const TVector3<T>& 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<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, T s)
{ {
return TVector3<T>(v1.x + s.v1.y + s, v1.z + s); return TVector3<T>(v1.x + s.v1.y + s, v1.z + s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); return TVector3<T>(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, T s) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, T s)
{ {
return TVector3<T>(v1.x - s.v1.y - s, v1.z - s); return TVector3<T>(v1.x - s.v1.y - s, v1.z - s);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); return TVector3<T>(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(TVector3<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
v1.z = -v1.z; v1.z = -v1.z;
return v1; return v1;
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::operator==(const TVector3<T>& v1, const TVector3<T>& v2) bool Phanes::Core::Math::operator==(const TVector3<T>& v1, const TVector3<T>& 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<RealType T> template<RealType T>
bool Phanes::Core::Math::operator!=(const TVector3<T>& v1, const TVector3<T>& v2) bool Phanes::Core::Math::operator!=(const TVector3<T>& v1, const TVector3<T>& 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<T>& v1, const TVector3<T>& v2
template<RealType T> template<RealType T>
T Phanes::Core::Math::Magnitude(const TVector3<T>& v1) T Phanes::Core::Math::Magnitude(const TVector3<T>& v1)
{ {
return sqrt(DotP(v1, v1)); return sqrt(DotP(v1, v1));
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::SqrMagnitude(const TVector3<T>& v1) T Phanes::Core::Math::SqrMagnitude(const TVector3<T>& v1)
{ {
return DotP(v1, v1); return DotP(v1, v1);
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::SqrLength(const TVector3<T>& v1) T Phanes::Core::Math::SqrLength(const TVector3<T>& v1)
{ {
return SqrMagnitude(v1); return SqrMagnitude(v1);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NormalizeV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NormalizeV(TVector3<T>& v1)
{ {
float vecNorm = Magnitude(v1); float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm; v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalizeV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalizeV(TVector3<T>& v1)
{ {
v1 /= Magnitude(v1); v1 /= Magnitude(v1);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectV(TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectV(TVector3<T>& v1, const TVector3<T>& normal)
{ {
Set(v1, v1 - (2 * (v1 * normal) * normal)); Set(v1, v1 - (2 * (v1 * normal) * normal));
return v1; return v1;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::Angle(const TVector3<T>& v1, const TVector3<T>& v2) T Phanes::Core::Math::Angle(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2))); return acos((v1 * v2) / (Magnitude(v1) * Magnitude(v2)));
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::DotP(const TVector3<T>& v1, const TVector3<T>& v2) T Phanes::Core::Math::DotP(const TVector3<T>& v1, const TVector3<T>& 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<RealType T> template<RealType T>
void Phanes::Core::Math::Orthogonalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3) void Phanes::Core::Math::Orthogonalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
{ {
Set(v2, Reject(v2, v1)); Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2)); Set(v3, Reject(Reject(v3, v1), v2));
} }
template<RealType T> template<RealType T>
void Phanes::Core::Math::OrthoNormalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3) void Phanes::Core::Math::OrthoNormalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
{ {
Set(v2, Reject(v2, v1)); Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2)); Set(v3, Reject(Reject(v3, v1), v2));
NormalizeV(v1); NormalizeV(v1);
NormalizeV(v2); NormalizeV(v2);
NormalizeV(v3); NormalizeV(v3);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitude(const TVector3<T>& v1, T magnitude) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitude(const TVector3<T>& v1, T magnitude)
{ {
NormalizeV(v1) *= magnitude; NormalizeV(v1) *= magnitude;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverse(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverse(const TVector3<T>& v1)
{ {
return TVector3<T>((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z); return TVector3<T>((T)1.0f / v1.x, (T)1.0f / v1.y, (T)1.0f / v1.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TPlane<T>& plane) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TPlane<T>& plane)
{ {
return Reflect(v1, plane.normal); return Reflect(v1, plane.normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlane(const TVector3<T>& v1, const TVector3<T>& normal)
{ {
return Reflect(v1, normal); return Reflect(v1, normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxis(const TVector3<T>& v1, const TVector3<T>& axisNormal, T angle) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxis(const TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
{ {
T sinAngle = sin(angle); T sinAngle = sin(angle);
T cosAngle = cos(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<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
{ {
return CrossP(CrossP(v1, v2), v3); return CrossP(CrossP(v1, v2), v3);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Project(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Project(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return (DotP(v1, v2) / DotP(v2, v2)) * v2; return (DotP(v1, v2) / DotP(v2, v2)) * v2;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reject(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reject(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2; return v1 - (DotP(v1, v2) / DotP(v2, v2)) * v2;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TVector3<T>& normal)
{ {
return Reject(v1, normal); return Reject(v1, normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TPlane<T>& plane) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlane(const TVector3<T>& v1, const TPlane<T>& plane)
{ {
return Reject(v1, plane.normal); return Reject(v1, plane.normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVector(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVector(const TVector3<T>& v1)
{ {
v1.x = (v1.x > 0) - (v1.x < 0); v1.x = (v1.x > 0) - (v1.x < 0);
v1.y = (v1.y > 0) - (v1.y < 0); v1.y = (v1.y > 0) - (v1.y < 0);
v1.z = (v1.z > 0) - (v1.z < 0); v1.z = (v1.z > 0) - (v1.z < 0);
return v1; return v1;
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::Equals(const TVector3<T>& v1, const TVector3<T>& v2, T threshold) bool Phanes::Core::Math::Equals(const TVector3<T>& v1, const TVector3<T>& 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<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivideV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivideV(TVector3<T>& v1)
{ {
float _z = (T)1.0 / v1.z; float _z = (T)1.0 / v1.z;
v1.x *= _z; v1.x *= _z;
v1.y *= _z; v1.y *= _z;
v1.z = (T)0.0; v1.z = (T)0.0;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossPV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossPV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
float x = v1.x; float x = v1.x;
float y = v1.y; float y = v1.y;
float z = v1.z; float z = v1.z;
v1.x = (y * v2.z) - (z * v2.y); v1.x = (y * v2.z) - (z * v2.y);
v1.y = (z * v2.x) - (x * v2.z); v1.y = (z * v2.x) - (x * v2.z);
v1.z = (x * v2.y) - (y * v2.x); v1.z = (x * v2.y) - (y * v2.x);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MaxV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MaxV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
v1.x = Max(v1.x, v2.x); v1.x = Max(v1.x, v2.x);
v1.y = Max(v1.y, v2.y); v1.y = Max(v1.y, v2.y);
v1.z = Max(v1.z, v2.z); v1.z = Max(v1.z, v2.z);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MinV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MinV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
v1.x = Min(v1.x, v2.x); v1.x = Min(v1.x, v2.x);
v1.y = Min(v1.y, v2.y); v1.y = Min(v1.y, v2.y);
v1.z = Min(v1.z, v2.z); v1.z = Min(v1.z, v2.z);
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NegateV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NegateV(TVector3<T>& v1)
{ {
v1.x = -v1.x; v1.x = -v1.x;
v1.y = -v1.y; v1.y = -v1.y;
v1.z = -v1.z; v1.z = -v1.z;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
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 v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
float x = (v1 * v2) / (v2 * v2); float x = (v1 * v2) / (v2 * v2);
v1 = x * v2; v1 = x * v2;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RejectV(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RejectV(TVector3<T>& v1, const TVector3<T>& v2)
{ {
float x = (v1 * v2) / (v2 * v2); float x = (v1 * v2) / (v2 * v2);
v1 -= x * v2; v1 -= x * v2;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TVector3<T>& normal)
{ {
return RejectV(v1, normal); return RejectV(v1, normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TPlane<T>& plane) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectOntoPlaneV(TVector3<T>& v1, const TPlane<T>& plane)
{ {
return RejectV(v1, plane.normal); return RejectV(v1, plane.normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, const TVector3<T>& v2)
{ {
v1 = v2; v1 = v2;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, T x, T y, T z) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, T x, T y, T z)
{ {
v1.x = x; v1.x = x;
v1.y = y; v1.y = y;
v1.z = z; v1.z = z;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitudeV(TVector3<T>& v1, T min, T max) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitudeV(TVector3<T>& 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<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverseV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverseV(TVector3<T>& v1)
{ {
v1.x = 1.0f / v1.x; v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y; v1.y = 1.0f / v1.y;
v1.z = 1.0f / v1.z; v1.z = 1.0f / v1.z;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TPlane<T>& plane) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TPlane<T>& plane)
{ {
return ReflectV(v1, plane.normal); return ReflectV(v1, plane.normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ReflectFromPlaneV(TVector3<T>& v1, const TVector3<T>& normal)
{ {
return ReflectV(v1, normal); return ReflectV(v1, normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxisV(TVector3<T>& v1, const TVector3<T>& axisNormal, T angle) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxisV(TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
{ {
T sinAngle = sin(angle); T sinAngle = sin(angle);
T cosAngle = cos(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<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitudeV(TVector3<T>& v1, T magnitude) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleToMagnitudeV(TVector3<T>& v1, T magnitude)
{ {
NormalizeV(v1) *= magnitude; NormalizeV(v1) *= magnitude;
return v1; return v1;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVectorV(TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVectorV(TVector3<T>& v1)
{ {
v1.x = (v1.x > 0) ? 1 : 0; v1.x = (v1.x > 0) ? 1 : 0;
v1.y = (v1.y > 0) ? 1 : 0; v1.y = (v1.y > 0) ? 1 : 0;
v1.z = (v1.z > 0) ? 1 : 0; v1.z = (v1.z > 0) ? 1 : 0;
return v1; return v1;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::ScalarTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3) T Phanes::Core::Math::ScalarTriple(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
{ {
return CrossP(v1, v2) * v3; return CrossP(v1, v2) * v3;
} }
template<RealType T> template<RealType T>
T Phanes::Core::Math::CosineAngle(const TVector3<T>& v1, const TVector3<T>& v2) T Phanes::Core::Math::CosineAngle(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return (v1 * v2) / (Magnitude(v1) * Magnitude(v2)); return (v1 * v2) / (Magnitude(v1) * Magnitude(v2));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTripleV(TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::VectorTripleV(TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3)
{ {
CrossPV(CrossPV(v1, v2), v3); CrossPV(CrossPV(v1, v2), v3);
return v1; return v1;
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::IsPerpendicular(const TVector3<T>& v1, const TVector3<T>& v2, T threshold) bool Phanes::Core::Math::IsPerpendicular(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
{ {
return (abs(DotP(v1, v2)) < threshold); return (abs(DotP(v1, v2)) < threshold);
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::IsParallel(const TVector3<T>& v1, const TVector3<T>& v2, T threshold) bool Phanes::Core::Math::IsParallel(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
{ {
return (abs(DotP(v1, v2)) > threshold); return (abs(DotP(v1, v2)) > threshold);
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::IsCoincident(const TVector3<T>& v1, const TVector3<T>& v2, T threshold) bool Phanes::Core::Math::IsCoincident(const TVector3<T>& v1, const TVector3<T>& v2, T threshold)
{ {
return (DotP(v1, v2) > threshold); return (DotP(v1, v2) > threshold);
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::IsNormalized(const TVector3<T>& v1, T threshold) bool Phanes::Core::Math::IsNormalized(const TVector3<T>& v1, T threshold)
{ {
return (SqrMagnitude(v1) < threshold); return (SqrMagnitude(v1) < threshold);
} }
template<RealType T> template<RealType T>
bool Phanes::Core::Math::IsCoplanar(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& v3, T threshold) bool Phanes::Core::Math::IsCoplanar(const TVector3<T>& v1, const TVector3<T>& v2, const TVector3<T>& 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<T>& v1, const TVector3<T>& v2
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Normalize(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Normalize(const TVector3<T>& v1)
{ {
float vecNorm = Magnitude(v1); float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm; return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalize(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalize(const TVector3<T>& v1)
{ {
return v1 / Magnitude(v1); return v1 / Magnitude(v1);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reflect(const TVector3<T>& v1, const TVector3<T>& normal) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Reflect(const TVector3<T>& v1, const TVector3<T>& normal)
{ {
return v1 - (2 * (v1 * normal) * normal); return v1 - (2 * (v1 * normal) * normal);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivide(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivide(const TVector3<T>& v1)
{ {
float _z = (T)1.0 / v1.z; float _z = (T)1.0 / v1.z;
return TVector3<T>(v1.x * _z, v1.y * _z, (T)0.0); return TVector3<T>(v1.x * _z, v1.y * _z, (T)0.0);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossP(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossP(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>((v1.y * v2.z) - (v1.z * v2.y), return TVector3<T>((v1.y * v2.z) - (v1.z * v2.y),
(v1.z * v2.x) - (v1.x * v2.z), (v1.z * v2.x) - (v1.x * v2.z),
(v1.x * v2.y) - (v1.y * v2.x)); (v1.x * v2.y) - (v1.y * v2.x));
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Lerp(const TVector3<T>& start, const TVector3<T>& dest, T t) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Lerp(const TVector3<T>& start, const TVector3<T>& dest, T t)
{ {
t = Clamp(t, (T)0.0, (T), 1.0); t = Clamp(t, (T)0.0, (T), 1.0);
return (1 - t) * start + t * dest; return (1 - t) * start + t * dest;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::LerpUnclamped(const TVector3<T>& start, const TVector3<T>& dest, T t) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::LerpUnclamped(const TVector3<T>& start, const TVector3<T>& dest, T t)
{ {
return (1 - t) * start + t * dest; return (1 - t) * start + t * dest;
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Max(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Max(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>((v1.x > v2.x) ? v1.x : v2.x, return TVector3<T>((v1.x > v2.x) ? v1.x : v2.x,
(v1.y > v2.y) ? v1.y : v2.y, (v1.y > v2.y) ? v1.y : v2.y,
(v1.z > v2.z) ? v1.z : v2.z); (v1.z > v2.z) ? v1.z : v2.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Min(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Min(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>((v1.x < v2.x) ? v1.x : v2.x, return TVector3<T>((v1.x < v2.x) ? v1.x : v2.x,
(v1.y < v2.y) ? v1.y : v2.y, (v1.y < v2.y) ? v1.y : v2.y,
(v1.z < v2.z) ? v1.z : v2.z); (v1.z < v2.z) ? v1.z : v2.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Negate(const TVector3<T>& v1) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Negate(const TVector3<T>& v1)
{ {
return TVector3<T>(-v1.x, -v1.y, -v1.z); return TVector3<T>(-v1.x, -v1.y, -v1.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Scale(const TVector3<T>& v1, const TVector3<T>& v2) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Scale(const TVector3<T>& v1, const TVector3<T>& v2)
{ {
return TVector3<T>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); return TVector3<T>(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
} }
template<RealType T> template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitude(const TVector3<T>& v1, T min, T max) Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ClampMagnitude(const TVector3<T>& v1, T min, T max)
{ {
T magnitude = Magnitude(v1); T magnitude = Magnitude(v1);
const TVector3<T> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T); const TVector3<T> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
Clamp(magnitude, min, max); Clamp(magnitude, min, max);
return unitVec * magnitude; return unitVec * magnitude;
} }

View File

@ -13,5 +13,5 @@ Phanes::Core::Application::PhanesGame::~PhanesGame()
void Phanes::Core::Application::PhanesGame::Run() void Phanes::Core::Application::PhanesGame::Run()
{ {
while (true); while (true);
} }

View File

@ -24,131 +24,131 @@
namespace Phanes::Core::Math { 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<IntType T> template<IntType T>
struct TIntPoint2 : public TIntVector2<T> { struct TIntPoint2 : public TIntVector2<T> {
using TIntVector2<T>::TIntVector2; using TIntVector2<T>::TIntVector2;
/** /**
* Creates IntPoint2 from IntPoint3's xy * Creates IntPoint2 from IntPoint3's xy
* *
* @param a IntPoint3 one * @param a IntPoint3 one
*/ */
TIntPoint2(const TIntPoint3<T>& a) TIntPoint2(const TIntPoint3<T>& a)
{ {
this->x = a.x; this->x = a.x;
this->y = a.y; this->y = a.y;
} }
/** /**
* Creates IntPoint2 from IntPoint4's xy * Creates IntPoint2 from IntPoint4's xy
* *
* @param a IntPoint4 one * @param a IntPoint4 one
*/ */
//TIntPoint2(const TIntPoint4<T>& a) //TIntPoint2(const TIntPoint4<T>& a)
//{ //{
// this->x = a.x; // this->x = a.x;
// this->y = a.y; // this->y = a.y;
//} //}
}; };
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2); Rt Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* A 3D Point with components x and y with integer precision. * A 3D Point with components x and y with integer precision.
*/ */
template<IntType T> template<IntType T>
struct TIntPoint3 : public TIntVector3<T> { struct TIntPoint3 : public TIntVector3<T> {
using TIntVector3<T>::TIntVector3; using TIntVector3<T>::TIntVector3;
/** /**
* Creates IntPoint3 from IntPoint2's xy and zero * Creates IntPoint3 from IntPoint2's xy and zero
* *
* @param a IntPoint2 one * @param a IntPoint2 one
*/ */
TIntPoint3(const TIntPoint2<T>& a) TIntPoint3(const TIntPoint2<T>& a)
{ {
this->x = a.x; this->x = a.x;
this->y = a.y; this->y = a.y;
this->z = 0; this->z = 0;
} }
/** /**
* Creates IntPoint3 from IntPoint4's xyz * Creates IntPoint3 from IntPoint4's xyz
* *
* @param a IntPoint4 one * @param a IntPoint4 one
*/ */
//TIntPoint3(const TIntPoint4<T>& a) //TIntPoint3(const TIntPoint4<T>& a)
//{ //{
// this->components[0] = a.components[0]; // this->components[0] = a.components[0];
// this->components[1] = a.components[1]; // this->components[1] = a.components[1];
// this->components[2] = a.components[2]; // this->components[2] = a.components[2];
//} //}
}; };
template<IntType T, RealType Rt> template<IntType T, RealType Rt>
Rt Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2); Rt Distance(const TIntPoint3<T>& p1, const TIntPoint3<T>& p2);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* A 4D Point with components x and y with integer precision. * A 4D Point with components x and y with integer precision.
*/ */
//template<typename T> //template<typename T>
//struct TIntPoint4 : public TIntVector4<T> { //struct TIntPoint4 : public TIntVector4<T> {
// static_assert(std::is_integral_v(T), "T must be an integer type."); // static_assert(std::is_integral_v(T), "T must be an integer type.");
// using IntVector4<T>::IntVector4; // using IntVector4<T>::IntVector4;
// /** // /**
// * Creates IntPoint4 from IntPoint2's xy and the last two zero // * Creates IntPoint4 from IntPoint2's xy and the last two zero
// * // *
// * @param a IntPoint2 one // * @param a IntPoint2 one
// */ // */
// PHANES_CORE_API IntPoint4(const IntPoint2<T>& a) // PHANES_CORE_API IntPoint4(const IntPoint2<T>& a)
// { // {
// this->components[0] = a.components[0]; // this->components[0] = a.components[0];
// this->components[1] = a.components[1]; // this->components[1] = a.components[1];
// this->components[2] = 0; // this->components[2] = 0;
// this->components[3] = 0; // this->components[3] = 0;
// } // }
// /** // /**
// * Creates IntPoint4 from IntPoint3's xyz and zero // * Creates IntPoint4 from IntPoint3's xyz and zero
// * // *
// * @param a IntPoint3 one // * @param a IntPoint3 one
// */ // */
// PHANES_CORE_API IntPoint4(const IntPoint3<T>& a) // PHANES_CORE_API IntPoint4(const IntPoint3<T>& a)
// { // {
// this->components[0] = a.components[0]; // this->components[0] = a.components[0];
// this->components[1] = a.components[1]; // this->components[1] = a.components[1];
// this->components[2] = a.components[2]; // this->components[2] = a.components[2];
// this->components[3] = 0; // this->components[3] = 0;
// } // }
//}; //};
} // phanes::core::math::coretypes } // phanes::core::math::coretypes

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,24 +5,24 @@
namespace Phanes::Core::Math::Internal { namespace Phanes::Core::Math::Internal {
template <typename T, unsigned int D = 3> template <typename T, unsigned int D = 3>
struct AVector { struct AVector {
public: public:
/** /**
* List of n components of the vector * List of n components of the vector
*/ */
T comp[D]; T comp[D];
}; };
template <typename T, unsigned int n = 3, unsigned int m = 3> template <typename T, unsigned int n = 3, unsigned int m = 3>
struct AMatrix { struct AMatrix {
public: public:
T fields[n][m]; T fields[n][m];
}; };
}; // Phanes::Core::Math::abstract::coretypes }; // Phanes::Core::Math::abstract::coretypes

View File

@ -21,76 +21,76 @@
namespace Phanes::Core::Math { namespace Phanes::Core::Math {
/** /**
* Clamps a value between minimum and maximum * Clamps a value between minimum and maximum
* *
* @param value Value to clamp * @param value Value to clamp
* @param low Minimum * @param low Minimum
* @param high Maximum * @param high Maximum
* *
* @return Minimum, if value is to small / Maximum, if value is to large / value, if value is in range. * @return Minimum, if value is to small / Maximum, if value is to large / value, if value is in range.
*/ */
template<typename T> template<typename T>
T Clamp(T value, T low, T high); T Clamp(T value, T low, T high);
/** /**
* Gets the larger of two values * Gets the larger of two values
* *
* @param x * @param x
* @param y * @param y
* *
* @return Larger value * @return Larger value
*/ */
template<typename T> template<typename T>
inline T Max(T x, T y); inline T Max(T x, T y);
/** /**
* Gets the smaller of two values * Gets the smaller of two values
* *
* @param x * @param x
* @param y * @param y
* *
* @return Smaller value * @return Smaller value
*/ */
template<typename T> template<typename T>
inline T Min(T x, T y); inline T Min(T x, T y);
/** /**
* Swaps the values of two variables * Swaps the values of two variables
* *
* @param x * @param x
* @param y * @param y
*/ */
template<typename T> template<typename T>
inline void Swap(T& x, T& y); inline void Swap(T& x, T& y);
/** /**
* Test two numbers for equality * Test two numbers for equality
* *
* @param x * @param x
*/ */
template<typename T> template<typename T>
bool Equals(T x, T y, T threshold = P_FLT_INAC); 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 * Calculates the reciprocal of the square root of n using the algorithm of A Quake III
* *
* @param n Number to calculate * @param n Number to calculate
* *
* @return Inverse square root of n * @return Inverse square root of n
* *
* @note a simple 1.0f / sqrtf(x) is faster than this algorithm. Use for research purpose only. * @note a simple 1.0f / sqrtf(x) is faster than this algorithm. Use for research purpose only.
*/ */
template<typename T> template<typename T>
float FastInvSqrt(T n); float FastInvSqrt(T n);
} // phanes } // phanes

View File

@ -18,85 +18,85 @@
namespace Phanes::Core::Math { namespace Phanes::Core::Math {
/** /**
* Template forward declarations. * Template forward declarations.
*/ */
template<RealType T> struct TColor; template<RealType T> struct TColor;
template<RealType T> struct TLinearColor; template<RealType T> struct TLinearColor;
template<RealType T> struct TVector2; template<RealType T> struct TVector2;
template<RealType T> struct TVector3; template<RealType T> struct TVector3;
template<RealType T> struct TVector4; template<RealType T> struct TVector4;
template<RealType T> struct TRay; template<RealType T> struct TRay;
template<RealType T> struct TPlane; template<RealType T> struct TPlane;
template<RealType T> struct TMatrix2; template<RealType T> struct TMatrix2;
template<RealType T> struct TMatrix3; template<RealType T> struct TMatrix3;
template<RealType T> struct TMatrix4; template<RealType T> struct TMatrix4;
template<RealType T> struct TQuaternion; template<RealType T> struct TQuaternion;
template<RealType T> struct TTransform; template<RealType T> struct TTransform;
template<RealType T> struct TPoint2; template<RealType T> struct TPoint2;
template<RealType T> struct TPoint3; template<RealType T> struct TPoint3;
template<RealType T> struct TPoint4; template<RealType T> struct TPoint4;
template<IntType T> struct TIntVector2; template<IntType T> struct TIntVector2;
template<IntType T> struct TIntVector3; template<IntType T> struct TIntVector3;
template<IntType T> struct TIntVector4; template<IntType T> struct TIntVector4;
template<IntType T> struct TIntPoint2; template<IntType T> struct TIntPoint2;
template<IntType T> struct TIntPoint3; template<IntType T> struct TIntPoint3;
template<IntType T> struct TIntPoint4; template<IntType T> struct TIntPoint4;
/** /**
* Specific instantiation of forward declarations. * Specific instantiation of forward declarations.
*/ */
// TVector2 // TVector2
typedef TVector2<float> Vector2; typedef TVector2<float> Vector2;
typedef TVector2<double> Vector2d; typedef TVector2<double> Vector2d;
typedef std::vector<Vector2> Vector2List; typedef std::vector<Vector2> Vector2List;
typedef std::vector<Vector2d> Vector2Listd; typedef std::vector<Vector2d> Vector2Listd;
// TVector3 // TVector3
typedef TVector3<float> Vector3; typedef TVector3<float> Vector3;
typedef TVector3<double> Vector3d; typedef TVector3<double> Vector3d;
typedef std::vector<Vector3> Vector3List; typedef std::vector<Vector3> Vector3List;
typedef std::vector<Vector3d> Vector3Listd; typedef std::vector<Vector3d> Vector3Listd;
// TIntVector2 // TIntVector2
typedef TIntVector2<int> IntVector2; typedef TIntVector2<int> IntVector2;
typedef TIntVector2<long> IntVector2l; typedef TIntVector2<long> IntVector2l;
typedef std::vector<IntVector2> IntVector2List; typedef std::vector<IntVector2> IntVector2List;
typedef std::vector<IntVector2l> IntVector2Listl; typedef std::vector<IntVector2l> IntVector2Listl;
// TIntVector3 // TIntVector3
typedef TIntVector3<int> IntVector3; typedef TIntVector3<int> IntVector3;
typedef TIntVector3<long> IntVector3l; typedef TIntVector3<long> IntVector3l;
typedef std::vector<IntVector3> IntVector3List; typedef std::vector<IntVector3> IntVector3List;
typedef std::vector<IntVector3l> IntVector3Listl; typedef std::vector<IntVector3l> IntVector3Listl;
// TMatrix2 // TMatrix2
typedef TMatrix2<float> Matrix2; typedef TMatrix2<float> Matrix2;
typedef TMatrix2<double> Matrix2d; typedef TMatrix2<double> Matrix2d;
typedef std::vector<Matrix2> Matrix2List; typedef std::vector<Matrix2> Matrix2List;
typedef std::vector<Matrix2d> Matrix2Listd; typedef std::vector<Matrix2d> Matrix2Listd;
} // Phanes::Core::Math::coretypes } // Phanes::Core::Math::coretypes
namespace Phanes::Core::Math::Internal namespace Phanes::Core::Math::Internal
{ {
// Internal types // Internal types
template <typename T, unsigned int D> struct AVector; template <typename T, unsigned int D> struct AVector;
template <typename T, unsigned int n, unsigned int> struct AMatrix; template <typename T, unsigned int n, unsigned int> struct AMatrix;
} }

View File

@ -24,53 +24,53 @@
namespace Phanes::Core::Math { namespace Phanes::Core::Math {
// =================================================== // // =================================================== //
// std::to_string wrapper // // std::to_string wrapper //
// // // //
// This is, to make using ToString more general // // This is, to make using ToString more general //
// and allow usage of one function instead of two, // // and allow usage of one function instead of two, //
// for converting a mathmatical type to a string. // // 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<RealType T> template<RealType T>
std::string ToString(const TVector2<T>& v); std::string ToString(const TVector2<T>& v);
template<IntType T> template<IntType T>
std::string ToString(const TIntVector2<T>& v); std::string ToString(const TIntVector2<T>& v);
template<RealType T> template<RealType T>
std::string ToString(const TVector3<T>& v); std::string ToString(const TVector3<T>& v);
template<IntType T> template<IntType T>
std::string ToString(const TIntVector3<T>& v); std::string ToString(const TIntVector3<T>& 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);
} }

View File

@ -11,111 +11,111 @@
namespace Phanes::Core::Math::UnitConversion namespace Phanes::Core::Math::UnitConversion
{ {
/** /**
* Converts degrees to radians. * Converts degrees to radians.
* *
* @param(deg) Angle in degress (°) * @param(deg) Angle in degress (°)
* *
* @return Angle in radians * @return Angle in radians
*/ */
template<RealType T> template<RealType T>
inline T DegToRad(T deg); inline T DegToRad(T deg);
/** /**
* Converts radians to degrees. * Converts radians to degrees.
* *
* @param(rad) Angle in radians (rad) * @param(rad) Angle in radians (rad)
* *
* @return Angle in degrees * @return Angle in degrees
*/ */
template<RealType T> template<RealType T>
inline T RadToDeg(T rad); inline T RadToDeg(T rad);
/** /**
* Converts degrees to gradian. * Converts degrees to gradian.
* *
* @param(deg) Angle in degress (°) * @param(deg) Angle in degress (°)
* *
* @return Angle in gradian * @return Angle in gradian
*/ */
template<RealType T> template<RealType T>
inline T DegToGradian(T deg); inline T DegToGradian(T deg);
/** /**
* Converts gradian to degrees. * Converts gradian to degrees.
* *
* @param(rad) Angle in gradians (g) * @param(rad) Angle in gradians (g)
* *
* @return Angle in degrees * @return Angle in degrees
*/ */
template<RealType T> template<RealType T>
inline T GradianToDeg(T g); inline T GradianToDeg(T g);
/** /**
* Converts radians to gradians. * Converts radians to gradians.
* *
* @param(deg) Angle in radians (rad) * @param(deg) Angle in radians (rad)
* *
* @return Angle in gradians * @return Angle in gradians
*/ */
template<RealType T> template<RealType T>
inline T RadToGradian(T rad); inline T RadToGradian(T rad);
/** /**
* Converts gradian to radians. * Converts gradian to radians.
* *
* @param(rad) Angle in gradians (g) * @param(rad) Angle in gradians (g)
* *
* @return Angle in radians * @return Angle in radians
*/ */
template<RealType T> template<RealType T>
inline T GradianToRad(T g); inline T GradianToRad(T g);
} // phanes::core::math::typeconversion } // phanes::core::math::typeconversion
namespace Phanes::Core::Math::UnitLiterals namespace Phanes::Core::Math::UnitLiterals
{ {
// ============================================== // // ============================================== //
// unit conversion with user-defined literals // // unit conversion with user-defined literals //
// ============================================== // // ============================================== //
/** /**
* Convert deg to rad. * Convert deg to rad.
* *
* @param(_x) Angle in degress * @param(_x) Angle in degress
*/ */
double operator ""_deg(long double _x) double operator ""_deg(long double _x)
{ {
return _x * P_PI_180_FLT; return _x * P_PI_180_FLT;
} }
/** /**
* Convert rad to rad. * Convert rad to rad.
* *
* @param(_x) Angle in degress * @param(_x) Angle in degress
*/ */
double operator ""_rad(long double _x) double operator ""_rad(long double _x)
{ {
return _x; return _x;
} }
/** /**
* Convert gradian to rad. * Convert gradian to rad.
* *
* @param(_x) Angle in degress * @param(_x) Angle in degress
*/ */
double operator ""_g(long double _x) double operator ""_g(long double _x)
{ {
return _x * P_PI_FLT / 200; return _x * P_PI_FLT / 200;
} }
} }

View File

@ -10,143 +10,143 @@
namespace Phanes::Core::Math { namespace Phanes::Core::Math {
// 2x2 Matrix defined in column-major order. // 2x2 Matrix defined in column-major order.
// Accessed by M[Row][Col]. // Accessed by M[Row][Col].
template<RealType T> template<RealType T>
struct alignas(4) TMatrix2 struct alignas(4) TMatrix2
{ {
public: 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<T>& m); TMatrix2(const TMatrix2<T>& m);
/** /**
* Move constructor. * Move constructor.
*/ */
TMatrix2(TMatrix2<T>&& m); TMatrix2(TMatrix2<T>&& m);
/** /**
* Construct Matrix from 2d array. * Construct Matrix from 2d array.
* *
* @param(fields) 2D Array with column major order. * @param(fields) 2D Array with column major order.
*/ */
TMatrix2(T fields[2][2]); TMatrix2(T fields[2][2]);
/** /**
* Construct Matrix from parameters. * Construct Matrix from parameters.
* *
* @param(n00) M[0][0] * @param(n00) M[0][0]
* @param(n10) M[1][0] * @param(n10) M[1][0]
* @param(n01) M[0][1] * @param(n01) M[0][1]
* @param(n11) M[1][1] * @param(n11) M[1][1]
* *
* @note nXY = n[Row][Col] * @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. * Construct Matrix from two 2d vector columns.
* *
* @param(v1) Column zero * @param(v1) Column zero
* @param(v2) Column one * @param(v2) Column one
*/ */
TMatrix2(const TVector2<T>& v1, const TVector2<T>& v2); TMatrix2(const TVector2<T>& v1, const TVector2<T>& v2);
public: public:
FORCEINLINE T& operator() (int n, int m); FORCEINLINE T& operator() (int n, int m);
FORCEINLINE TVector2<T>& operator[] (int m); FORCEINLINE TVector2<T>& operator[] (int m);
FORCEINLINE const T& operator() (int n, int m) const; FORCEINLINE const T& operator() (int n, int m) const;
FORCEINLINE const TVector2<T>& operator[] (int m) const; FORCEINLINE const TVector2<T>& operator[] (int m) const;
}; };
// ==================== // // ==================== //
// Matrix2 operator // // Matrix2 operator //
// ==================== // // ==================== //
template<RealType T> template<RealType T>
void operator+= (TMatrix2<T>& m1, T s); void operator+= (TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
void operator+= (TMatrix2<T>& m1, const TMatrix2<T>& m2); void operator+= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
void operator-= (TMatrix2<T>& m1, T s); void operator-= (TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
void operator-= (TMatrix2<T>& m1, const TMatrix2<T>& m2); void operator-= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
void operator*= (TMatrix2<T>& m1, T s); void operator*= (TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
void operator*= (TMatrix2<T>& m1, const TMatrix2<T>& m2); void operator*= (TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
TMatrix2<T> operator+ (const TMatrix2<T>& m1, T s); TMatrix2<T> operator+ (const TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
TMatrix2<T> operator+ (const TMatrix2<T>& m1, const TMatrix2<T>& m2); TMatrix2<T> operator+ (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
TMatrix2<T> operator- (const TMatrix2<T>& m1, T s); TMatrix2<T> operator- (const TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
TMatrix2<T> operator- (const TMatrix2<T>& m1, const TMatrix2<T>& m2); TMatrix2<T> operator- (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
TMatrix2<T> operator* (const TMatrix2<T>& m1, T s); TMatrix2<T> operator* (const TMatrix2<T>& m1, T s);
template<RealType T> template<RealType T>
TMatrix2<T> operator* (const TMatrix2<T>& m1, const TMatrix2<T>& m2); TMatrix2<T> operator* (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
template<RealType T> template<RealType T>
TVector2<T> operator* (const TMatrix2<T>& m1, const TVector2<T>& v); TVector2<T> operator* (const TMatrix2<T>& m1, const TVector2<T>& v);
template<RealType T> template<RealType T>
bool operator== (const TMatrix2<T>& m1, const TMatrix2<T>& m2); bool operator== (const TMatrix2<T>& m1, const TMatrix2<T>& m2);
// =============================== // // =============================== //
// Matrix function definition // // Matrix function definition //
// =============================== // // =============================== //
template<RealType T> template<RealType T>
T Determinant(const Matrix2& m1); T Determinant(const Matrix2& m1);
template<RealType T> template<RealType T>
void InverseV(TMatrix2<T>& m1); void InverseV(TMatrix2<T>& m1);
template<RealType T> template<RealType T>
void TransposeV(TMatrix2<T>& m1); void TransposeV(TMatrix2<T>& m1);
// =============== // // =============== //
// WITH RETURN // // WITH RETURN //
// =============== // // =============== //
template<RealType T> template<RealType T>
TMatrix2<T> Inverse(TMatrix2<T>& m1); TMatrix2<T> Inverse(TMatrix2<T>& m1);
template<RealType T> template<RealType T>
TMatrix2<T> Transpose(const TMatrix2<T>& m1); TMatrix2<T> Transpose(const TMatrix2<T>& m1);
template<RealType T> template<RealType T>
bool IsIndentityMatrix(const TMatrix2<T>& m1, T threshold = P_FLT_INAC); bool IsIndentityMatrix(const TMatrix2<T>& m1, T threshold = P_FLT_INAC);
} // Phanes::Core::Math } // Phanes::Core::Math

View File

@ -8,14 +8,16 @@
namespace Phanes::Core::Math { 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<RealType T> template<RealType T>
struct TPlane struct TPlane
{ {
public: public:
TVector3<T> normal; TVector3<T> normal;
T d; T d;
}; };
} // Phanes::Core::Math } // Phanes::Core::Math

View File

@ -20,164 +20,164 @@
namespace Phanes::Core::Math { 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<RealType T> template<RealType T>
struct TPoint2 : public TVector2<T> { struct TPoint2 : public TVector2<T> {
static_assert(std::is_floating_point_v<T>, "T must be a floating point"); static_assert(std::is_floating_point_v<T>, "T must be a floating point");
using TVector2<T>::TVector2; using TVector2<T>::TVector2;
using Real = T; using Real = T;
/** /**
* Creates Point2 from Point3's xy * Creates Point2 from Point3's xy
* *
* @param a Point3 one * @param a Point3 one
*/ */
TPoint2(const TPoint3<T>& p) TPoint2(const TPoint3<T>& p)
{ {
this->x = p.x; this->x = p.x;
this->y = p.y; this->y = p.y;
} }
/** /**
* Creates Point2 from Point4's xy * Creates Point2 from Point4's xy
* *
* @param a Point4 one * @param a Point4 one
*/ */
TPoint2(const TPoint4<T>& p) TPoint2(const TPoint4<T>& p)
{ {
this->x = p.x; this->x = p.x;
this->y = p.y; this->y = p.y;
} }
}; };
/** /**
* Calculates distance between two points. * Calculates distance between two points.
* *
* @param(p1) Point one * @param(p1) Point one
* @param(p2) Point two * @param(p2) Point two
* *
* @return Distance between two points. * @return Distance between two points.
*/ */
template<RealType T> template<RealType T>
T Distance(const TPoint2<T>& p1, const TPoint2<T>& p2); T Distance(const TPoint2<T>& p1, const TPoint2<T>& p2);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* A 3D Point with components x and y with float precision. * A 3D Point with components x and y with float precision.
*/ */
template<RealType T> template<RealType T>
struct TPoint3 : public TVector3<T> { struct TPoint3 : public TVector3<T> {
static_assert(std::is_floating_point_v(T), "T must be a floating point"); static_assert(std::is_floating_point_v(T), "T must be a floating point");
using TVector3<T>::TVector3; using TVector3<T>::TVector3;
using Real = T; using Real = T;
/** /**
* Creates Point3 from Point2's xy and zero * Creates Point3 from Point2's xy and zero
* *
* @param a Point2 one * @param a Point2 one
*/ */
TPoint3(const TPoint2<T>& p) TPoint3(const TPoint2<T>& p)
{ {
this->x = p.x; this->x = p.x;
this->y = p.y; this->y = p.y;
this->z = 0; this->z = 0;
} }
/** /**
* Creates Point3 from Point4's xyz * Creates Point3 from Point4's xyz
* *
* @param a Point4 one * @param a Point4 one
*/ */
TPoint3(const TPoint4<T>& p) TPoint3(const TPoint4<T>& p)
{ {
this->x = p.x; this->x = p.x;
this->y = p.y; this->y = p.y;
this->z = p.z; this->z = p.z;
} }
}; };
/** /**
* Calculates distance between two points. * Calculates distance between two points.
* *
* @param(p1) Point one * @param(p1) Point one
* @param(p2) Point two * @param(p2) Point two
* *
* @return Distance between two points. * @return Distance between two points.
*/ */
template<RealType T> template<RealType T>
T Distance(const TPoint3<T>& p1, const TPoint3<T>& p2); T Distance(const TPoint3<T>& p1, const TPoint3<T>& p2);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* A 4D Point with components x and y with float precision. * A 4D Point with components x and y with float precision.
*/ */
//template<RealType T> //template<RealType T>
//struct TPoint4 : public TVector4<T> { //struct TPoint4 : public TVector4<T> {
// static_assert(std::is_floating_point_v(T), "T must be a floating point"); // static_assert(std::is_floating_point_v(T), "T must be a floating point");
// using TVector4<T>::TVector4; // using TVector4<T>::TVector4;
// /** // /**
// * Creates Point4 from Point2's xy and the last two zero // * Creates Point4 from Point2's xy and the last two zero
// * // *
// * @param a Point2 one // * @param a Point2 one
// */ // */
// TPoint4(const TPoint2<T>& p) // TPoint4(const TPoint2<T>& p)
// { // {
// this->x = p.x; // this->x = p.x;
// this->y = p.y; // this->y = p.y;
// this->z = 0; // this->z = 0;
// this->w = 0; // this->w = 0;
// } // }
// /** // /**
// * Creates Point4 from Point3's xyz and zero // * Creates Point4 from Point3's xyz and zero
// * // *
// * @param a Point3 one // * @param a Point3 one
// */ // */
// TPoint4(const TPoint3<T>& p) // TPoint4(const TPoint3<T>& p)
// { // {
// this->x = p.x; // this->x = p.x;
// this->y = p.y; // this->y = p.y;
// this->z = p.z; // this->z = p.z;
// this->w = 0; // this->w = 0;
// } // }
//}; //};
///** ///**
// * Calculates distance between two points. // * Calculates distance between two points.
// * // *
// * @param(p1) Point one // * @param(p1) Point one
// * @param(p2) Point two // * @param(p2) Point two
// * // *
// * @return Distance between two points. // * @return Distance between two points.
// */ // */
//template<RealType T> //template<RealType T>
//T Distance(const TPoint4<T>& p1, const TPoint4<T>& p2); //T Distance(const TPoint4<T>& p1, const TPoint4<T>& p2);
} // phanes::core::math::coretypes } // phanes::core::math::coretypes

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,9 @@ namespace Phanes::Core::Types
#ifdef P_WIN_BUILD #ifdef P_WIN_BUILD
// MSCV++ specific types // MSCV++ specific types
typedef FLOAT128 float128; typedef FLOAT128 float128;
//#elif P_UNIX_BUILD //#elif P_UNIX_BUILD
// //
@ -27,86 +27,86 @@ namespace Phanes::Core::Types
#endif #endif
// Specific types size // Specific types size
// //
// 8-Bit integer // 8-Bit integer
typedef int8_t int8; typedef int8_t int8;
// 16-Bit integer // 16-Bit integer
typedef int16_t int16; typedef int16_t int16;
// 32-Bit integer // 32-Bit integer
typedef int32_t int32; typedef int32_t int32;
// 64-Bit integer // 64-Bit integer
typedef int64_t int64; typedef int64_t int64;
// 8-Bit unsigned integer // 8-Bit unsigned integer
typedef uint8_t uint8; typedef uint8_t uint8;
// 16-Bit unsigned integer // 16-Bit unsigned integer
typedef uint16_t uint16; typedef uint16_t uint16;
// 32-Bit unsigned integer // 32-Bit unsigned integer
typedef uint32_t uint32; typedef uint32_t uint32;
// 64-Bit unsigned integer // 64-Bit unsigned integer
typedef uint64_t uint64; typedef uint64_t uint64;
// At least N bit types // At least N bit types
// //
// At least 8-Bit integer // At least 8-Bit integer
typedef int_least8_t lint8; typedef int_least8_t lint8;
// At least 16-Bit integer // At least 16-Bit integer
typedef int_least16_t lint16; typedef int_least16_t lint16;
// At least 32-Bit integer // At least 32-Bit integer
typedef int_least32_t lint32; typedef int_least32_t lint32;
// At least 64-Bit integer // At least 64-Bit integer
typedef int_least64_t lint64; typedef int_least64_t lint64;
// At least 8-Bit integer // At least 8-Bit integer
typedef uint_least8_t ulint8; typedef uint_least8_t ulint8;
// At least 16-Bit integer // At least 16-Bit integer
typedef uint_least16_t ulint16; typedef uint_least16_t ulint16;
// At least 32-Bit integer // At least 32-Bit integer
typedef uint_least32_t ulint32; typedef uint_least32_t ulint32;
// At least 64-Bit integer // At least 64-Bit integer
typedef uint_least64_t ulint64; typedef uint_least64_t ulint64;
// Fast N bit types // Fast N bit types
// //
// Fast 8-bit integer // Fast 8-bit integer
typedef int_fast8_t fint8; typedef int_fast8_t fint8;
// At least 16-Bit integer // At least 16-Bit integer
typedef int_fast16_t fint16; typedef int_fast16_t fint16;
// At least 32-Bit integer // At least 32-Bit integer
typedef int_fast32_t fint32; typedef int_fast32_t fint32;
// At least 64-Bit integer // At least 64-Bit integer
typedef int_fast64_t fint64; typedef int_fast64_t fint64;
// At least 8-Bit integer // At least 8-Bit integer
typedef uint_fast8_t ufint8; typedef uint_fast8_t ufint8;
// At least 16-Bit integer // At least 16-Bit integer
typedef uint_fast16_t ufint16; typedef uint_fast16_t ufint16;
// At least 32-Bit integer // At least 32-Bit integer
typedef uint_fast32_t ufint32; typedef uint_fast32_t ufint32;
// At least 64-Bit integer // At least 64-Bit integer
typedef uint_fast64_t ufint64; typedef uint_fast64_t ufint64;
} }

View File

@ -7,11 +7,11 @@ extern Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreateP
int main(int argc, char** argv) 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 #endif

View File

@ -6,26 +6,26 @@
namespace Phanes::Core::Application namespace Phanes::Core::Application
{ {
class PhanesGame class PhanesGame
{ {
public: public:
PhanesGame(); PhanesGame();
virtual ~PhanesGame(); virtual ~PhanesGame();
/** /**
* PhanesEngine main loop. * PhanesEngine main loop.
*/ */
void Run(); void Run();
}; };
/** /**
* Function to be overwriten by client. * Function to be overwriten by client.
*/ */
PhanesGame* CreatePhanesGame(); PhanesGame* CreatePhanesGame();
} }

View File

@ -10,18 +10,18 @@
#include <cmath> #include <cmath>
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include <concepts> #include <concepts>
#include <type_traits> #include <type_traits>
#include <string> #include <string>
#ifdef P_WIN_BUILD #ifdef P_WIN_BUILD
#include <windows.h> #include <windows.h>
#endif #endif
#endif // !PHANES_CORE_PCH_H #endif // !PHANES_CORE_PCH_H

View File

@ -7,5 +7,5 @@ class DevPlayground : public Phanes::Core::Application::PhanesGame {};
Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreatePhanesGame() Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreatePhanesGame()
{ {
return new DevPlayground(); return new DevPlayground();
} }

View File

@ -4,9 +4,9 @@ namespace PMath = Phanes::Core::Math;
int main() int main()
{ {
float t = 2; float t = 2;
PMath::Clamp(t, 2.0f, 4.0f); PMath::Clamp(t, 2.0f, 4.0f);
return 0; return 0;
} }