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_DEBUG
#define P_DEBUGBREAK DebugBreak();
#ifdef P_DEBUG
#define P_DEBUGBREAK DebugBreak();
#else
#define P_DEBUGBREAK
#else
#define P_DEBUGBREAK
#endif // P_DEBUG
#endif // P_DEBUG
#define FORCEINLINE __forceinline
#define FORCEINLINE __forceinline
#elif defined(P_UNIX_BUILD)
#error Only Windows is supported at the moment.
#error Only Windows is supported at the moment.
#elif defined(P_ARM_BUILD)
#error Only Windows is supported at the moment.
#error Only Windows is supported at the moment.
#else
#error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information)
#error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information)
#endif // P_WIN_BUILD

View File

@ -9,7 +9,7 @@
template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2)
{
return Magnitude(p2 - p1);
return Magnitude(p2 - p1);
}
// ----- TIntPoint3 ------------------------------------------
@ -18,5 +18,5 @@ Rt Phanes::Core::Math::Distance(const TIntPoint2<T>& p1, const TIntPoint2<T>& p2
template<IntType T, RealType Rt>
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>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const T x, const T y)
{
this->x = x;
this->y = y;
this->x = x;
this->y = y;
}
template<IntType T>
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.");
memcpy(this->comp, comp, sizeof(T) * 2);
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (IntVector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components.");
memcpy(this->comp, comp, sizeof(T) * 2);
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntPoint2<T>& start, const TIntPoint2<T>& end)
{
this->x = end.x - start.x;
this->y = end.y - start.y;
this->x = end.x - start.x;
this->y = end.y - start.y;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(const TIntVector3<T>& v)
{
this->x = v.x;
this->y = v.y;
this->x = v.x;
this->y = v.y;
}
template<IntType T>
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>
Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v)
{
this->comp = v.comp;
v.comp = nullptr;
this->comp = v.comp;
v.comp = nullptr;
}
@ -71,254 +71,254 @@ Phanes::Core::Math::TIntVector2<T>::TIntVector2(TIntVector2<T>&& v)
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, T s)
{
v1.x += s;
v1.y += s;
v1.x += s;
v1.y += s;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator+=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{
v1.x += v2.x;
v1.y += v2.y;
v1.x += v2.x;
v1.y += v2.y;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, T s)
{
v1.x -= s;
v1.y -= s;
v1.x -= s;
v1.y -= s;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator-=(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{
v1.x -= v2.x;
v1.y -= v2.y;
v1.x -= v2.x;
v1.y -= v2.y;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::operator*=(TIntVector2<T>& v1, T s)
{
v1.x *= s;
v1.y *= s;
v1.x *= s;
v1.y *= s;
return v1;
return v1;
}
template<IntType T>
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>
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>
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>
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>
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>
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>
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>
void Phanes::Core::Math::operator-(TIntVector2<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.x = -v1.x;
v1.y = -v1.y;
}
template<IntType T>
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>
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>
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>
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>
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.y = trunc(v1.y * s);
v1.x = trunc(v1.x * s);
v1.y = trunc(v1.y * s);
return v1;
return v1;
}
template<IntType T, RealType Rt>
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>
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>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::SignVectorV(TIntVector2<T>& v1)
{
v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1;
v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1;
return v1;
return v1;
}
template<IntType T>
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>
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.y = Phanes::Core::Math::Max(v1.y, v2.y);
v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
return v1;
return v1;
}
template<IntType T>
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.y = Phanes::Core::Math::Min(v1.y, v2.y);
v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetPerpendicularV(TIntVector2<T>& v1)
{
T x = v1.x;
v1.x = v1.y;
v1.y = -v1.x;
T x = v1.x;
v1.x = v1.y;
v1.y = -v1.x;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TIntVector2<T>& v1)
{
T x = v1.x;
v1.x = -v1.y;
v1.y = v1.x;
T x = v1.x;
v1.x = -v1.y;
v1.y = v1.x;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::ScaleV(TIntVector2<T>& v1, const TIntVector2<T>& v2)
{
v1.x *= v2.x;
v1.y *= v2.y;
v1.x *= v2.x;
v1.y *= v2.y;
return v1;
return v1;
}
template<IntType T>
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>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::Set(TIntVector2<T>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
v1.x = x;
v1.y = y;
return v1;
return v1;
}
template<IntType T>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::NegateV(TIntVector2<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.x = -v1.x;
v1.y = -v1.y;
}
template<IntType T>
inline bool Phanes::Core::Math::IsNormalized(const TIntVector2<T>& v1)
{
return (SqrMagnitude(v1));
return (SqrMagnitude(v1));
}
template<IntType T>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Normalize(const TIntVector2<T>& v1)
{
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm);
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PIntZeroVector2(T) : (v1 / vecNorm);
}
template<IntType T, RealType Rt>
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>
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>
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);
return v1 * k;
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
return v1 * k;
}
template<IntType T, RealType Rt>
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 k = (prime > radius) ? abs(radius / prime) : 1.0f;
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
return TVector2(v1 * k);
return TVector2(v1 * k);
}
template<IntType T, RealType Rt>
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>
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>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::Rotate(const TIntVector2<T>& v1, Rt angle)
{
float sinAngle = sin(angle);
float cosAngle = cos(angle);
float sinAngle = sin(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>
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>
Phanes::Core::Math::TIntVector2<T> Phanes::Core::Math::DivideTrunc(const TIntVector2<T>& v1, T s)
{
Rt _s = (Rt)1.0 / s;
return TIntVector2<T>(trunc(v1.x * _s), trunc(v1.y * _s));
Rt _s = (Rt)1.0 / s;
return TIntVector2<T>(trunc(v1.x * _s), trunc(v1.y * _s));
}
template<IntType T, RealType Rt>
Phanes::Core::Math::TVector2<Rt> Phanes::Core::Math::DivideFloat(const TIntVector2<T>& v1, T s)
{
Rt _s = (Rt)1.0 / s;
return TIntVector2<T>((Rt)v1.x * _s, (Rt)v1.y * _s);
Rt _s = (Rt)1.0 / 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 //
// ======================================= //
template<IntType T, RealType Rt>
Rt Phanes::Core::Math::Magnitude(const TIntVector3<T>& v1)
{

View File

@ -54,4 +54,4 @@ float Phanes::Core::Math::FastInvSqrt(T n)
n = n * (1.5f - (x2 * n * n));
return n;
}
}

View File

@ -7,26 +7,26 @@
template<RealType T>
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>
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>
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>
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>

View File

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

View File

@ -12,7 +12,7 @@
template<RealType T>
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>
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>
Phanes::Core::Math::TVector2<T>::TVector2(const Real x, const Real y)
{
this->x = x;
this->y = y;
this->x = x;
this->y = y;
}
template<RealType T>
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.");
memcpy(this->comp, comp, sizeof(T) * 2);
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector2.cpp): Setting 2D vector coordinates by an array, comp must have a size of at least 2 components.");
memcpy(this->comp, comp, sizeof(T) * 2);
}
template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const TPoint2<Real>& start, const TPoint2<Real>& end)
{
this->x = end.x - start.x;
this->y = end.y - start.y;
this->x = end.x - start.x;
this->y = end.y - start.y;
}
template<RealType T>
Phanes::Core::Math::TVector2<T>::TVector2(const TVector3<Real>& v)
{
this->x = v.x;
this->y = v.y;
this->x = v.x;
this->y = v.y;
}
template<RealType T>
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>
Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v)
{
this->comp = v.comp;
v.comp = nullptr;
this->comp = v.comp;
v.comp = nullptr;
}
@ -107,340 +107,340 @@ Phanes::Core::Math::TVector2<T>::TVector2(TVector2<Real>&& v)
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, T s)
{
v1.x += s;
v1.y += s;
v1.x += s;
v1.y += s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator+=(TVector2<T>& v1, const TVector2<T>& v2)
{
v1.x += v2.x;
v1.y += v2.y;
v1.x += v2.x;
v1.y += v2.y;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, T s)
{
v1.x -= s;
v1.y -= s;
v1.x -= s;
v1.y -= s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator-=(TVector2<T>& v1, const TVector2<T>& v2)
{
v1.x -= v2.x;
v1.y -= v2.y;
v1.x -= v2.x;
v1.y -= v2.y;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator*=(TVector2<T>& v1, T s)
{
v1.x *= s;
v1.y *= s;
v1.x *= s;
v1.y *= s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/=(TVector2<T>& v1, T s)
{
s = 1.0f / s;
v1.x *= s;
v1.y *= s;
s = 1.0f / s;
v1.x *= s;
v1.y *= s;
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(const TVector2<T>& v1, T s)
{
s = 1.0f / s;
return TVector2<T>(v1.x * s, v1.y * s);
s = 1.0f / s;
return TVector2<T>(v1.x * s, v1.y * s);
}
template<RealType T>
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>
inline Phanes::Core::Math::TVector2<T> Phanes::Core::Math::operator/(T s, const TVector2<T>& v1)
{
s = 1.0f / s;
return v1 * s;
s = 1.0f / s;
return v1 * s;
}
template<RealType T>
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>
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>
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>
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>
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>
void Phanes::Core::Math::operator-(TVector2<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.x = -v1.x;
v1.y = -v1.y;
}
template<RealType T>
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>
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>
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>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NormalizeV(TVector2<T>& v1)
{
float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
return v1;
float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
return v1;
}
template<RealType T>
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>
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>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::SignVectorV(TVector2<T>& v1)
{
v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1;
v1.x = (v1.x > 0) ? 1 : -1;
v1.y = (v1.y > 0) ? 1 : -1;
return v1;
return v1;
}
template<RealType T>
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);
v1 *= k;
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
v1 *= k;
return v1;
return v1;
}
template<RealType T>
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 k = (prime > radius) ? abs(radius / prime) : 1.0f;
v1 *= k;
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
v1 *= k;
return v1;
return v1;
}
template<RealType T>
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>
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.y = Phanes::Core::Math::Max(v1.y, v2.y);
v1.x = Phanes::Core::Math::Max(v1.x, v2.x);
v1.y = Phanes::Core::Math::Max(v1.y, v2.y);
return v1;
return v1;
}
template<RealType T>
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.y = Phanes::Core::Math::Min(v1.y, v2.y);
v1.x = Phanes::Core::Math::Min(v1.x, v2.x);
v1.y = Phanes::Core::Math::Min(v1.y, v2.y);
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetPerpendicularV(TVector2<T>& v1)
{
T x = v1.x;
v1.x = v1.y;
v1.y = -v1.x;
T x = v1.x;
v1.x = v1.y;
v1.y = -v1.x;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::GetReversePerpendicularV(TVector2<T>& v1)
{
T x = v1.x;
v1.x = -v1.y;
v1.y = v1.x;
T x = v1.x;
v1.x = -v1.y;
v1.y = v1.x;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::ScaleV(TVector2<T>& v1, const TVector2<T>& v2)
{
v1.x *= v2.x;
v1.y *= v2.y;
v1.x *= v2.x;
v1.y *= v2.y;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::CompInverseV(TVector2<T>& v1)
{
v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y;
return v1;
v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y;
return v1;
}
template<RealType T>
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>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Set(TVector2<T>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
v1.x = x;
v1.y = y;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::RotateV(TVector2<T>& v1, T angle)
{
float sinAngle = sin(angle);
float cosAngle = cos(angle);
float sinAngle = sin(angle);
float cosAngle = cos(angle);
Set(v1,
v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle
);
Set(v1,
v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle
);
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::NegateV(TVector2<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.x = -v1.x;
v1.y = -v1.y;
}
template<RealType T>
inline bool Phanes::Core::Math::IsNormalized(const TVector2<T>& v1, T threshold)
{
return (SqrMagnitude(v1) < threshold);
return (SqrMagnitude(v1) < threshold);
}
template<RealType T>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Normalize(const TVector2<T>& v1)
{
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm);
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm);
}
template<RealType T>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::UnsafeNormalize(const TVector2<T>& v1)
{
return (v1 / Magnitude(v1));
return (v1 / Magnitude(v1));
}
template<RealType T>
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>
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);
return v1 * k;
float k = (abs(v1.x) > abs(v1.y)) ? abs(radius / v1.x) : abs(radius / v1.y);
return v1 * k;
}
template<RealType T>
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 k = (prime > radius) ? abs(radius / prime) : 1.0f;
float prime = (abs(v1.x) > abs(v1.y)) ? v1.x : v1.y;
float k = (prime > radius) ? abs(radius / prime) : 1.0f;
return v1 * k;
return v1 * k;
}
template<RealType 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);
return (t * destVec) + ((1 - t) * startVec);
t = Phanes::Core::Math::Clamp(t, (T)0.0, (T)1.0);
return (t * destVec) + ((1 - t) * startVec);
}
template<RealType 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>
Phanes::Core::Math::TVector2<T> Phanes::Core::Math::Rotate(const TVector2<T>& v1, T angle)
{
float sinAngle = sin(angle);
float cosAngle = cos(angle);
float sinAngle = sin(angle);
float cosAngle = cos(angle);
return TVector2<T>(v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle);
return TVector2<T>(v1.x * cosAngle - v1.y * sinAngle,
v1.y * cosAngle + v1.x * sinAngle);
}
template<RealType T>
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>
inline Phanes::Core::Math::TVector3<T>::TVector3(const Real x, const Real y, const Real z)
{
this->x = x;
this->y = y;
this->z = z;
this->x = x;
this->y = y;
this->z = z;
}
template<RealType T>
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.");
memcpy(this->comp, comp, sizeof(T) * 3);
static_assert(sizeof(comp) > 2 * sizeof(T), "PHANES_CORE (Vector3.cpp): Setting 3D vector coordinates by an array, comp must have a size of at least 3 components.");
memcpy(this->comp, comp, sizeof(T) * 3);
}
template<RealType T>
Phanes::Core::Math::TVector3<T>::TVector3(const TPoint3<T>& start, const TPoint3<T>& end)
{
this->x = end.x - start.x;
this->y = end.y - start.y;
this->z = end.z - start.z;
this->x = end.x - start.x;
this->y = end.y - start.y;
this->z = end.z - start.z;
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v)
{
this->comp = v.comp;
v.comp = nullptr;
this->comp = v.comp;
v.comp = nullptr;
}
@ -55,139 +55,139 @@ Phanes::Core::Math::TVector3<T>::TVector3(TVector3<Real>&& v)
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, T s)
{
v1.x += s;
v1.y += s;
v1.z += s;
v1.x += s;
v1.y += s;
v1.z += s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator+=(TVector3<T>& v1, const TVector3<T>& v2)
{
v1.x += v2.x;
v1.y += v2.y;
v1.z += v2.z;
v1.x += v2.x;
v1.y += v2.y;
v1.z += v2.z;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, T s)
{
v1.x -= s;
v1.y -= s;
v1.z -= s;
v1.x -= s;
v1.y -= s;
v1.z -= s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-=(TVector3<T>& v1, const TVector3<T>& v2)
{
v1.x -= v2.x;
v1.y -= v2.y;
v1.z -= v2.z;
v1.x -= v2.x;
v1.y -= v2.y;
v1.z -= v2.z;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*=(TVector3<T>& v1, T s)
{
v1.x *= s;
v1.y *= s;
v1.z *= s;
v1.x *= s;
v1.y *= s;
v1.z *= s;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/=(TVector3<T>& v1, T s)
{
s = (T)1.0 / s;
v1.x *= s;
v1.y *= s;
v1.z *= s;
s = (T)1.0 / s;
v1.x *= s;
v1.y *= s;
v1.z *= s;
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(const TVector3<T>& v1, T s)
{
s = (T)1.0 / s;
return TVector3<T>(v1.x * s.v1.y * s, v1.z * s);
s = (T)1.0 / s;
return TVector3<T>(v1.x * s.v1.y * s, v1.z * s);
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator*(T s, const TVector3<T>& v1)
{
return v1 * s;
return v1 * s;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator/(T s, const TVector3<T>& v1)
{
return v1 / s;
return v1 / s;
}
template<RealType T>
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>
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>
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>
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>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::operator-(TVector3<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.z = -v1.z;
v1.x = -v1.x;
v1.y = -v1.y;
v1.z = -v1.z;
return v1;
return v1;
}
template<RealType T>
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>
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>
T Phanes::Core::Math::Magnitude(const TVector3<T>& v1)
{
return sqrt(DotP(v1, v1));
return sqrt(DotP(v1, v1));
}
template<RealType T>
T Phanes::Core::Math::SqrMagnitude(const TVector3<T>& v1)
{
return DotP(v1, v1);
return DotP(v1, v1);
}
template<RealType T>
T Phanes::Core::Math::SqrLength(const TVector3<T>& v1)
{
return SqrMagnitude(v1);
return SqrMagnitude(v1);
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NormalizeV(TVector3<T>& v1)
{
float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
float vecNorm = Magnitude(v1);
v1 /= (vecNorm < P_FLT_INAC) ? 1 : vecNorm;
return v1;
return v1;
}
template<RealType T>
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>
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>
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>
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>
void Phanes::Core::Math::Orthogonalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
{
Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2));
Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2));
}
template<RealType T>
void Phanes::Core::Math::OrthoNormalize(TVector3<T>& v1, TVector3<T>& v2, TVector3<T>& v3)
{
Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2));
Set(v2, Reject(v2, v1));
Set(v3, Reject(Reject(v3, v1), v2));
NormalizeV(v1);
NormalizeV(v2);
NormalizeV(v3);
NormalizeV(v1);
NormalizeV(v2);
NormalizeV(v3);
}
template<RealType T>
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>
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>
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>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxis(const TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
{
T sinAngle = sin(angle);
T cosAngle = cos(angle);
T sinAngle = sin(angle);
T cosAngle = cos(angle);
return (1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal);
return (1 - cosAngle) * DotP(v1, axisNormal) * axisNormal + cosAngle * v1 + sinAngle * CrossP(v1, axisNormal);
}
template<RealType T>
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>
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>
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>
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>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVector(const TVector3<T>& v1)
{
v1.x = (v1.x > 0) - (v1.x < 0);
v1.y = (v1.y > 0) - (v1.y < 0);
v1.z = (v1.z > 0) - (v1.z < 0);
v1.x = (v1.x > 0) - (v1.x < 0);
v1.y = (v1.y > 0) - (v1.y < 0);
v1.z = (v1.z > 0) - (v1.z < 0);
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivideV(TVector3<T>& v1)
{
float _z = (T)1.0 / v1.z;
v1.x *= _z;
v1.y *= _z;
v1.z = (T)0.0;
return v1;
float _z = (T)1.0 / v1.z;
v1.x *= _z;
v1.y *= _z;
v1.z = (T)0.0;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CrossPV(TVector3<T>& v1, const TVector3<T>& v2)
{
float x = v1.x;
float y = v1.y;
float z = v1.z;
float x = v1.x;
float y = v1.y;
float z = v1.z;
v1.x = (y * v2.z) - (z * v2.y);
v1.y = (z * v2.x) - (x * v2.z);
v1.z = (x * v2.y) - (y * v2.x);
v1.x = (y * v2.z) - (z * v2.y);
v1.y = (z * v2.x) - (x * v2.z);
v1.z = (x * v2.y) - (y * v2.x);
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MaxV(TVector3<T>& v1, const TVector3<T>& v2)
{
v1.x = Max(v1.x, v2.x);
v1.y = Max(v1.y, v2.y);
v1.z = Max(v1.z, v2.z);
v1.x = Max(v1.x, v2.x);
v1.y = Max(v1.y, v2.y);
v1.z = Max(v1.z, v2.z);
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::MinV(TVector3<T>& v1, const TVector3<T>& v2)
{
v1.x = Min(v1.x, v2.x);
v1.y = Min(v1.y, v2.y);
v1.z = Min(v1.z, v2.z);
v1.x = Min(v1.x, v2.x);
v1.y = Min(v1.y, v2.y);
v1.z = Min(v1.z, v2.z);
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::NegateV(TVector3<T>& v1)
{
v1.x = -v1.x;
v1.y = -v1.y;
v1.z = -v1.z;
v1.x = -v1.x;
v1.y = -v1.y;
v1.z = -v1.z;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ScaleV(TVector3<T>& v1, const TVector3<T>& v2)
{
v1.x *= v2.x;
v1.y *= v2.y;
v1.z *= v2.z;
v1.x *= v2.x;
v1.y *= v2.y;
v1.z *= v2.z;
return v1;
return v1;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::ProjectV(TVector3<T>& v1, const TVector3<T>& v2)
{
float x = (v1 * v2) / (v2 * v2);
v1 = x * v2;
float x = (v1 * v2) / (v2 * v2);
v1 = x * v2;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RejectV(TVector3<T>& v1, const TVector3<T>& v2)
{
float x = (v1 * v2) / (v2 * v2);
v1 -= x * v2;
float x = (v1 * v2) / (v2 * v2);
v1 -= x * v2;
return v1;
return v1;
}
template<RealType T>
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>
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>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Set(TVector3<T>& v1, T x, T y, T z)
{
v1.x = x;
v1.y = y;
v1.z = z;
v1.x = x;
v1.y = y;
v1.z = z;
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::CompInverseV(TVector3<T>& v1)
{
v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y;
v1.z = 1.0f / v1.z;
v1.x = 1.0f / v1.x;
v1.y = 1.0f / v1.y;
v1.z = 1.0f / v1.z;
return v1;
return v1;
}
template<RealType T>
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>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::RotateAroundAxisV(TVector3<T>& v1, const TVector3<T>& axisNormal, T angle)
{
T sinAngle = sin(angle);
T cosAngle = cos(angle);
T sinAngle = sin(angle);
T cosAngle = cos(angle);
v1 = ((T)1.0 - cosAngle) * DotP(axisNormal, v1) * axisNormal + cosAngle * v1 + sinAngle * CrossP(axisNormal, v1);
v1 = ((T)1.0 - cosAngle) * DotP(axisNormal, v1) * axisNormal + cosAngle * v1 + sinAngle * CrossP(axisNormal, v1);
return v1;
return v1;
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::SignVectorV(TVector3<T>& v1)
{
v1.x = (v1.x > 0) ? 1 : 0;
v1.y = (v1.y > 0) ? 1 : 0;
v1.z = (v1.z > 0) ? 1 : 0;
v1.x = (v1.x > 0) ? 1 : 0;
v1.y = (v1.y > 0) ? 1 : 0;
v1.z = (v1.z > 0) ? 1 : 0;
return v1;
return v1;
}
template<RealType T>
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>
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>
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>
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>
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>
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>
bool Phanes::Core::Math::IsNormalized(const TVector3<T>& v1, T threshold)
{
return (SqrMagnitude(v1) < threshold);
return (SqrMagnitude(v1) < threshold);
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::Normalize(const TVector3<T>& v1)
{
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
}
template<RealType T>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::UnsafeNormalize(const TVector3<T>& v1)
{
return v1 / Magnitude(v1);
return v1 / Magnitude(v1);
}
template<RealType T>
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>
Phanes::Core::Math::TVector3<T> Phanes::Core::Math::PerspectiveDivide(const TVector3<T>& v1)
{
float _z = (T)1.0 / v1.z;
return TVector3<T>(v1.x * _z, v1.y * _z, (T)0.0);
float _z = (T)1.0 / v1.z;
return TVector3<T>(v1.x * _z, v1.y * _z, (T)0.0);
}
template<RealType T>
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),
(v1.z * v2.x) - (v1.x * v2.z),
(v1.x * v2.y) - (v1.y * v2.x));
return TVector3<T>((v1.y * v2.z) - (v1.z * v2.y),
(v1.z * v2.x) - (v1.x * v2.z),
(v1.x * v2.y) - (v1.y * v2.x));
}
template<RealType 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);
return (1 - t) * start + t * dest;
t = Clamp(t, (T)0.0, (T), 1.0);
return (1 - t) * start + t * dest;
}
template<RealType 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>
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,
(v1.y > v2.y) ? v1.y : v2.y,
(v1.z > v2.z) ? v1.z : v2.z);
return TVector3<T>((v1.x > v2.x) ? v1.x : v2.x,
(v1.y > v2.y) ? v1.y : v2.y,
(v1.z > v2.z) ? v1.z : v2.z);
}
template<RealType T>
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,
(v1.y < v2.y) ? v1.y : v2.y,
(v1.z < v2.z) ? v1.z : v2.z);
return TVector3<T>((v1.x < v2.x) ? v1.x : v2.x,
(v1.y < v2.y) ? v1.y : v2.y,
(v1.z < v2.z) ? v1.z : v2.z);
}
template<RealType T>
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>
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>
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()
{
while (true);
while (true);
}

View File

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

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 {
template <typename T, unsigned int D = 3>
struct AVector {
public:
template <typename T, unsigned int D = 3>
struct AVector {
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>
struct AMatrix {
public:
T fields[n][m];
template <typename T, unsigned int n = 3, unsigned int m = 3>
struct AMatrix {
public:
T fields[n][m];
};
};
}; // Phanes::Core::Math::abstract::coretypes

View File

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

View File

@ -18,85 +18,85 @@
namespace Phanes::Core::Math {
/**
* Template forward declarations.
*/
/**
* Template forward declarations.
*/
template<RealType T> struct TColor;
template<RealType T> struct TLinearColor;
template<RealType T> struct TColor;
template<RealType T> struct TLinearColor;
template<RealType T> struct TVector2;
template<RealType T> struct TVector3;
template<RealType T> struct TVector4;
template<RealType T> struct TRay;
template<RealType T> struct TPlane;
template<RealType T> struct TMatrix2;
template<RealType T> struct TMatrix3;
template<RealType T> struct TMatrix4;
template<RealType T> struct TQuaternion;
template<RealType T> struct TTransform;
template<RealType T> struct TPoint2;
template<RealType T> struct TPoint3;
template<RealType T> struct TPoint4;
template<IntType T> struct TIntVector2;
template<IntType T> struct TIntVector3;
template<IntType T> struct TIntVector4;
template<IntType T> struct TIntPoint2;
template<IntType T> struct TIntPoint3;
template<IntType T> struct TIntPoint4;
template<RealType T> struct TVector3;
template<RealType T> struct TVector4;
template<RealType T> struct TRay;
template<RealType T> struct TPlane;
template<RealType T> struct TMatrix2;
template<RealType T> struct TMatrix3;
template<RealType T> struct TMatrix4;
template<RealType T> struct TQuaternion;
template<RealType T> struct TTransform;
template<RealType T> struct TPoint2;
template<RealType T> struct TPoint3;
template<RealType T> struct TPoint4;
template<IntType T> struct TIntVector2;
template<IntType T> struct TIntVector3;
template<IntType T> struct TIntVector4;
template<IntType T> struct TIntPoint2;
template<IntType T> struct TIntPoint3;
template<IntType T> struct TIntPoint4;
/**
* Specific instantiation of forward declarations.
*/
/**
* Specific instantiation of forward declarations.
*/
// TVector2
typedef TVector2<float> Vector2;
typedef TVector2<double> Vector2d;
// TVector2
typedef TVector2<float> Vector2;
typedef TVector2<double> Vector2d;
typedef std::vector<Vector2> Vector2List;
typedef std::vector<Vector2d> Vector2Listd;
typedef std::vector<Vector2> Vector2List;
typedef std::vector<Vector2d> Vector2Listd;
// TVector3
typedef TVector3<float> Vector3;
typedef TVector3<double> Vector3d;
// TVector3
typedef TVector3<float> Vector3;
typedef TVector3<double> Vector3d;
typedef std::vector<Vector3> Vector3List;
typedef std::vector<Vector3d> Vector3Listd;
typedef std::vector<Vector3> Vector3List;
typedef std::vector<Vector3d> Vector3Listd;
// TIntVector2
typedef TIntVector2<int> IntVector2;
typedef TIntVector2<long> IntVector2l;
// TIntVector2
typedef TIntVector2<int> IntVector2;
typedef TIntVector2<long> IntVector2l;
typedef std::vector<IntVector2> IntVector2List;
typedef std::vector<IntVector2l> IntVector2Listl;
typedef std::vector<IntVector2> IntVector2List;
typedef std::vector<IntVector2l> IntVector2Listl;
// TIntVector3
typedef TIntVector3<int> IntVector3;
typedef TIntVector3<long> IntVector3l;
// TIntVector3
typedef TIntVector3<int> IntVector3;
typedef TIntVector3<long> IntVector3l;
typedef std::vector<IntVector3> IntVector3List;
typedef std::vector<IntVector3l> IntVector3Listl;
typedef std::vector<IntVector3> IntVector3List;
typedef std::vector<IntVector3l> IntVector3Listl;
// TMatrix2
typedef TMatrix2<float> Matrix2;
typedef TMatrix2<double> Matrix2d;
// TMatrix2
typedef TMatrix2<float> Matrix2;
typedef TMatrix2<double> Matrix2d;
typedef std::vector<Matrix2> Matrix2List;
typedef std::vector<Matrix2d> Matrix2Listd;
typedef std::vector<Matrix2> Matrix2List;
typedef std::vector<Matrix2d> Matrix2Listd;
} // Phanes::Core::Math::coretypes
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 {
// =================================================== //
// std::to_string wrapper //
// //
// This is, to make using ToString more general //
// and allow usage of one function instead of two, //
// for converting a mathmatical type to a string. //
// =================================================== //
// =================================================== //
// std::to_string wrapper //
// //
// This is, to make using ToString more general //
// and allow usage of one function instead of two, //
// for converting a mathmatical type to a string. //
// =================================================== //
FORCEINLINE std::string ToString(long long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(long long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(double val) { return std::to_string(val); };
FORCEINLINE std::string ToString(double val) { return std::to_string(val); };
FORCEINLINE std::string ToString(float val) { return std::to_string(val); };
FORCEINLINE std::string ToString(float val) { return std::to_string(val); };
FORCEINLINE std::string ToString(int val) { return std::to_string(val); };
FORCEINLINE std::string ToString(int val) { return std::to_string(val); };
FORCEINLINE std::string ToString(long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(long double val) { return std::to_string(val); };
FORCEINLINE std::string ToString(long double val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned long long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned long long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned int val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned int val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned long val) { return std::to_string(val); };
FORCEINLINE std::string ToString(unsigned long val) { return std::to_string(val); };
// ============ //
// ToString //
// ============ //
// ============ //
// ToString //
// ============ //
template<RealType T>
std::string ToString(const TVector2<T>& v);
template<RealType T>
std::string ToString(const TVector2<T>& v);
template<IntType T>
std::string ToString(const TIntVector2<T>& v);
template<IntType T>
std::string ToString(const TIntVector2<T>& v);
template<RealType T>
std::string ToString(const TVector3<T>& v);
template<RealType T>
std::string ToString(const TVector3<T>& v);
template<IntType T>
std::string ToString(const TIntVector3<T>& v);
template<IntType T>
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
{
/**
* Converts degrees to radians.
*
* @param(deg) Angle in degress (°)
*
* @return Angle in radians
*/
/**
* Converts degrees to radians.
*
* @param(deg) Angle in degress (°)
*
* @return Angle in radians
*/
template<RealType T>
inline T DegToRad(T deg);
template<RealType T>
inline T DegToRad(T deg);
/**
* Converts radians to degrees.
*
* @param(rad) Angle in radians (rad)
*
* @return Angle in degrees
*/
/**
* Converts radians to degrees.
*
* @param(rad) Angle in radians (rad)
*
* @return Angle in degrees
*/
template<RealType T>
inline T RadToDeg(T rad);
template<RealType T>
inline T RadToDeg(T rad);
/**
* Converts degrees to gradian.
*
* @param(deg) Angle in degress (°)
*
* @return Angle in gradian
*/
/**
* Converts degrees to gradian.
*
* @param(deg) Angle in degress (°)
*
* @return Angle in gradian
*/
template<RealType T>
inline T DegToGradian(T deg);
template<RealType T>
inline T DegToGradian(T deg);
/**
* Converts gradian to degrees.
*
* @param(rad) Angle in gradians (g)
*
* @return Angle in degrees
*/
/**
* Converts gradian to degrees.
*
* @param(rad) Angle in gradians (g)
*
* @return Angle in degrees
*/
template<RealType T>
inline T GradianToDeg(T g);
template<RealType T>
inline T GradianToDeg(T g);
/**
* Converts radians to gradians.
*
* @param(deg) Angle in radians (rad)
*
* @return Angle in gradians
*/
/**
* Converts radians to gradians.
*
* @param(deg) Angle in radians (rad)
*
* @return Angle in gradians
*/
template<RealType T>
inline T RadToGradian(T rad);
template<RealType T>
inline T RadToGradian(T rad);
/**
* Converts gradian to radians.
*
* @param(rad) Angle in gradians (g)
*
* @return Angle in radians
*/
/**
* Converts gradian to radians.
*
* @param(rad) Angle in gradians (g)
*
* @return Angle in radians
*/
template<RealType T>
inline T GradianToRad(T g);
template<RealType T>
inline T GradianToRad(T g);
} // phanes::core::math::typeconversion
namespace Phanes::Core::Math::UnitLiterals
{
// ============================================== //
// unit conversion with user-defined literals //
// ============================================== //
// ============================================== //
// unit conversion with user-defined literals //
// ============================================== //
/**
* Convert deg to rad.
*
* @param(_x) Angle in degress
*/
/**
* Convert deg to rad.
*
* @param(_x) Angle in degress
*/
double operator ""_deg(long double _x)
{
return _x * P_PI_180_FLT;
}
double operator ""_deg(long double _x)
{
return _x * P_PI_180_FLT;
}
/**
* Convert rad to rad.
*
* @param(_x) Angle in degress
*/
/**
* Convert rad to rad.
*
* @param(_x) Angle in degress
*/
double operator ""_rad(long double _x)
{
return _x;
}
double operator ""_rad(long double _x)
{
return _x;
}
/**
* Convert gradian to rad.
*
* @param(_x) Angle in degress
*/
/**
* Convert gradian to rad.
*
* @param(_x) Angle in degress
*/
double operator ""_g(long double _x)
{
return _x * P_PI_FLT / 200;
}
double operator ""_g(long double _x)
{
return _x * P_PI_FLT / 200;
}
}

View File

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

View File

@ -8,14 +8,16 @@
namespace Phanes::Core::Math {
// Plane in 3D space, defined as: P: ax + by + cz = d;
// Plane in 3D space, defined as: P: ax + by + cz = d;
template<RealType T>
struct TPlane
{
public:
TVector3<T> normal;
T d;
};
template<RealType T>
struct TPlane
{
public:
TVector3<T> normal;
T d;
};
} // Phanes::Core::Math
} // Phanes::Core::Math

View File

@ -20,164 +20,164 @@
namespace Phanes::Core::Math {
/**
* A 2D Point with components x and y with float precision.
*/
/**
* A 2D Point with components x and y with float precision.
*/
template<RealType T>
struct TPoint2 : public TVector2<T> {
static_assert(std::is_floating_point_v<T>, "T must be a floating point");
template<RealType T>
struct TPoint2 : public TVector2<T> {
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
*
* @param a Point3 one
*/
/**
* Creates Point2 from Point3's xy
*
* @param a Point3 one
*/
TPoint2(const TPoint3<T>& p)
{
this->x = p.x;
this->y = p.y;
}
TPoint2(const TPoint3<T>& p)
{
this->x = p.x;
this->y = p.y;
}
/**
* Creates Point2 from Point4's xy
*
* @param a Point4 one
*/
/**
* Creates Point2 from Point4's xy
*
* @param a Point4 one
*/
TPoint2(const TPoint4<T>& p)
{
this->x = p.x;
this->y = p.y;
}
};
TPoint2(const TPoint4<T>& p)
{
this->x = p.x;
this->y = p.y;
}
};
/**
* Calculates distance between two points.
*
* @param(p1) Point one
* @param(p2) Point two
*
* @return Distance between two points.
*/
/**
* Calculates distance between two points.
*
* @param(p1) Point one
* @param(p2) Point two
*
* @return Distance between two points.
*/
template<RealType T>
T Distance(const TPoint2<T>& p1, const TPoint2<T>& p2);
template<RealType T>
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>
struct TPoint3 : public TVector3<T> {
static_assert(std::is_floating_point_v(T), "T must be a floating point");
template<RealType T>
struct TPoint3 : public TVector3<T> {
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
*
* @param a Point2 one
*/
/**
* Creates Point3 from Point2's xy and zero
*
* @param a Point2 one
*/
TPoint3(const TPoint2<T>& p)
{
this->x = p.x;
this->y = p.y;
this->z = 0;
}
TPoint3(const TPoint2<T>& p)
{
this->x = p.x;
this->y = p.y;
this->z = 0;
}
/**
* Creates Point3 from Point4's xyz
*
* @param a Point4 one
*/
/**
* Creates Point3 from Point4's xyz
*
* @param a Point4 one
*/
TPoint3(const TPoint4<T>& p)
{
this->x = p.x;
this->y = p.y;
this->z = p.z;
}
};
TPoint3(const TPoint4<T>& p)
{
this->x = p.x;
this->y = p.y;
this->z = p.z;
}
};
/**
* Calculates distance between two points.
*
* @param(p1) Point one
* @param(p2) Point two
*
* @return Distance between two points.
*/
/**
* Calculates distance between two points.
*
* @param(p1) Point one
* @param(p2) Point two
*
* @return Distance between two points.
*/
template<RealType T>
T Distance(const TPoint3<T>& p1, const TPoint3<T>& p2);
template<RealType T>
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>
//struct TPoint4 : public TVector4<T> {
// static_assert(std::is_floating_point_v(T), "T must be a floating point");
//template<RealType T>
//struct TPoint4 : public TVector4<T> {
// 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
// *
// * @param a Point2 one
// */
// /**
// * Creates Point4 from Point2's xy and the last two zero
// *
// * @param a Point2 one
// */
// TPoint4(const TPoint2<T>& p)
// {
// this->x = p.x;
// this->y = p.y;
// this->z = 0;
// this->w = 0;
// }
// TPoint4(const TPoint2<T>& p)
// {
// this->x = p.x;
// this->y = p.y;
// this->z = 0;
// this->w = 0;
// }
// /**
// * Creates Point4 from Point3's xyz and zero
// *
// * @param a Point3 one
// */
// /**
// * Creates Point4 from Point3's xyz and zero
// *
// * @param a Point3 one
// */
// TPoint4(const TPoint3<T>& p)
// {
// this->x = p.x;
// this->y = p.y;
// this->z = p.z;
// this->w = 0;
// }
//};
// TPoint4(const TPoint3<T>& p)
// {
// this->x = p.x;
// this->y = p.y;
// this->z = p.z;
// this->w = 0;
// }
//};
///**
// * Calculates distance between two points.
// *
// * @param(p1) Point one
// * @param(p2) Point two
// *
// * @return Distance between two points.
// */
///**
// * Calculates distance between two points.
// *
// * @param(p1) Point one
// * @param(p2) Point two
// *
// * @return Distance between two points.
// */
//template<RealType T>
//T Distance(const TPoint4<T>& p1, const TPoint4<T>& p2);
//template<RealType T>
//T Distance(const TPoint4<T>& p1, const TPoint4<T>& p2);
} // 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
// MSCV++ specific types
// MSCV++ specific types
typedef FLOAT128 float128;
typedef FLOAT128 float128;
//#elif P_UNIX_BUILD
//
@ -27,86 +27,86 @@ namespace Phanes::Core::Types
#endif
// Specific types size
//
// 8-Bit integer
typedef int8_t int8;
// Specific types size
//
// 8-Bit integer
typedef int8_t int8;
// 16-Bit integer
typedef int16_t int16;
// 16-Bit integer
typedef int16_t int16;
// 32-Bit integer
typedef int32_t int32;
// 32-Bit integer
typedef int32_t int32;
// 64-Bit integer
typedef int64_t int64;
// 64-Bit integer
typedef int64_t int64;
// 8-Bit unsigned integer
typedef uint8_t uint8;
// 8-Bit unsigned integer
typedef uint8_t uint8;
// 16-Bit unsigned integer
typedef uint16_t uint16;
// 16-Bit unsigned integer
typedef uint16_t uint16;
// 32-Bit unsigned integer
typedef uint32_t uint32;
// 32-Bit unsigned integer
typedef uint32_t uint32;
// 64-Bit unsigned integer
typedef uint64_t uint64;
// 64-Bit unsigned integer
typedef uint64_t uint64;
// At least N bit types
//
// At least 8-Bit integer
typedef int_least8_t lint8;
// At least N bit types
//
// At least 8-Bit integer
typedef int_least8_t lint8;
// At least 16-Bit integer
typedef int_least16_t lint16;
// At least 16-Bit integer
typedef int_least16_t lint16;
// At least 32-Bit integer
typedef int_least32_t lint32;
// At least 32-Bit integer
typedef int_least32_t lint32;
// At least 64-Bit integer
typedef int_least64_t lint64;
// At least 64-Bit integer
typedef int_least64_t lint64;
// At least 8-Bit integer
typedef uint_least8_t ulint8;
// At least 8-Bit integer
typedef uint_least8_t ulint8;
// At least 16-Bit integer
typedef uint_least16_t ulint16;
// At least 16-Bit integer
typedef uint_least16_t ulint16;
// At least 32-Bit integer
typedef uint_least32_t ulint32;
// At least 32-Bit integer
typedef uint_least32_t ulint32;
// At least 64-Bit integer
typedef uint_least64_t ulint64;
// At least 64-Bit integer
typedef uint_least64_t ulint64;
// Fast N bit types
//
// Fast 8-bit integer
typedef int_fast8_t fint8;
// Fast N bit types
//
// Fast 8-bit integer
typedef int_fast8_t fint8;
// At least 16-Bit integer
typedef int_fast16_t fint16;
// At least 16-Bit integer
typedef int_fast16_t fint16;
// At least 32-Bit integer
typedef int_fast32_t fint32;
// At least 32-Bit integer
typedef int_fast32_t fint32;
// At least 64-Bit integer
typedef int_fast64_t fint64;
// At least 64-Bit integer
typedef int_fast64_t fint64;
// At least 8-Bit integer
typedef uint_fast8_t ufint8;
// At least 8-Bit integer
typedef uint_fast8_t ufint8;
// At least 16-Bit integer
typedef uint_fast16_t ufint16;
// At least 16-Bit integer
typedef uint_fast16_t ufint16;
// At least 32-Bit integer
typedef uint_fast32_t ufint32;
// At least 32-Bit integer
typedef uint_fast32_t ufint32;
// At least 64-Bit integer
typedef uint_fast64_t ufint64;
// At least 64-Bit integer
typedef uint_fast64_t ufint64;
}

View File

@ -7,11 +7,11 @@ extern Phanes::Core::Application::PhanesGame* Phanes::Core::Application::CreateP
int main(int argc, char** argv)
{
auto phanes_game = Phanes::Core::Application::CreatePhanesGame();
auto phanes_game = Phanes::Core::Application::CreatePhanesGame();
phanes_game->Run();
phanes_game->Run();
delete phanes_game;
delete phanes_game;
}
#endif

View File

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

View File

@ -6,22 +6,22 @@
#define NOMAXMIN
#ifndef PHANES_CORE_PCH_H
#include <cmath>
#include <stdint.h>
#include <vector>
#include <concepts>
#include <type_traits>
#include <string>
#include <cmath>
#include <stdint.h>
#include <vector>
#include <concepts>
#include <type_traits>
#include <string>
#ifdef P_WIN_BUILD
#ifdef P_WIN_BUILD
#include <windows.h>
#include <windows.h>
#endif
#endif
#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()
{
return new DevPlayground();
return new DevPlayground();
}

View File

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