Moved everything in namespace Leonetienne::Eule

This commit is contained in:
Leonetienne 2022-03-06 19:58:59 +01:00
parent 3c8391d9ce
commit be63652df6
19 changed files with 661 additions and 713 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#include "Vector3.h"
namespace Eule
namespace Leonetienne::Eule
{
/** Abstract class of a collider domain.
* Specializations describe a shape in 3d space, and provide implementations of the methods below,

View File

@ -2,14 +2,16 @@
// Pretty sure the compiler will optimize these calculations out...
//! Pi up to 50 decimal places
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
namespace Leonetienne::Eule {
//! Pi up to 50 decimal places
static constexpr double PI = 3.14159265358979323846264338327950288419716939937510;
//! Pi divided by two
static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755;
//! Pi divided by two
static constexpr double HALF_PI = 1.57079632679489661923132169163975144209858469968755;
//! Factor to convert degrees to radians
static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222;
//! Factor to convert degrees to radians
static constexpr double Deg2Rad = 0.0174532925199432957692369076848861271344287188854172222222222222;
//! Factor to convert radians to degrees
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
//! Factor to convert radians to degrees
static constexpr double Rad2Deg = 57.295779513082320876798154814105170332405472466564427711013084788;
}

View File

@ -2,10 +2,9 @@
#include "Constants.h"
#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)
throw std::logic_error("Division by zero");
@ -21,9 +20,9 @@ int Math::Mod(const int numerator, const int denominator)
// Else: generalized formula
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;
}
}

View File

@ -2,7 +2,7 @@
#include <stdexcept>
#include <math.h>
namespace Eule
namespace Leonetienne::Eule
{
/** Math utility class containing basic functions.
*/

View File

@ -7,36 +7,32 @@
#include <immintrin.h>
#endif
using namespace Eule;
namespace Leonetienne::Eule {
Matrix4x4::Matrix4x4()
{
Matrix4x4::Matrix4x4() {
// Create identity matrix
for (std::size_t i = 0; i < 4; i++)
for (std::size_t j = 0; j < 4; j++)
v[i][j] = double(i == j);
return;
}
}
Matrix4x4::Matrix4x4(const Matrix4x4& other)
{
Matrix4x4::Matrix4x4(const Matrix4x4 &other) {
v = other.v;
return;
}
}
Matrix4x4::Matrix4x4(Matrix4x4&& other) noexcept
{
Matrix4x4::Matrix4x4(Matrix4x4 &&other) noexcept {
v = std::move(other.v);
return;
}
}
Matrix4x4 Matrix4x4::operator*(const Matrix4x4& other) const
{
Matrix4x4 Matrix4x4::operator*(const Matrix4x4 &other) const {
Matrix4x4 newMatrix;
newMatrix.p = 1;
#ifndef _EULE_NO_INTRINSICS_
#ifndef _EULE_NO_INTRINSICS_
/* <= Matrix3x3 multiplication => */
@ -117,7 +113,7 @@ Matrix4x4 Matrix4x4::operator*(const Matrix4x4& other) const
newMatrix.h = sum[1];
newMatrix.l = sum[2];
#else
#else
// Rotation, Scaling
@ -139,33 +135,29 @@ Matrix4x4 Matrix4x4::operator*(const Matrix4x4& other) const
newMatrix[1][3] = v[1][3] + other[1][3];
newMatrix[2][3] = v[2][3] + other[2][3];
#endif
#endif
return newMatrix;
}
}
void Matrix4x4::operator*=(const Matrix4x4& other)
{
void Matrix4x4::operator*=(const Matrix4x4 &other) {
*this = *this * other;
return;
}
}
Matrix4x4 Matrix4x4::operator/(const Matrix4x4& other) const
{
Matrix4x4 Matrix4x4::operator/(const Matrix4x4 &other) const {
return *this * other.Inverse3x3();
}
}
void Matrix4x4::operator/=(const Matrix4x4& other)
{
void Matrix4x4::operator/=(const Matrix4x4 &other) {
*this = *this * other.Inverse3x3();
return;
}
}
Matrix4x4 Matrix4x4::operator*(const double scalar) const
{
Matrix4x4 Matrix4x4::operator*(const double scalar) const {
Matrix4x4 m;
#ifndef _EULE_NO_INTRINSICS_
#ifndef _EULE_NO_INTRINSICS_
// Load matrix rows
__m256d __row0 = _mm256_set_pd(v[0][3], v[0][2], v[0][1], v[0][0]);
@ -188,41 +180,37 @@ Matrix4x4 Matrix4x4::operator*(const double scalar) const
_mm256_storeu_pd(m.v[2].data(), __sr2);
_mm256_storeu_pd(m.v[3].data(), __sr3);
#else
#else
for (std::size_t x = 0; x < 4; x++)
for (std::size_t y = 0; y < 4; y++)
m[x][y] = v[x][y] * scalar;
#endif
#endif
return m;
}
}
void Matrix4x4::operator*=(const double scalar)
{
void Matrix4x4::operator*=(const double scalar) {
*this = *this * scalar;
return;
}
}
Matrix4x4 Matrix4x4::operator/(const double denominator) const
{
Matrix4x4 Matrix4x4::operator/(const double denominator) const {
const double precomputeDivision = 1.0 / denominator;
return *this * precomputeDivision;
}
}
void Matrix4x4::operator/=(const double denominator)
{
void Matrix4x4::operator/=(const double denominator) {
*this = *this / denominator;
return;
}
}
Matrix4x4 Matrix4x4::operator+(const Matrix4x4& other) const
{
Matrix4x4 Matrix4x4::operator+(const Matrix4x4 &other) const {
Matrix4x4 m;
#ifndef _EULE_NO_INTRINSICS_
#ifndef _EULE_NO_INTRINSICS_
// Load matrix rows
__m256d __row0a = _mm256_set_pd(v[0][3], v[0][2], v[0][1], v[0][0]);
@ -247,20 +235,19 @@ Matrix4x4 Matrix4x4::operator+(const Matrix4x4& other) const
_mm256_storeu_pd(m.v[2].data(), __sr2);
_mm256_storeu_pd(m.v[3].data(), __sr3);
#else
#else
for (std::size_t x = 0; x < 4; x++)
for (std::size_t y = 0; y < 4; y++)
m[x][y] = v[x][y] + other[x][y];
#endif
#endif
return m;
}
}
void Matrix4x4::operator+=(const Matrix4x4& other)
{
#ifndef _EULE_NO_INTRINSICS_
void Matrix4x4::operator+=(const Matrix4x4 &other) {
#ifndef _EULE_NO_INTRINSICS_
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
// Load matrix rows
@ -286,20 +273,19 @@ void Matrix4x4::operator+=(const Matrix4x4& other)
_mm256_storeu_pd(v[2].data(), __sr2);
_mm256_storeu_pd(v[3].data(), __sr3);
#else
#else
*this = *this + other;
#endif
#endif
return;
}
}
Matrix4x4 Matrix4x4::operator-(const Matrix4x4& other) const
{
Matrix4x4 Matrix4x4::operator-(const Matrix4x4 &other) const {
Matrix4x4 m;
#ifndef _EULE_NO_INTRINSICS_
#ifndef _EULE_NO_INTRINSICS_
// Load matrix rows
__m256d __row0a = _mm256_set_pd(v[0][3], v[0][2], v[0][1], v[0][0]);
@ -324,20 +310,19 @@ Matrix4x4 Matrix4x4::operator-(const Matrix4x4& other) const
_mm256_storeu_pd(m.v[2].data(), __sr2);
_mm256_storeu_pd(m.v[3].data(), __sr3);
#else
#else
for (std::size_t x = 0; x < 4; x++)
for (std::size_t y = 0; y < 4; y++)
m[x][y] = v[x][y] - other[x][y];
#endif
#endif
return m;
}
}
void Matrix4x4::operator-=(const Matrix4x4& other)
{
#ifndef _EULE_NO_INTRINSICS_
void Matrix4x4::operator-=(const Matrix4x4 &other) {
#ifndef _EULE_NO_INTRINSICS_
// Doing it again is a tad directer, and thus faster. We avoid an intermittent Matrix4x4 instance
// Load matrix rows
@ -363,81 +348,69 @@ void Matrix4x4::operator-=(const Matrix4x4& other)
_mm256_storeu_pd(v[2].data(), __sr2);
_mm256_storeu_pd(v[3].data(), __sr3);
#else
#else
* this = *this - other;
*this = *this - other;
#endif
#endif
return;
}
}
std::array<double, 4>& Matrix4x4::operator[](std::size_t y)
{
std::array<double, 4> &Matrix4x4::operator[](std::size_t 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];
}
}
void Matrix4x4::operator=(const Matrix4x4& other)
{
void Matrix4x4::operator=(const Matrix4x4 &other) {
v = other.v;
return;
}
}
void Matrix4x4::operator=(Matrix4x4&& other) noexcept
{
void Matrix4x4::operator=(Matrix4x4 &&other) noexcept {
v = std::move(other.v);
return;
}
}
bool Matrix4x4::operator==(const Matrix4x4& other)
{
bool Matrix4x4::operator==(const Matrix4x4 &other) {
return v == other.v;
}
}
bool Matrix4x4::operator!=(const Matrix4x4& other)
{
bool Matrix4x4::operator!=(const Matrix4x4 &other) {
return !operator==(other);
}
}
bool Matrix4x4::operator==(const Matrix4x4& other) const
{
bool Matrix4x4::operator==(const Matrix4x4 &other) const {
return v == other.v;
}
}
bool Matrix4x4::operator!=(const Matrix4x4& other) const
{
bool Matrix4x4::operator!=(const Matrix4x4 &other) const {
return !operator==(other);
}
}
const Vector3d Matrix4x4::GetTranslationComponent() const
{
const Vector3d Matrix4x4::GetTranslationComponent() const {
return Vector3d(d, h, l);
}
}
void Matrix4x4::SetTranslationComponent(const Vector3d& trans)
{
void Matrix4x4::SetTranslationComponent(const Vector3d &trans) {
d = trans.x;
h = trans.y;
l = trans.z;
return;
}
}
Matrix4x4 Matrix4x4::DropTranslationComponents() const
{
Matrix4x4 Matrix4x4::DropTranslationComponents() const {
Matrix4x4 m(*this);
m.d = 0;
m.h = 0;
m.l = 0;
return m;
}
}
Matrix4x4 Matrix4x4::Transpose3x3() const
{
Matrix4x4 Matrix4x4::Transpose3x3() const {
Matrix4x4 trans(*this); // Keep other cells
for (std::size_t i = 0; i < 3; i++)
@ -445,10 +418,9 @@ Matrix4x4 Matrix4x4::Transpose3x3() const
trans[j][i] = v[i][j];
return trans;
}
}
Matrix4x4 Matrix4x4::Transpose4x4() const
{
Matrix4x4 Matrix4x4::Transpose4x4() const {
Matrix4x4 trans;
for (std::size_t i = 0; i < 4; i++)
@ -456,37 +428,35 @@ Matrix4x4 Matrix4x4::Transpose4x4() const
trans[j][i] = v[i][j];
return trans;
}
}
Matrix4x4 Matrix4x4::Multiply4x4(const Matrix4x4& o) const
{
Matrix4x4 Matrix4x4::Multiply4x4(const Matrix4x4 &o) const {
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][1] = (v[0][0]*o[0][1]) + (v[0][1]*o[1][1]) + (v[0][2]*o[2][1]) + (v[0][3]*o[3][1]);
m[0][2] = (v[0][0]*o[0][2]) + (v[0][1]*o[1][2]) + (v[0][2]*o[2][2]) + (v[0][3]*o[3][2]);
m[0][3] = (v[0][0]*o[0][3]) + (v[0][1]*o[1][3]) + (v[0][2]*o[2][3]) + (v[0][3]*o[3][3]);
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][1] = (v[0][0] * o[0][1]) + (v[0][1] * o[1][1]) + (v[0][2] * o[2][1]) + (v[0][3] * o[3][1]);
m[0][2] = (v[0][0] * o[0][2]) + (v[0][1] * o[1][2]) + (v[0][2] * o[2][2]) + (v[0][3] * o[3][2]);
m[0][3] = (v[0][0] * o[0][3]) + (v[0][1] * o[1][3]) + (v[0][2] * o[2][3]) + (v[0][3] * o[3][3]);
m[1][0] = (v[1][0]*o[0][0]) + (v[1][1]*o[1][0]) + (v[1][2]*o[2][0]) + (v[1][3]*o[3][0]);
m[1][1] = (v[1][0]*o[0][1]) + (v[1][1]*o[1][1]) + (v[1][2]*o[2][1]) + (v[1][3]*o[3][1]);
m[1][2] = (v[1][0]*o[0][2]) + (v[1][1]*o[1][2]) + (v[1][2]*o[2][2]) + (v[1][3]*o[3][2]);
m[1][3] = (v[1][0]*o[0][3]) + (v[1][1]*o[1][3]) + (v[1][2]*o[2][3]) + (v[1][3]*o[3][3]);
m[1][0] = (v[1][0] * o[0][0]) + (v[1][1] * o[1][0]) + (v[1][2] * o[2][0]) + (v[1][3] * o[3][0]);
m[1][1] = (v[1][0] * o[0][1]) + (v[1][1] * o[1][1]) + (v[1][2] * o[2][1]) + (v[1][3] * o[3][1]);
m[1][2] = (v[1][0] * o[0][2]) + (v[1][1] * o[1][2]) + (v[1][2] * o[2][2]) + (v[1][3] * o[3][2]);
m[1][3] = (v[1][0] * o[0][3]) + (v[1][1] * o[1][3]) + (v[1][2] * o[2][3]) + (v[1][3] * o[3][3]);
m[2][0] = (v[2][0]*o[0][0]) + (v[2][1]*o[1][0]) + (v[2][2]*o[2][0]) + (v[2][3]*o[3][0]);
m[2][1] = (v[2][0]*o[0][1]) + (v[2][1]*o[1][1]) + (v[2][2]*o[2][1]) + (v[2][3]*o[3][1]);
m[2][2] = (v[2][0]*o[0][2]) + (v[2][1]*o[1][2]) + (v[2][2]*o[2][2]) + (v[2][3]*o[3][2]);
m[2][3] = (v[2][0]*o[0][3]) + (v[2][1]*o[1][3]) + (v[2][2]*o[2][3]) + (v[2][3]*o[3][3]);
m[2][0] = (v[2][0] * o[0][0]) + (v[2][1] * o[1][0]) + (v[2][2] * o[2][0]) + (v[2][3] * o[3][0]);
m[2][1] = (v[2][0] * o[0][1]) + (v[2][1] * o[1][1]) + (v[2][2] * o[2][1]) + (v[2][3] * o[3][1]);
m[2][2] = (v[2][0] * o[0][2]) + (v[2][1] * o[1][2]) + (v[2][2] * o[2][2]) + (v[2][3] * o[3][2]);
m[2][3] = (v[2][0] * o[0][3]) + (v[2][1] * o[1][3]) + (v[2][2] * o[2][3]) + (v[2][3] * o[3][3]);
m[3][0] = (v[3][0]*o[0][0]) + (v[3][1]*o[1][0]) + (v[3][2]*o[2][0]) + (v[3][3]*o[3][0]);
m[3][1] = (v[3][0]*o[0][1]) + (v[3][1]*o[1][1]) + (v[3][2]*o[2][1]) + (v[3][3]*o[3][1]);
m[3][2] = (v[3][0]*o[0][2]) + (v[3][1]*o[1][2]) + (v[3][2]*o[2][2]) + (v[3][3]*o[3][2]);
m[3][3] = (v[3][0]*o[0][3]) + (v[3][1]*o[1][3]) + (v[3][2]*o[2][3]) + (v[3][3]*o[3][3]);
m[3][0] = (v[3][0] * o[0][0]) + (v[3][1] * o[1][0]) + (v[3][2] * o[2][0]) + (v[3][3] * o[3][0]);
m[3][1] = (v[3][0] * o[0][1]) + (v[3][1] * o[1][1]) + (v[3][2] * o[2][1]) + (v[3][3] * o[3][1]);
m[3][2] = (v[3][0] * o[0][2]) + (v[3][1] * o[1][2]) + (v[3][2] * o[2][2]) + (v[3][3] * o[3][2]);
m[3][3] = (v[3][0] * o[0][3]) + (v[3][1] * o[1][3]) + (v[3][2] * o[2][3]) + (v[3][3] * o[3][3]);
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)
throw std::runtime_error("Dimension out of range! 0 <= n <= 4");
@ -496,30 +466,26 @@ Matrix4x4 Matrix4x4::GetCofactors(std::size_t p, std::size_t q, std::size_t n) c
std::size_t j = 0;
for (std::size_t y = 0; y < n; y++)
for (std::size_t x = 0; x < n; x++)
{
if ((y != p) && (x != q))
{
for (std::size_t x = 0; x < n; x++) {
if ((y != p) && (x != q)) {
cofs[i][j] = v[y][x];
j++;
}
if (j == n - 1)
{
if (j == n - 1) {
j = 0;
i++;
}
}
return cofs;
}
}
/*
* BEGIN_REF
* 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)
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)
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);
d += sign * v[0][x] * cofs.Determinant(n - 1);
@ -538,10 +503,9 @@ double Matrix4x4::Determinant(std::size_t n) const
}
return d;
}
}
Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const
{
Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const {
if (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;
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);
// sign of adj[j][i] positive if sum of row
@ -563,10 +526,9 @@ Matrix4x4 Matrix4x4::Adjoint(std::size_t n) const
}
return adj;
}
}
Matrix4x4 Matrix4x4::Inverse3x3() const
{
Matrix4x4 Matrix4x4::Inverse3x3() const {
Matrix4x4 inv;
double det = Determinant(3);
@ -582,10 +544,9 @@ Matrix4x4 Matrix4x4::Inverse3x3() const
inv.SetTranslationComponent(-GetTranslationComponent());
return inv;
}
}
Matrix4x4 Matrix4x4::Inverse4x4() const
{
Matrix4x4 Matrix4x4::Inverse4x4() const {
Matrix4x4 inv;
double det = Determinant(4);
@ -599,40 +560,34 @@ Matrix4x4 Matrix4x4::Inverse4x4() const
inv[i][j] = adj[i][j] / det;
return inv;
}
}
/*
* END REF
*/
bool Matrix4x4::IsInversible3x3() const
{
bool Matrix4x4::IsInversible3x3() const {
return (Determinant(3) != 0);
}
}
bool Matrix4x4::IsInversible4x4() const
{
bool Matrix4x4::IsInversible4x4() const {
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 j = 0; j < 4; j++)
if (!Math::Similar(v[i][j], other[i][j], epsilon))
return false;
return true;
}
}
namespace Eule
{
std::ostream& operator<< (std::ostream& os, const Matrix4x4& m)
{
namespace Eule {
std::ostream &operator<<(std::ostream &os, const Matrix4x4 &m) {
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++)
os << " | " << m[y][x];
@ -642,12 +597,10 @@ namespace Eule
return os;
}
std::wostream& operator<< (std::wostream& os, const Matrix4x4& m)
{
std::wostream &operator<<(std::wostream &os, const Matrix4x4 &m) {
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++)
os << L" | " << m[y][x];
@ -656,4 +609,5 @@ namespace Eule
return os;
}
}
}

View File

@ -3,7 +3,7 @@
#include <array>
#include <ostream>
namespace Eule
namespace Leonetienne::Eule
{
template <class T>
class Vector3;

View File

@ -10,7 +10,7 @@
#include "gcccompat.h"
#endif
namespace Eule {
namespace Leonetienne::Eule {
Quaternion::Quaternion()
{

View File

@ -4,7 +4,7 @@
#include "Matrix4x4.h"
#include <mutex>
namespace Eule
namespace Leonetienne::Eule
{
/** 3D rotation representation
*/

View File

@ -2,13 +2,11 @@
#include <array>
#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.
#define MAKE_SURE_RNG_IS_INITIALIZED if (!isRngInitialized) InitRng();
void Random::InitRng()
{
void Random::InitRng() {
// Create truly random source (from hardware events)
std::random_device randomSource;
@ -23,54 +21,49 @@ void Random::InitRng()
isRngInitialized = true;
return;
}
}
// Will return a random double between 0 and 1
double Random::RandomFloat()
{
double Random::RandomFloat() {
MAKE_SURE_RNG_IS_INITIALIZED;
return (rng() % 694206942069ll) / 694206942069.0;
}
}
// Will return a random unsigned integer.
unsigned int Random::RandomUint()
{
unsigned int Random::RandomUint() {
MAKE_SURE_RNG_IS_INITIALIZED;
return rng();
}
}
// Will return a random integer
unsigned int Random::RandomInt()
{
unsigned int Random::RandomInt() {
MAKE_SURE_RNG_IS_INITIALIZED;
// Since this is supposed to return a random value anyways,
// we can let the random uint overflow without any problems.
return (int)rng();
}
return (int) rng();
}
// Will return a random double within a range
// These bounds are INCLUSIVE!
double Random::RandomRange(double min, double max)
{
double Random::RandomRange(double min, double max) {
return (RandomFloat() * (max - min)) + min;
}
}
// Will return a random integer within a range. This is faster than '(int)RandomRange(x,y)'
// These bounds are INCLUSIVE!
int Random::RandomIntRange(int min, int max)
{
int Random::RandomIntRange(int min, int max) {
MAKE_SURE_RNG_IS_INITIALIZED;
return (rng() % (max + 1 - min)) + min;
}
}
bool Random::RandomChance(const double chance)
{
bool Random::RandomChance(const double chance) {
return RandomFloat() <= chance;
}
}
std::mt19937 Random::rng;
bool Random::isRngInitialized = false;
std::mt19937 Random::rng;
bool Random::isRngInitialized = false;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <random>
namespace Eule
namespace Leonetienne::Eule
{
/** Extensive random number generator
*/

View File

@ -1,7 +1,7 @@
#pragma once
#include "../Eule/Vector2.h"
namespace Eule
namespace Leonetienne::Eule
{
/** Trivial data structure representing a rectangle
*/

View File

@ -1,6 +1,6 @@
#include "TrapazoidalPrismCollider.h"
using namespace Eule;
using namespace Leonetienne::Eule;
TrapazoidalPrismCollider::TrapazoidalPrismCollider()
{

View File

@ -3,7 +3,7 @@
#include "Collider.h"
#include <array>
namespace Eule
namespace Leonetienne::Eule
{
/** A collider describing a trapazoidal prism.
* A trapazoidal prism is basically a box, but each vertex can be manipulated individually, altering

View File

@ -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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector2<T>::operator Vector3<T>() const
@ -322,8 +322,8 @@ namespace Eule {
bool Vector2<T>::Similar(const Vector2<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon))
;
}

View File

@ -2,7 +2,7 @@
#include <cstdlib>
#include <sstream>
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
class Vector3;

View File

@ -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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector3<T>::operator Vector2<T>() const
{
@ -235,9 +235,9 @@ namespace Eule {
bool Vector3<T>::Similar(const Vector3<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon))
;
}

View File

@ -5,7 +5,7 @@
#include <sstream>
#include "Matrix4x4.h"
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
class Vector2;

View File

@ -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.
*/
namespace Eule {
namespace Leonetienne::Eule {
template<typename T>
Vector4<T>::operator Vector2<T>() const
@ -183,10 +183,10 @@ namespace Eule {
bool Vector4<T>::Similar(const Vector4<T>& other, double epsilon) const
{
return
(::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Eule::Math::Similar(z, other.z, epsilon)) &&
(::Eule::Math::Similar(w, other.w, epsilon))
(::Leonetienne::Eule::Math::Similar(x, other.x, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(y, other.y, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(z, other.z, epsilon)) &&
(::Leonetienne::Eule::Math::Similar(w, other.w, epsilon))
;
}

View File

@ -5,7 +5,7 @@
#include <sstream>
#include "Matrix4x4.h"
namespace Eule
namespace Leonetienne::Eule
{
template <typename T> class Vector2;
template <typename T> class Vector3;