Exclude private/Math.
This commit is contained in:
parent
5b13eeec40
commit
e0f6cf1fa0
Engine/src/Runtime/Core/private/Math
303
Engine/src/Runtime/Core/private/Math/Matrix3.cpp
Normal file
303
Engine/src/Runtime/Core/private/Math/Matrix3.cpp
Normal file
@ -0,0 +1,303 @@
|
||||
// ========================== //
|
||||
// Matrix3 implementation //
|
||||
// ========================== //
|
||||
|
||||
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Matrix3.h"
|
||||
|
||||
// ================================= //
|
||||
// Class Methods for easy access //
|
||||
// ================================= //
|
||||
|
||||
float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m)
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m)
|
||||
{
|
||||
return (*reinterpret_cast<Vector3*>(this->fields[m]));
|
||||
}
|
||||
|
||||
const float& phanes::core::math::coretypes::Matrix3::operator()(int n, int m) const
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
const phanes::core::math::coretypes::Vector3& phanes::core::math::coretypes::Matrix3::operator[](int m) const
|
||||
{
|
||||
return (*reinterpret_cast<const Vector3*>(this->fields[m]));
|
||||
}
|
||||
|
||||
|
||||
// ================= //
|
||||
// Constructors //
|
||||
// ================= //
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float fields[3][3])
|
||||
{
|
||||
Matrix3 a;
|
||||
std::copy(&fields[0][0], &fields[3][3], &a.fields[0][0]);
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f02, float f10, float f11, float f12, float f20, float f21, float f22)
|
||||
{
|
||||
Matrix3 a;
|
||||
a.fields[0][0] = f00; a.fields[1][0] = f01; a.fields[2][0] = f02;
|
||||
a.fields[0][1] = f10; a.fields[1][1] = f11; a.fields[2][1] = f12;
|
||||
a.fields[0][2] = f20; a.fields[1][2] = f21; a.fields[2][2] = f22;
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::createMatrix(const Vector3& a, const Vector3& b, const Vector3& c)
|
||||
{
|
||||
Matrix3 m;
|
||||
m.fields[0][0] = a.x; m.fields[1][0] = b.x; m.fields[2][0] = c.x;
|
||||
m.fields[0][1] = a.y; m.fields[1][1] = b.y; m.fields[2][1] = c.y;
|
||||
m.fields[0][2] = a.z; m.fields[1][2] = b.z; m.fields[2][2] = c.z;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// ============= //
|
||||
// Operators //
|
||||
// ============= //
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] += s;
|
||||
a[1] += s;
|
||||
a[2] += s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
a[2] += b[2];
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] -= s;
|
||||
a[1] -= s;
|
||||
a[2] -= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
a[0] -= b[0];
|
||||
a[1] -= b[1];
|
||||
a[2] -= b[2];
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix3& a, float s)
|
||||
{
|
||||
a[0] *= s;
|
||||
a[1] *= s;
|
||||
a[2] *= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 c = a;
|
||||
a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0) + c(0, 2) * b(2, 0);
|
||||
a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1) + c(0, 2) * b(2, 1);
|
||||
a(0, 2) = c(0, 0) * b(0, 2) + c(0, 1) * b(1, 2) + c(0, 2) * b(2, 2);
|
||||
|
||||
a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0) + c(1, 2) * b(2, 0);
|
||||
a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1) + c(1, 2) * b(2, 1);
|
||||
a(1, 2) = c(1, 0) * b(0, 2) + c(1, 1) * b(1, 2) + c(1, 2) * b(2, 2);
|
||||
|
||||
a(2, 0) = c(2, 0) * b(0, 0) + c(2, 1) * b(1, 0) + c(2, 2) * b(2, 0);
|
||||
a(2, 1) = c(2, 0) * b(0, 1) + c(2, 1) * b(1, 1) + c(2, 2) * b(2, 1);
|
||||
a(2, 2) = c(2, 0) * b(0, 2) + c(2, 1) * b(1, 2) + c(2, 2) * b(2, 2);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] + s;
|
||||
m[1] = a[1] + s;
|
||||
m[2] = a[2] + s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator+(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] + b[0];
|
||||
m[1] = a[1] + b[1];
|
||||
m[2] = a[2] + b[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] - s;
|
||||
m[1] = a[1] - s;
|
||||
m[2] = a[2] - s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator-(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] - b[0];
|
||||
m[1] = a[1] - b[1];
|
||||
m[2] = a[2] - b[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, float s)
|
||||
{
|
||||
Matrix3 m;
|
||||
m[0] = a[0] * s;
|
||||
m[1] = a[1] * s;
|
||||
m[2] = a[2] * s;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
Matrix3 m;
|
||||
|
||||
m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0) + a(0, 2) * b(2, 0);
|
||||
m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1) + a(0, 2) * b(2, 1);
|
||||
m(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2) * b(2, 2);
|
||||
|
||||
m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0) + a(1, 2) * b(2, 0);
|
||||
m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1) + a(1, 2) * b(2, 1);
|
||||
m(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2) * b(2, 2);
|
||||
|
||||
m(2, 0) = a(2, 0) * b(0, 0) + a(2, 1) * b(1, 0) + a(2, 2) * b(2, 0);
|
||||
m(2, 1) = a(2, 0) * b(0, 1) + a(2, 1) * b(1, 1) + a(2, 2) * b(2, 1);
|
||||
m(2, 2) = a(2, 0) * b(0, 2) + a(2, 1) * b(1, 2) + a(2, 2) * b(2, 2);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector3 phanes::core::math::coretypes::operator*(const Matrix3& a, const Vector3& v)
|
||||
{
|
||||
Vector3 b = createVector(
|
||||
a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z,
|
||||
a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z,
|
||||
a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Matrix3& a, const Matrix3& b)
|
||||
{
|
||||
if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::determinant(const Matrix3& a)
|
||||
{
|
||||
return (a(0, 0) * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1))
|
||||
-a(0, 1) * (a(1, 0) * a(2, 2) - a(1, 2) * a(2, 0))
|
||||
+a(0, 2) * (a(1, 0) * a(2, 1) - a(1, 1) * a(2, 0)));
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::inverseNR(Matrix3& a)
|
||||
{
|
||||
const Vector3& v0 = a[0];
|
||||
const Vector3& v1 = a[1];
|
||||
const Vector3& v2 = a[2];
|
||||
|
||||
Vector3 r0 = crossP(v1, v2);
|
||||
Vector3 r1 = crossP(v2, v0);
|
||||
Vector3 r2 = crossP(v0, v1);
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
a = createMatrix(
|
||||
r0.x, r0.y, r0.z,
|
||||
r1.x, r1.y, r1.z,
|
||||
r2.x, r2.y, r2.z
|
||||
);
|
||||
|
||||
a *= _1_det;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::transposeNR(Matrix3& a)
|
||||
{
|
||||
swap(a(0, 1), a(1, 0));
|
||||
swap(a(0, 2), a(2, 0));
|
||||
swap(a(1, 2), a(2, 1));
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::inverse(Matrix3& a)
|
||||
{
|
||||
const Vector3& v0 = a[0];
|
||||
const Vector3& v1 = a[1];
|
||||
const Vector3& v2 = a[2];
|
||||
|
||||
Vector3 r0 = crossP(v1, v2);
|
||||
Vector3 r1 = crossP(v2, v0);
|
||||
Vector3 r2 = crossP(v0, v1);
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Matrix3 m = createMatrix(
|
||||
r0.x, r0.y, r0.z,
|
||||
r1.x, r1.y, r1.z,
|
||||
r2.x, r2.y, r2.z
|
||||
);
|
||||
|
||||
m *= _1_det;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix3 phanes::core::math::coretypes::transpose(const Matrix3& a)
|
||||
{
|
||||
Matrix3 m = createMatrix(
|
||||
a(0, 0), a(1, 0), a(2, 0),
|
||||
a(0, 1), a(1, 1), a(2, 1),
|
||||
a(0, 2), a(1, 2), a(2, 2)
|
||||
);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix3& a)
|
||||
{
|
||||
if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 0, 1, 0, 0, 0, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
347
Engine/src/Runtime/Core/private/Math/Matrix4.cpp
Normal file
347
Engine/src/Runtime/Core/private/Math/Matrix4.cpp
Normal file
@ -0,0 +1,347 @@
|
||||
// ========================== //
|
||||
// Matrix4 implementation //
|
||||
// ========================== //
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Matrix4.h"
|
||||
|
||||
#include "Math/Vector3.h"
|
||||
|
||||
|
||||
// ================================= //
|
||||
// Class Methods for easy access //
|
||||
// ================================= //
|
||||
|
||||
float& phanes::core::math::coretypes::Matrix4::operator()(int n, int m)
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4& phanes::core::math::coretypes::Matrix4::operator[](int m)
|
||||
{
|
||||
return (*reinterpret_cast<Vector4*>(this->fields[m]));
|
||||
}
|
||||
|
||||
const float& phanes::core::math::coretypes::Matrix4::operator()(int n, int m) const
|
||||
{
|
||||
return this->fields[m][n];
|
||||
}
|
||||
|
||||
const phanes::core::math::coretypes::Vector4& phanes::core::math::coretypes::Matrix4::operator[](int m) const
|
||||
{
|
||||
return (*reinterpret_cast<const Vector4*>(this->fields[m]));
|
||||
}
|
||||
|
||||
|
||||
// ================= //
|
||||
// Constructors //
|
||||
// ================= //
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(float fields[4][4])
|
||||
{
|
||||
Matrix4 a;
|
||||
std::copy(&fields[0][0], &fields[4][4], &a.fields[0][0]);
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(float f00, float f01, float f02, float f03, float f10, float f11, float f12, float f13, float f20, float f21, float f22, float f23, float f30, float f31, float f32, float f33)
|
||||
{
|
||||
Matrix4 a;
|
||||
a.fields[0][0] = f00; a.fields[1][0] = f01; a.fields[2][0] = f02; a.fields[3][0] = f03;
|
||||
a.fields[0][1] = f10; a.fields[1][1] = f11; a.fields[2][1] = f12; a.fields[3][1] = f13;
|
||||
a.fields[0][2] = f20; a.fields[1][2] = f21; a.fields[2][2] = f22; a.fields[3][2] = f23;
|
||||
a.fields[0][3] = f30; a.fields[1][3] = f31; a.fields[2][3] = f32; a.fields[3][3] = f33;
|
||||
return a;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::createMatrix(const Vector4& a, const Vector4& b, const Vector4& c, const Vector4& d)
|
||||
{
|
||||
Matrix4 m;
|
||||
m.fields[0][0] = a.x; m.fields[1][0] = b.x; m.fields[2][0] = c.x; m.fields[3][0] = d.x;
|
||||
m.fields[0][1] = a.y; m.fields[1][1] = b.y; m.fields[2][1] = c.y; m.fields[3][1] = d.y;
|
||||
m.fields[0][2] = a.z; m.fields[1][2] = b.z; m.fields[2][2] = c.z; m.fields[3][2] = d.z;
|
||||
m.fields[0][3] = a.w; m.fields[1][3] = b.w; m.fields[2][3] = c.w; m.fields[3][3] = d.w;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// ============= //
|
||||
// Operators //
|
||||
// ============= //
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] += s;
|
||||
a[1] += s;
|
||||
a[2] += s;
|
||||
a[3] += s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
a[0] += b[0];
|
||||
a[1] += b[1];
|
||||
a[2] += b[2];
|
||||
a[3] += b[3];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] -= s;
|
||||
a[1] -= s;
|
||||
a[2] -= s;
|
||||
a[3] -= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
a[0] -= b[0];
|
||||
a[1] -= b[1];
|
||||
a[2] -= b[2];
|
||||
a[3] -= b[3];
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix4& a, float s)
|
||||
{
|
||||
a[0] *= s;
|
||||
a[1] *= s;
|
||||
a[2] *= s;
|
||||
a[3] *= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator*=(Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 c = a;
|
||||
|
||||
a(0, 0) = c(0, 0) * b(0, 0) + c(0, 1) * b(1, 0) + c(0, 2) * b(2, 0) + c(0, 3) * b(3, 0);
|
||||
a(0, 1) = c(0, 0) * b(0, 1) + c(0, 1) * b(1, 1) + c(0, 2) * b(2, 1) + c(0, 3) * b(3, 1);
|
||||
a(0, 2) = c(0, 0) * b(0, 2) + c(0, 1) * b(1, 2) + c(0, 2) * b(2, 2) + c(0, 3) * b(3, 2);
|
||||
a(0, 3) = c(0, 0) * b(0, 3) + c(0, 1) * b(1, 3) + c(0, 2) * b(2, 3) + c(0, 3) * b(3, 3);
|
||||
|
||||
a(1, 0) = c(1, 0) * b(0, 0) + c(1, 1) * b(1, 0) + c(1, 2) * b(2, 0) + c(1, 3) * b(3, 0);
|
||||
a(1, 1) = c(1, 0) * b(0, 1) + c(1, 1) * b(1, 1) + c(1, 2) * b(2, 1) + c(1, 3) * b(3, 1);
|
||||
a(1, 2) = c(1, 0) * b(0, 2) + c(1, 1) * b(1, 2) + c(1, 2) * b(2, 2) + c(1, 3) * b(3, 2);
|
||||
a(1, 3) = c(1, 0) * b(0, 3) + c(1, 1) * b(1, 3) + c(1, 2) * b(2, 3) + c(1, 3) * b(3, 3);
|
||||
|
||||
a(2, 0) = c(2, 0) * b(0, 0) + c(2, 1) * b(1, 0) + c(2, 2) * b(2, 0) + c(2, 3) * b(3, 0);
|
||||
a(2, 1) = c(2, 0) * b(0, 1) + c(2, 1) * b(1, 1) + c(2, 2) * b(2, 1) + c(2, 3) * b(3, 1);
|
||||
a(2, 2) = c(2, 0) * b(0, 2) + c(2, 1) * b(1, 2) + c(2, 2) * b(2, 2) + c(2, 3) * b(3, 2);
|
||||
a(2, 3) = c(2, 0) * b(0, 3) + c(2, 1) * b(1, 3) + c(2, 2) * b(2, 3) + c(2, 3) * b(3, 3);
|
||||
|
||||
a(3, 0) = c(3, 0) * b(0, 0) + c(3, 1) * b(1, 0) + c(3, 2) * b(2, 0) + c(3, 3) * b(3, 0);
|
||||
a(3, 1) = c(3, 0) * b(0, 1) + c(3, 1) * b(1, 1) + c(3, 2) * b(2, 1) + c(3, 3) * b(3, 1);
|
||||
a(3, 2) = c(3, 0) * b(0, 2) + c(3, 1) * b(1, 2) + c(3, 2) * b(2, 2) + c(3, 3) * b(3, 2);
|
||||
a(3, 3) = c(3, 0) * b(0, 3) + c(3, 1) * b(1, 3) + c(3, 2) * b(2, 3) + c(3, 3) * b(3, 3);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator+(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] + s;
|
||||
m[1] = a[1] + s;
|
||||
m[2] = a[2] + s;
|
||||
m[3] = a[3] + s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator+(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] + b[0];
|
||||
m[1] = a[1] + b[1];
|
||||
m[2] = a[2] + b[2];
|
||||
m[3] = a[3] + b[3];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator-(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] - s;
|
||||
m[1] = a[1] - s;
|
||||
m[2] = a[2] - s;
|
||||
m[3] = a[3] - s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator-(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] - b[0];
|
||||
m[1] = a[1] - b[1];
|
||||
m[2] = a[2] - b[2];
|
||||
m[3] = a[3] - b[3];
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator*(const Matrix4& a, float s)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[0] = a[0] * s;
|
||||
m[1] = a[1] * s;
|
||||
m[2] = a[2] * s;
|
||||
m[3] = a[3] * s;
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::operator*(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
Matrix4 m;
|
||||
|
||||
m(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0) + a(0, 2) * b(2, 0) + a(0, 3) * b(3, 0);
|
||||
m(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1) + a(0, 2) * b(2, 1) + a(0, 3) * b(3, 1);
|
||||
m(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2) * b(2, 2) + a(0, 3) * b(3, 2);
|
||||
m(0, 3) = a(0, 0) * b(0, 3) + a(0, 1) * b(1, 3) + a(0, 2) * b(2, 3) + a(0, 3) * b(3, 3);
|
||||
|
||||
m(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0) + a(1, 2) * b(2, 0) + a(1, 3) * b(3, 0);
|
||||
m(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1) + a(1, 2) * b(2, 1) + a(1, 3) * b(3, 1);
|
||||
m(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2) * b(2, 2) + a(1, 3) * b(3, 2);
|
||||
m(1, 3) = a(1, 0) * b(0, 3) + a(1, 1) * b(1, 3) + a(1, 2) * b(2, 3) + a(1, 3) * b(3, 3);
|
||||
|
||||
m(2, 0) = a(2, 0) * b(0, 0) + a(2, 1) * b(1, 0) + a(2, 2) * b(2, 0) + a(2, 3) * b(3, 0);
|
||||
m(2, 1) = a(2, 0) * b(0, 1) + a(2, 1) * b(1, 1) + a(2, 2) * b(2, 1) + a(2, 3) * b(3, 1);
|
||||
m(2, 2) = a(2, 0) * b(0, 2) + a(2, 1) * b(1, 2) + a(2, 2) * b(2, 2) + a(2, 3) * b(3, 2);
|
||||
m(2, 3) = a(2, 0) * b(0, 3) + a(2, 1) * b(1, 3) + a(2, 2) * b(2, 3) + a(2, 3) * b(3, 3);
|
||||
|
||||
m(3, 0) = a(3, 0) * b(0, 0) + a(3, 1) * b(1, 0) + a(3, 2) * b(2, 0) + a(3, 3) * b(3, 0);
|
||||
m(3, 1) = a(3, 0) * b(0, 1) + a(3, 1) * b(1, 1) + a(3, 2) * b(2, 1) + a(3, 3) * b(3, 1);
|
||||
m(3, 2) = a(3, 0) * b(0, 2) + a(3, 1) * b(1, 2) + a(3, 2) * b(2, 2) + a(3, 3) * b(3, 2);
|
||||
m(3, 3) = a(3, 0) * b(0, 3) + a(3, 1) * b(1, 3) + a(3, 2) * b(2, 3) + a(3, 3) * b(3, 3);
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(const Matrix4& a, const Vector4& v)
|
||||
{
|
||||
Vector4 b = createVector(
|
||||
a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z + a(0, 3) * v.w,
|
||||
a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z + a(1, 3) * v.w,
|
||||
a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z + a(2, 3) * v.w,
|
||||
a(3, 0) * v.x + a(3, 1) * v.y + a(3, 2) * v.z + a(3, 3) * v.w
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Matrix4& a, const Matrix4& b)
|
||||
{
|
||||
if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// =============================== //
|
||||
// Matrix function definition //
|
||||
// =============================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::determinant(const Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
return s * v + t * u;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::inverseNR(Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Vector3 r0 = crossP(v1, v) + t * a(3, 1);
|
||||
Vector3 r1 = crossP(v, v0) - t * a(3, 0);
|
||||
Vector3 r2 = crossP(v3, u) + s * a(3, 3);
|
||||
Vector3 r3 = crossP(u, v2) - s * a(3, 2);
|
||||
|
||||
a = createMatrix(
|
||||
r0.x, r0.y, r0.z, -dotP(v1, t),
|
||||
r1.x, r1.y, r1.z, -dotP(v0, t),
|
||||
r2.x, r2.y, r2.z, -dotP(v3, s),
|
||||
r3.x, r3.y, r3.z, -dotP(v2, s)
|
||||
);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::transposeNR(Matrix4& a)
|
||||
{
|
||||
swap(a(0, 1), a(1, 0));
|
||||
swap(a(0, 2), a(2, 0));
|
||||
swap(a(0, 3), a(3, 0));
|
||||
|
||||
swap(a(1, 2), a(2, 1));
|
||||
swap(a(1, 3), a(3, 1));
|
||||
|
||||
swap(a(2, 3), a(3, 2));
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::inverse(Matrix4& a)
|
||||
{
|
||||
Vector3 v0 = reinterpret_cast<const Vector3&>(a[0]);
|
||||
Vector3 v1 = reinterpret_cast<const Vector3&>(a[1]);
|
||||
Vector3 v2 = reinterpret_cast<const Vector3&>(a[2]);
|
||||
Vector3 v3 = reinterpret_cast<const Vector3&>(a[3]);
|
||||
|
||||
Vector3 s = crossP(v0, v1);
|
||||
Vector3 t = crossP(v2, v3);
|
||||
Vector3 u = a(3, 1) * v0 + a(3, 0) * v1;
|
||||
Vector3 v = a(3, 3) * v2 + a(3, 2) * v3;
|
||||
|
||||
float _1_det = 1.0f / determinant(a);
|
||||
|
||||
Vector3 r0 = crossP(v1, v) + t * a(3, 1);
|
||||
Vector3 r1 = crossP(v, v0) - t * a(3, 0);
|
||||
Vector3 r2 = crossP(v3, u) + s * a(3, 3);
|
||||
Vector3 r3 = crossP(u, v2) - s * a(3, 2);
|
||||
|
||||
Matrix4 m = createMatrix(
|
||||
r0.x, r0.y, r0.z, -dotP(v1, t),
|
||||
r1.x, r1.y, r1.z, -dotP(v0, t),
|
||||
r2.x, r2.y, r2.z, -dotP(v3, s),
|
||||
r3.x, r3.y, r3.z, -dotP(v2, s)
|
||||
);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Matrix4 phanes::core::math::coretypes::transpose(const Matrix4& a)
|
||||
{
|
||||
Matrix4 m = a;
|
||||
|
||||
swap(m(0, 1), m(1, 0));
|
||||
swap(m(0, 2), m(2, 0));
|
||||
swap(m(0, 3), m(3, 0));
|
||||
|
||||
swap(m(1, 2), m(2, 1));
|
||||
swap(m(1, 3), m(3, 1));
|
||||
|
||||
swap(m(2, 3), m(3, 2));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::isIndentityMatrix(const Matrix4& a)
|
||||
{
|
||||
if (a == phanes::core::math::coretypes::createMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
388
Engine/src/Runtime/Core/private/Math/Vector4.cpp
Normal file
388
Engine/src/Runtime/Core/private/Math/Vector4.cpp
Normal file
@ -0,0 +1,388 @@
|
||||
// ========================== //
|
||||
// Vector4 implementation //
|
||||
// ========================== //
|
||||
|
||||
|
||||
#include "Misc/CommonDefines.h"
|
||||
#include PHANES_CORE_PCH_DEFAULT_PATH
|
||||
|
||||
#include "Math/Vector4.h"
|
||||
|
||||
#include "Math/Vector3.h"
|
||||
#include "Math/Vector2.h"
|
||||
|
||||
|
||||
// ===================== //
|
||||
// Vector4 operators //
|
||||
// ===================== //
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::createVector(float x, float y, float z, float w)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = x;
|
||||
_new.y = y;
|
||||
_new.z = z;
|
||||
_new.w = w;
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+=(Vector4& a, float s)
|
||||
{
|
||||
a.x += s;
|
||||
a.y += s;
|
||||
a.z += s;
|
||||
a.w += s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator+= (phanes::core::math::coretypes::Vector4& a, const phanes::core::math::coretypes::Vector4& b) {
|
||||
a.x += b.x;
|
||||
a.y += b.y;
|
||||
a.z += b.z;
|
||||
a.w += b.w;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-=(Vector4& a, float s)
|
||||
{
|
||||
a.x -= s;
|
||||
a.y -= s;
|
||||
a.z -= s;
|
||||
a.w -= s;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::operator-= (phanes::core::math::coretypes::Vector4& a, const phanes::core::math::coretypes::Vector4& b) {
|
||||
a.x -= b.x;
|
||||
a.y -= b.y;
|
||||
a.z -= b.z;
|
||||
a.w -= b.w;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator*= (phanes::core::math::coretypes::Vector4& a, float s) {
|
||||
a.x *= s;
|
||||
a.y *= s;
|
||||
a.z *= s;
|
||||
a.w *= s;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator/= (phanes::core::math::coretypes::Vector4& a, float s) {
|
||||
s = 1.0f / s;
|
||||
a.x *= s;
|
||||
a.y *= s;
|
||||
a.z *= s;
|
||||
a.w *= s;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator*(float s, const Vector4& a)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator/(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
s = 1.0f / s;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator/(float s, const Vector4& a)
|
||||
{
|
||||
Vector4 v;
|
||||
s = 1.0f / s;
|
||||
v.x = a.x * s;
|
||||
v.y = a.y * s;
|
||||
v.z = a.z * s;
|
||||
v.w = a.w * s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::operator*(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator+(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x + s;
|
||||
v.y = a.y + s;
|
||||
v.z = a.z + s;
|
||||
v.w = a.w + s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator+(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x + b.x;
|
||||
v.y = a.y + b.y;
|
||||
v.z = a.z + b.z;
|
||||
v.w = a.w + b.w;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator-(const Vector4& a, float s)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x - s;
|
||||
v.y = a.y - s;
|
||||
v.z = a.z - s;
|
||||
v.w = a.w - s;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::operator-(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 v;
|
||||
v.x = a.x - b.x;
|
||||
v.y = a.y - b.y;
|
||||
v.z = a.z - b.z;
|
||||
v.w = a.w - b.w;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::operator-(Vector4& a)
|
||||
{
|
||||
a.x = -a.x;
|
||||
a.y = -a.y;
|
||||
a.z = -a.z;
|
||||
a.w = -a.w;
|
||||
}
|
||||
|
||||
|
||||
bool phanes::core::math::coretypes::operator==(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
if (abs(a.x - b.x) <= P_FLT_INAC and abs(a.y - b.y) <= P_FLT_INAC and abs(a.z - b.z) <= P_FLT_INAC and abs(a.w - b.w) <= P_FLT_INAC)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ====================================== //
|
||||
// Vector4 function implementation //
|
||||
// ====================================== //
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::magnitude(const Vector4& a)
|
||||
{
|
||||
return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
|
||||
}
|
||||
|
||||
float phanes::core::math::coretypes::sqrMagnitude(const Vector4& a)
|
||||
{
|
||||
return a.x * a.x + a.y * a.y + a.z * a.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::normalizeNR(Vector4& a)
|
||||
{
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::angle(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return acosf(dotP(a, b) / (magnitude(a) * magnitude(b)));
|
||||
}
|
||||
|
||||
|
||||
float phanes::core::math::coretypes::dotP(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::orthogonolize(Vector4& a, Vector4& b, Vector4& c)
|
||||
{
|
||||
Set(b, b - project(b, a));
|
||||
Set(c, c - project(c, a) - project(c, b));
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::orthoNormalize(Vector4& a, Vector4& b, Vector4& c)
|
||||
{
|
||||
Set(b, b - project(b, a));
|
||||
Set(c, c - project(c, a) - project(c, b));
|
||||
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
b /= sqrtf(b.x * b.x + b.y * b.y + b.z * b.z);
|
||||
c /= sqrtf(c.x * c.x + c.y * c.y + c.z * c.z);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::scaleToMagnitude(Vector4& a, float size)
|
||||
{
|
||||
a /= sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
a *= size;
|
||||
}
|
||||
|
||||
bool phanes::core::math::coretypes::equals(const Vector4& a, const Vector4& b, float threshold)
|
||||
{
|
||||
if (abs(a.x - b.x) <= threshold and abs(a.y - b.y) <= threshold and abs(a.z - b.z) <= threshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::perpspectiveDivideNR(Vector4& a)
|
||||
{
|
||||
float _z = 1.0f / a.z;
|
||||
a.x *= _z;
|
||||
a.y *= _z;
|
||||
a.z = 0.0f;
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::maxNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = phanes::core::math::max(a.x, b.x);
|
||||
a.y = phanes::core::math::max(a.y, b.y);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::minNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = phanes::core::math::min(a.x, b.x);
|
||||
a.y = phanes::core::math::min(a.y, b.y);
|
||||
}
|
||||
|
||||
void phanes::core::math::coretypes::scaleNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
a.z *= b.z;
|
||||
}
|
||||
|
||||
// projects vector a onto vector b
|
||||
void phanes::core::math::coretypes::projectNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
float x = (a * b) / (b * b);
|
||||
a.x = x * b.x;
|
||||
a.y = x * b.y;
|
||||
a.z = x * b.z;
|
||||
}
|
||||
|
||||
// rejects vector a from vector b
|
||||
void phanes::core::math::coretypes::rejectNR(Vector4& a, const Vector4& b)
|
||||
{
|
||||
float x = ((a * b) / (b * b));
|
||||
a.x -= x * b.x;
|
||||
a.y -= x * b.y;
|
||||
a.z -= x * b.z;
|
||||
}
|
||||
|
||||
|
||||
void phanes::core::math::coretypes::Set(Vector4& a, const Vector4& b)
|
||||
{
|
||||
a.x = b.x;
|
||||
a.y = b.y;
|
||||
a.z = b.z;
|
||||
}
|
||||
|
||||
|
||||
// WITH RETURN: //
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::perpspectiveDivide(const Vector4& a)
|
||||
{
|
||||
float _z = 1.0f / a.z;
|
||||
return createVector(a.x * _z, a.y * _z, a.z * _z, 0.0f);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::lerp(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
t = phanes::core::math::clamp(t, .0f, 1.0f);
|
||||
return a * (1 - t) + t * b;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::lerpUnclamped(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
return a * (1 - t) + t * b;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::slerp(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
t = phanes::core::math::clamp(t, 0.0f, 1.0f);
|
||||
Vector4 _a = normalize(a);
|
||||
Vector4 _b = normalize(b);
|
||||
float _angle = angle(_a, _b);
|
||||
return (((sinf(1.0f - t) * _angle) / sinf(_angle)) * _a) + ((sinf(t * _angle) / sinf(_angle)) * _b);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::slerpUnclamped(const Vector4& a, const Vector4& b, float t)
|
||||
{
|
||||
Vector4 _a = normalize(a);
|
||||
Vector4 _b = normalize(b);
|
||||
float _angle = angle(_a, _b);
|
||||
return (((sinf(1.0f - t) * _angle) / sinf(_angle)) * _a) + ((sinf(t * _angle) / sinf(_angle)) * _b);
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::max(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = phanes::core::math::max(a.x, b.x);
|
||||
_new.y = phanes::core::math::max(a.y, b.y);
|
||||
_new.z = phanes::core::math::max(a.z, b.z);
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::min(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
Vector4 _new{};
|
||||
_new.x = phanes::core::math::min(a.x, b.x);
|
||||
_new.y = phanes::core::math::min(a.y, b.y);
|
||||
_new.z = phanes::core::math::min(a.z, b.z);
|
||||
return _new;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::scale(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return createVector(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::project(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return ((a * b) / (b * b)) * b;
|
||||
}
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::reject(const Vector4& a, const Vector4& b)
|
||||
{
|
||||
return a - ((a * b) / (b * b)) * b;
|
||||
}
|
||||
|
||||
|
||||
phanes::core::math::coretypes::Vector4 phanes::core::math::coretypes::normalize(const Vector4& a)
|
||||
{
|
||||
return a / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user