Moved everything in namespace Leonetienne::Eule
This commit is contained in:
parent
3c8391d9ce
commit
be63652df6
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** Abstract class of a collider domain.
|
/** Abstract class of a collider domain.
|
||||||
* Specializations describe a shape in 3d space, and provide implementations of the methods below,
|
* Specializations describe a shape in 3d space, and provide implementations of the methods below,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// Pretty sure the compiler will optimize these calculations out...
|
// Pretty sure the compiler will optimize these calculations out...
|
||||||
|
|
||||||
|
namespace Leonetienne::Eule {
|
||||||
//! Pi up to 50 decimal places
|
//! Pi up to 50 decimal places
|
||||||
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
|
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
|
||||||
|
|
||||||
@ -13,3 +14,4 @@ static constexpr double Deg2Rad = 0.01745329251994329576923690768488612713442871
|
|||||||
|
|
||||||
//! Factor to convert radians to degrees
|
//! Factor to convert radians to degrees
|
||||||
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
|
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
|
||||||
|
}
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
using namespace Eule;
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
int Math::Mod(const int numerator, const int denominator)
|
int Math::Mod(const int numerator, const int denominator) {
|
||||||
{
|
|
||||||
if (denominator == 0)
|
if (denominator == 0)
|
||||||
throw std::logic_error("Division by zero");
|
throw std::logic_error("Division by zero");
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ int Math::Mod(const int numerator, const int denominator)
|
|||||||
return (denominator + (numerator % denominator)) % denominator;
|
return (denominator + (numerator % denominator)) % denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Math::Oscillate(const double a, const double b, const double counter, const double speed)
|
double Math::Oscillate(const double a, const double b, const double counter, const double speed) {
|
||||||
{
|
|
||||||
return (sin(counter * speed * PI - HALF_PI) * 0.5 + 0.5) * (b - a) + a;
|
return (sin(counter * speed * PI - HALF_PI) * 0.5 + 0.5) * (b - a) + a;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** Math utility class containing basic functions.
|
/** Math utility class containing basic functions.
|
||||||
*/
|
*/
|
||||||
|
@ -7,10 +7,9 @@
|
|||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Eule;
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
Matrix4x4::Matrix4x4()
|
Matrix4x4::Matrix4x4() {
|
||||||
{
|
|
||||||
// Create identity matrix
|
// Create identity matrix
|
||||||
for (std::size_t i = 0; i < 4; i++)
|
for (std::size_t i = 0; i < 4; i++)
|
||||||
for (std::size_t j = 0; j < 4; j++)
|
for (std::size_t j = 0; j < 4; j++)
|
||||||
@ -19,20 +18,17 @@ Matrix4x4::Matrix4x4()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4::Matrix4x4(const Matrix4x4& other)
|
Matrix4x4::Matrix4x4(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
v = other.v;
|
v = other.v;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4::Matrix4x4(Matrix4x4&& other) noexcept
|
Matrix4x4::Matrix4x4(Matrix4x4 &&other) noexcept {
|
||||||
{
|
|
||||||
v = std::move(other.v);
|
v = std::move(other.v);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator*(const Matrix4x4& other) const
|
Matrix4x4 Matrix4x4::operator*(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
Matrix4x4 newMatrix;
|
Matrix4x4 newMatrix;
|
||||||
newMatrix.p = 1;
|
newMatrix.p = 1;
|
||||||
|
|
||||||
@ -144,25 +140,21 @@ Matrix4x4 Matrix4x4::operator*(const Matrix4x4& other) const
|
|||||||
return newMatrix;
|
return newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator*=(const Matrix4x4& other)
|
void Matrix4x4::operator*=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
*this = *this * other;
|
*this = *this * other;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator/(const Matrix4x4& other) const
|
Matrix4x4 Matrix4x4::operator/(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
return *this * other.Inverse3x3();
|
return *this * other.Inverse3x3();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator/=(const Matrix4x4& other)
|
void Matrix4x4::operator/=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
*this = *this * other.Inverse3x3();
|
*this = *this * other.Inverse3x3();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator*(const double scalar) const
|
Matrix4x4 Matrix4x4::operator*(const double scalar) const {
|
||||||
{
|
|
||||||
Matrix4x4 m;
|
Matrix4x4 m;
|
||||||
|
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -199,27 +191,23 @@ Matrix4x4 Matrix4x4::operator*(const double scalar) const
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator*=(const double scalar)
|
void Matrix4x4::operator*=(const double scalar) {
|
||||||
{
|
|
||||||
*this = *this * scalar;
|
*this = *this * scalar;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator/(const double denominator) const
|
Matrix4x4 Matrix4x4::operator/(const double denominator) const {
|
||||||
{
|
|
||||||
const double precomputeDivision = 1.0 / denominator;
|
const double precomputeDivision = 1.0 / denominator;
|
||||||
|
|
||||||
return *this * precomputeDivision;
|
return *this * precomputeDivision;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator/=(const double denominator)
|
void Matrix4x4::operator/=(const double denominator) {
|
||||||
{
|
|
||||||
*this = *this / denominator;
|
*this = *this / denominator;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator+(const Matrix4x4& other) const
|
Matrix4x4 Matrix4x4::operator+(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
Matrix4x4 m;
|
Matrix4x4 m;
|
||||||
|
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -258,8 +246,7 @@ Matrix4x4 Matrix4x4::operator+(const Matrix4x4& other) const
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator+=(const Matrix4x4& other)
|
void Matrix4x4::operator+=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
|
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
|
||||||
|
|
||||||
@ -295,8 +282,7 @@ void Matrix4x4::operator+=(const Matrix4x4& other)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::operator-(const Matrix4x4& other) const
|
Matrix4x4 Matrix4x4::operator-(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
Matrix4x4 m;
|
Matrix4x4 m;
|
||||||
|
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
@ -335,8 +321,7 @@ Matrix4x4 Matrix4x4::operator-(const Matrix4x4& other) const
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator-=(const Matrix4x4& other)
|
void Matrix4x4::operator-=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
#ifndef _EULE_NO_INTRINSICS_
|
#ifndef _EULE_NO_INTRINSICS_
|
||||||
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
|
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
|
||||||
|
|
||||||
@ -372,63 +357,52 @@ void Matrix4x4::operator-=(const Matrix4x4& other)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<double, 4>& Matrix4x4::operator[](std::size_t y)
|
std::array<double, 4> &Matrix4x4::operator[](std::size_t y) {
|
||||||
{
|
|
||||||
return v[y];
|
return v[y];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::array<double, 4>& Matrix4x4::operator[](std::size_t y) const
|
const std::array<double, 4> &Matrix4x4::operator[](std::size_t y) const {
|
||||||
{
|
|
||||||
return v[y];
|
return v[y];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator=(const Matrix4x4& other)
|
void Matrix4x4::operator=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
v = other.v;
|
v = other.v;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::operator=(Matrix4x4&& other) noexcept
|
void Matrix4x4::operator=(Matrix4x4 &&other) noexcept {
|
||||||
{
|
|
||||||
v = std::move(other.v);
|
v = std::move(other.v);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::operator==(const Matrix4x4& other)
|
bool Matrix4x4::operator==(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
return v == other.v;
|
return v == other.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::operator!=(const Matrix4x4& other)
|
bool Matrix4x4::operator!=(const Matrix4x4 &other) {
|
||||||
{
|
|
||||||
return !operator==(other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::operator==(const Matrix4x4& other) const
|
bool Matrix4x4::operator==(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
return v == other.v;
|
return v == other.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::operator!=(const Matrix4x4& other) const
|
bool Matrix4x4::operator!=(const Matrix4x4 &other) const {
|
||||||
{
|
|
||||||
return !operator==(other);
|
return !operator==(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3d Matrix4x4::GetTranslationComponent() const
|
const Vector3d Matrix4x4::GetTranslationComponent() const {
|
||||||
{
|
|
||||||
return Vector3d(d, h, l);
|
return Vector3d(d, h, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix4x4::SetTranslationComponent(const Vector3d& trans)
|
void Matrix4x4::SetTranslationComponent(const Vector3d &trans) {
|
||||||
{
|
|
||||||
d = trans.x;
|
d = trans.x;
|
||||||
h = trans.y;
|
h = trans.y;
|
||||||
l = trans.z;
|
l = trans.z;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::DropTranslationComponents() const
|
Matrix4x4 Matrix4x4::DropTranslationComponents() const {
|
||||||
{
|
|
||||||
Matrix4x4 m(*this);
|
Matrix4x4 m(*this);
|
||||||
m.d = 0;
|
m.d = 0;
|
||||||
m.h = 0;
|
m.h = 0;
|
||||||
@ -436,8 +410,7 @@ Matrix4x4 Matrix4x4::DropTranslationComponents() const
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Transpose3x3() const
|
Matrix4x4 Matrix4x4::Transpose3x3() const {
|
||||||
{
|
|
||||||
Matrix4x4 trans(*this); // Keep other cells
|
Matrix4x4 trans(*this); // Keep other cells
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 3; i++)
|
for (std::size_t i = 0; i < 3; i++)
|
||||||
@ -447,8 +420,7 @@ Matrix4x4 Matrix4x4::Transpose3x3() const
|
|||||||
return trans;
|
return trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Transpose4x4() const
|
Matrix4x4 Matrix4x4::Transpose4x4() const {
|
||||||
{
|
|
||||||
Matrix4x4 trans;
|
Matrix4x4 trans;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 4; i++)
|
for (std::size_t i = 0; i < 4; i++)
|
||||||
@ -458,8 +430,7 @@ Matrix4x4 Matrix4x4::Transpose4x4() const
|
|||||||
return trans;
|
return trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Multiply4x4(const Matrix4x4& o) const
|
Matrix4x4 Matrix4x4::Multiply4x4(const Matrix4x4 &o) const {
|
||||||
{
|
|
||||||
Matrix4x4 m;
|
Matrix4x4 m;
|
||||||
|
|
||||||
m[0][0] = (v[0][0] * o[0][0]) + (v[0][1] * o[1][0]) + (v[0][2] * o[2][0]) + (v[0][3] * o[3][0]);
|
m[0][0] = (v[0][0] * o[0][0]) + (v[0][1] * o[1][0]) + (v[0][2] * o[2][0]) + (v[0][3] * o[3][0]);
|
||||||
@ -485,8 +456,7 @@ Matrix4x4 Matrix4x4::Multiply4x4(const Matrix4x4& o) const
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::GetCofactors(std::size_t p, std::size_t q, std::size_t n) const
|
Matrix4x4 Matrix4x4::GetCofactors(std::size_t p, std::size_t q, std::size_t n) const {
|
||||||
{
|
|
||||||
if (n > 4)
|
if (n > 4)
|
||||||
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
||||||
|
|
||||||
@ -496,16 +466,13 @@ Matrix4x4 Matrix4x4::GetCofactors(std::size_t p, std::size_t q, std::size_t n) c
|
|||||||
std::size_t j = 0;
|
std::size_t j = 0;
|
||||||
|
|
||||||
for (std::size_t y = 0; y < n; y++)
|
for (std::size_t y = 0; y < n; y++)
|
||||||
for (std::size_t x = 0; x < n; x++)
|
for (std::size_t x = 0; x < n; x++) {
|
||||||
{
|
if ((y != p) && (x != q)) {
|
||||||
if ((y != p) && (x != q))
|
|
||||||
{
|
|
||||||
cofs[i][j] = v[y][x];
|
cofs[i][j] = v[y][x];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j == n - 1)
|
if (j == n - 1) {
|
||||||
{
|
|
||||||
j = 0;
|
j = 0;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -518,8 +485,7 @@ Matrix4x4 Matrix4x4::GetCofactors(std::size_t p, std::size_t q, std::size_t n) c
|
|||||||
* BEGIN_REF
|
* BEGIN_REF
|
||||||
* https://www.geeksforgeeks.org/adjoint-inverse-matrix/
|
* https://www.geeksforgeeks.org/adjoint-inverse-matrix/
|
||||||
*/
|
*/
|
||||||
double Matrix4x4::Determinant(std::size_t n) const
|
double Matrix4x4::Determinant(std::size_t n) const {
|
||||||
{
|
|
||||||
if (n > 4)
|
if (n > 4)
|
||||||
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
||||||
|
|
||||||
@ -529,8 +495,7 @@ double Matrix4x4::Determinant(std::size_t n) const
|
|||||||
if (n == 1)
|
if (n == 1)
|
||||||
return v[0][0];
|
return v[0][0];
|
||||||
|
|
||||||
for (std::size_t x = 0; x < n; x++)
|
for (std::size_t x = 0; x < n; x++) {
|
||||||
{
|
|
||||||
Matrix4x4 cofs = GetCofactors(0, x, n);
|
Matrix4x4 cofs = GetCofactors(0, x, n);
|
||||||
|
|
||||||
d += sign * v[0][x] * cofs.Determinant(n - 1);
|
d += sign * v[0][x] * cofs.Determinant(n - 1);
|
||||||
@ -540,8 +505,7 @@ double Matrix4x4::Determinant(std::size_t n) const
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const
|
Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const {
|
||||||
{
|
|
||||||
if (n > 4)
|
if (n > 4)
|
||||||
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
|
||||||
|
|
||||||
@ -549,8 +513,7 @@ Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const
|
|||||||
double sign = 1;
|
double sign = 1;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < n; i++)
|
for (std::size_t i = 0; i < n; i++)
|
||||||
for (std::size_t j = 0; j < n; j++)
|
for (std::size_t j = 0; j < n; j++) {
|
||||||
{
|
|
||||||
Matrix4x4 cofs = GetCofactors(i, j, n);
|
Matrix4x4 cofs = GetCofactors(i, j, n);
|
||||||
|
|
||||||
// sign of adj[j][i] positive if sum of row
|
// sign of adj[j][i] positive if sum of row
|
||||||
@ -565,8 +528,7 @@ Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const
|
|||||||
return adj;
|
return adj;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Inverse3x3() const
|
Matrix4x4 Matrix4x4::Inverse3x3() const {
|
||||||
{
|
|
||||||
Matrix4x4 inv;
|
Matrix4x4 inv;
|
||||||
|
|
||||||
double det = Determinant(3);
|
double det = Determinant(3);
|
||||||
@ -584,8 +546,7 @@ Matrix4x4 Matrix4x4::Inverse3x3() const
|
|||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 Matrix4x4::Inverse4x4() const
|
Matrix4x4 Matrix4x4::Inverse4x4() const {
|
||||||
{
|
|
||||||
Matrix4x4 inv;
|
Matrix4x4 inv;
|
||||||
|
|
||||||
double det = Determinant(4);
|
double det = Determinant(4);
|
||||||
@ -605,18 +566,15 @@ Matrix4x4 Matrix4x4::Inverse4x4() const
|
|||||||
* END REF
|
* END REF
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool Matrix4x4::IsInversible3x3() const
|
bool Matrix4x4::IsInversible3x3() const {
|
||||||
{
|
|
||||||
return (Determinant(3) != 0);
|
return (Determinant(3) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::IsInversible4x4() const
|
bool Matrix4x4::IsInversible4x4() const {
|
||||||
{
|
|
||||||
return (Determinant(4) != 0);
|
return (Determinant(4) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix4x4::Similar(const Matrix4x4& other, double epsilon) const
|
bool Matrix4x4::Similar(const Matrix4x4 &other, double epsilon) const {
|
||||||
{
|
|
||||||
for (std::size_t i = 0; i < 4; i++)
|
for (std::size_t i = 0; i < 4; i++)
|
||||||
for (std::size_t j = 0; j < 4; j++)
|
for (std::size_t j = 0; j < 4; j++)
|
||||||
if (!Math::Similar(v[i][j], other[i][j], epsilon))
|
if (!Math::Similar(v[i][j], other[i][j], epsilon))
|
||||||
@ -625,14 +583,11 @@ bool Matrix4x4::Similar(const Matrix4x4& other, double epsilon) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Eule
|
namespace Eule {
|
||||||
{
|
std::ostream &operator<<(std::ostream &os, const Matrix4x4 &m) {
|
||||||
std::ostream& operator<< (std::ostream& os, const Matrix4x4& m)
|
|
||||||
{
|
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
for (std::size_t y = 0; y < 4; y++)
|
for (std::size_t y = 0; y < 4; y++) {
|
||||||
{
|
|
||||||
for (std::size_t x = 0; x < 4; x++)
|
for (std::size_t x = 0; x < 4; x++)
|
||||||
os << " | " << m[y][x];
|
os << " | " << m[y][x];
|
||||||
|
|
||||||
@ -642,12 +597,10 @@ namespace Eule
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wostream& operator<< (std::wostream& os, const Matrix4x4& m)
|
std::wostream &operator<<(std::wostream &os, const Matrix4x4 &m) {
|
||||||
{
|
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
for (std::size_t y = 0; y < 4; y++)
|
for (std::size_t y = 0; y < 4; y++) {
|
||||||
{
|
|
||||||
for (std::size_t x = 0; x < 4; x++)
|
for (std::size_t x = 0; x < 4; x++)
|
||||||
os << L" | " << m[y][x];
|
os << L" | " << m[y][x];
|
||||||
|
|
||||||
@ -657,3 +610,4 @@ namespace Eule
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "gcccompat.h"
|
#include "gcccompat.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
Quaternion::Quaternion()
|
Quaternion::Quaternion()
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "Matrix4x4.h"
|
#include "Matrix4x4.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** 3D rotation representation
|
/** 3D rotation representation
|
||||||
*/
|
*/
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace Eule;
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
// Checks if the random number generator is initialized. Does nothing if it is, initializes if it isn't.
|
// Checks if the random number generator is initialized. Does nothing if it is, initializes if it isn't.
|
||||||
#define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng();
|
#define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng();
|
||||||
|
|
||||||
void Random::InitRng()
|
void Random::InitRng() {
|
||||||
{
|
|
||||||
// Create truly random source (from hardware events)
|
// Create truly random source (from hardware events)
|
||||||
std::random_device randomSource;
|
std::random_device randomSource;
|
||||||
|
|
||||||
@ -26,24 +24,21 @@ void Random::InitRng()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Will return a random double between 0 and 1
|
// Will return a random double between 0 and 1
|
||||||
double Random::RandomFloat()
|
double Random::RandomFloat() {
|
||||||
{
|
|
||||||
MAKE_SURE_RNG_IS_INITIALIZED;
|
MAKE_SURE_RNG_IS_INITIALIZED;
|
||||||
|
|
||||||
return (rng() % 694206942069ll) / 694206942069.0;
|
return (rng() % 694206942069ll) / 694206942069.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will return a random unsigned integer.
|
// Will return a random unsigned integer.
|
||||||
unsigned int Random::RandomUint()
|
unsigned int Random::RandomUint() {
|
||||||
{
|
|
||||||
MAKE_SURE_RNG_IS_INITIALIZED;
|
MAKE_SURE_RNG_IS_INITIALIZED;
|
||||||
|
|
||||||
return rng();
|
return rng();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will return a random integer
|
// Will return a random integer
|
||||||
unsigned int Random::RandomInt()
|
unsigned int Random::RandomInt() {
|
||||||
{
|
|
||||||
MAKE_SURE_RNG_IS_INITIALIZED;
|
MAKE_SURE_RNG_IS_INITIALIZED;
|
||||||
|
|
||||||
// Since this is supposed to return a random value anyways,
|
// Since this is supposed to return a random value anyways,
|
||||||
@ -53,24 +48,22 @@ unsigned int Random::RandomInt()
|
|||||||
|
|
||||||
// Will return a random double within a range
|
// Will return a random double within a range
|
||||||
// These bounds are INCLUSIVE!
|
// These bounds are INCLUSIVE!
|
||||||
double Random::RandomRange(double min, double max)
|
double Random::RandomRange(double min, double max) {
|
||||||
{
|
|
||||||
return (RandomFloat() * (max - min)) + min;
|
return (RandomFloat() * (max - min)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will return a random integer within a range. This is faster than '(int)RandomRange(x,y)'
|
// Will return a random integer within a range. This is faster than '(int)RandomRange(x,y)'
|
||||||
// These bounds are INCLUSIVE!
|
// These bounds are INCLUSIVE!
|
||||||
int Random::RandomIntRange(int min, int max)
|
int Random::RandomIntRange(int min, int max) {
|
||||||
{
|
|
||||||
MAKE_SURE_RNG_IS_INITIALIZED;
|
MAKE_SURE_RNG_IS_INITIALIZED;
|
||||||
|
|
||||||
return (rng() % (max + 1 - min)) + min;
|
return (rng() % (max + 1 - min)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Random::RandomChance(const double chance)
|
bool Random::RandomChance(const double chance) {
|
||||||
{
|
|
||||||
return RandomFloat() <= chance;
|
return RandomFloat() <= chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mt19937 Random::rng;
|
std::mt19937 Random::rng;
|
||||||
bool Random::isRngInitialized = false;
|
bool Random::isRngInitialized = false;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** Extensive random number generator
|
/** Extensive random number generator
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Eule/Vector2.h"
|
#include "../Eule/Vector2.h"
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** Trivial data structure representing a rectangle
|
/** Trivial data structure representing a rectangle
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "TrapazoidalPrismCollider.h"
|
#include "TrapazoidalPrismCollider.h"
|
||||||
|
|
||||||
using namespace Eule;
|
using namespace Leonetienne::Eule;
|
||||||
|
|
||||||
TrapazoidalPrismCollider::TrapazoidalPrismCollider()
|
TrapazoidalPrismCollider::TrapazoidalPrismCollider()
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "Collider.h"
|
#include "Collider.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
/** A collider describing a trapazoidal prism.
|
/** A collider describing a trapazoidal prism.
|
||||||
* A trapazoidal prism is basically a box, but each vertex can be manipulated individually, altering
|
* A trapazoidal prism is basically a box, but each vertex can be manipulated individually, altering
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vector2<T>::operator Vector3<T>() const
|
Vector2<T>::operator Vector3<T>() const
|
||||||
@ -322,8 +322,8 @@ namespace Eule {
|
|||||||
bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const
|
bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(::Eule::Math::Similar(x, other.x, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
|
||||||
(::Eule::Math::Similar(y, other.y, epsilon))
|
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vector3<T>::operator Vector2<T>() const
|
Vector3<T>::operator Vector2<T>() const
|
||||||
{
|
{
|
||||||
@ -235,9 +235,9 @@ namespace Eule {
|
|||||||
bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const
|
bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(::Eule::Math::Similar(x, other.x, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
|
||||||
(::Eule::Math::Similar(y, other.y, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
|
||||||
(::Eule::Math::Similar(z, other.z, epsilon))
|
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "Matrix4x4.h"
|
#include "Matrix4x4.h"
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Vector2;
|
class Vector2;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
The T=int instantiation only exists to store a value-pair of two ints. Not so-much as a vector in terms of vector calculus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Eule {
|
namespace Leonetienne::Eule {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vector4<T>::operator Vector2<T>() const
|
Vector4<T>::operator Vector2<T>() const
|
||||||
@ -183,10 +183,10 @@ namespace Eule {
|
|||||||
bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const
|
bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(::Eule::Math::Similar(x, other.x, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
|
||||||
(::Eule::Math::Similar(y, other.y, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
|
||||||
(::Eule::Math::Similar(z, other.z, epsilon)) &&
|
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon)) &&
|
||||||
(::Eule::Math::Similar(w, other.w, epsilon))
|
(::Leonetienne::Eule::Math::Similar(w, other.w, epsilon))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "Matrix4x4.h"
|
#include "Matrix4x4.h"
|
||||||
|
|
||||||
namespace Eule
|
namespace Leonetienne::Eule
|
||||||
{
|
{
|
||||||
template <typename T> class Vector2;
|
template <typename T> class Vector2;
|
||||||
template <typename T> class Vector3;
|
template <typename T> class Vector3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user