aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2023-12-03 09:27:32 +0100
committervimene <vincent.menegaux@gmail.com>2023-12-03 09:27:32 +0100
commit48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0 (patch)
tree259ec6e395e44b0af117adc9605203f8affb4b0f /src/math
parent5a8bc0a4936cdd461c43740437541f8c991ff117 (diff)
downloadengine-48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0.tar.gz
renamed MathVector{2,3,4} to Vector{2,3,4} and Mat4 to Matrix4 in engine::math
Diffstat (limited to 'src/math')
-rw-r--r--src/math/mat4.cpp34
-rw-r--r--src/math/mat4.h34
-rw-r--r--src/math/vector.cpp90
-rw-r--r--src/math/vector.h100
4 files changed, 129 insertions, 129 deletions
diff --git a/src/math/mat4.cpp b/src/math/mat4.cpp
index 6418e9c..f1f28b7 100644
--- a/src/math/mat4.cpp
+++ b/src/math/mat4.cpp
@@ -1,11 +1,11 @@
#include "math/mat4.h"
#include <array>
#include <cmath>
-#include "math/math_vector.h"
+#include "math/vector.h"
using namespace engine::math;
-Mat4 Mat4::idty() {
+Matrix4 Matrix4::idty() {
return {
1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
@@ -14,7 +14,7 @@ Mat4 Mat4::idty() {
};
}
-Mat4 Mat4::translate(MathVector3 v) {
+Matrix4 Matrix4::translate(Vector3 v) {
return {
1.f, 0.f, 0.f, v.x,
0.f, 1.f, 0.f, v.y,
@@ -22,7 +22,7 @@ Mat4 Mat4::translate(MathVector3 v) {
0.f, 0.f, 0.f, 1.f,
};
}
-Mat4 Mat4::scale(float fac) {
+Matrix4 Matrix4::scale(float fac) {
return {
fac, 0.f, 0.f, 0.f,
0.f, fac, 0.f, 0.f,
@@ -31,7 +31,7 @@ Mat4 Mat4::scale(float fac) {
};
}
-Mat4 Mat4::rot_x(float a) {
+Matrix4 Matrix4::rot_x(float a) {
float c = std::cos(a);
float s = std::sin(a);
return {
@@ -42,7 +42,7 @@ Mat4 Mat4::rot_x(float a) {
};
}
-Mat4 Mat4::rot_y(float a) {
+Matrix4 Matrix4::rot_y(float a) {
float c = std::cos(a);
float s = std::sin(a);
return {
@@ -53,7 +53,7 @@ Mat4 Mat4::rot_y(float a) {
};
}
-Mat4 Mat4::rot_z(float a) {
+Matrix4 Matrix4::rot_z(float a) {
float c = std::cos(a);
float s = std::sin(a);
return {
@@ -64,7 +64,7 @@ Mat4 Mat4::rot_z(float a) {
};
}
-Mat4 Mat4::projection(float aspect_ratio, float min_z, float max_z) {
+Matrix4 Matrix4::projection(float aspect_ratio, float min_z, float max_z) {
return {{
aspect_ratio, 0.f, 0.f, 0.f,
0.f, -1.f, 0.f, 0.f,
@@ -73,11 +73,11 @@ Mat4 Mat4::projection(float aspect_ratio, float min_z, float max_z) {
}};
}
-Mat4 Mat4::operator+() {
+Matrix4 Matrix4::operator+() {
return *this;
}
-Mat4 Mat4::operator-() {
+Matrix4 Matrix4::operator-() {
return {
-values[ 0], -values[ 1], -values[ 2], -values[ 3],
-values[ 4], -values[ 5], -values[ 6], -values[ 7],
@@ -86,7 +86,7 @@ Mat4 Mat4::operator-() {
};
}
-Mat4 Mat4::operator+(Mat4 m) {
+Matrix4 Matrix4::operator+(Matrix4 m) {
return {
values[ 0] + m.values[ 0], values[ 1] + m.values[ 1], values[ 2] + m.values[ 2], values[ 3] + m.values[ 3],
values[ 4] + m.values[ 4], values[ 5] + m.values[ 5], values[ 6] + m.values[ 6], values[ 7] + m.values[ 7],
@@ -95,12 +95,12 @@ Mat4 Mat4::operator+(Mat4 m) {
};
}
-Mat4 Mat4::operator-(Mat4 m) {
+Matrix4 Matrix4::operator-(Matrix4 m) {
return *this + (-m);
}
-Mat4 Mat4::operator*(Mat4 m) {
- Mat4 ret;
+Matrix4 Matrix4::operator*(Matrix4 m) {
+ Matrix4 ret;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
ret.values[i * 4 + j] = 0.f;
@@ -111,7 +111,7 @@ Mat4 Mat4::operator*(Mat4 m) {
return ret;
}
-MathVector4 Mat4::operator*(MathVector4 v) {
+Vector4 Matrix4::operator*(Vector4 v) {
return {
values[ 0] * v.x + values[ 1] * v.y + values[ 2] * v.z + values[ 3] * v.w,
values[ 4] * v.x + values[ 5] * v.y + values[ 6] * v.z + values[ 7] * v.w,
@@ -120,7 +120,7 @@ MathVector4 Mat4::operator*(MathVector4 v) {
};
}
-std::array<MathVector4, 4> Mat4::to_vecs() {
+std::array<Vector4, 4> Matrix4::to_vecs() {
return {{
{ values[ 0], values[ 4], values[ 8], values[12] },
{ values[ 1], values[ 5], values[ 9], values[13] },
@@ -129,7 +129,7 @@ std::array<MathVector4, 4> Mat4::to_vecs() {
}};
}
-Mat4 engine::math::operator*(float fac, Mat4 m) {
+Matrix4 engine::math::operator*(float fac, Matrix4 m) {
return {
fac * m.values[ 0], fac * m.values[ 1], fac * m.values[ 2], fac * m.values[ 3],
fac * m.values[ 4], fac * m.values[ 5], fac * m.values[ 6], fac * m.values[ 7],
diff --git a/src/math/mat4.h b/src/math/mat4.h
index d8b66c4..66d6cd2 100644
--- a/src/math/mat4.h
+++ b/src/math/mat4.h
@@ -2,32 +2,32 @@
#define MATH_MAT4_H
#include <array>
-#include "math/math_vector.h"
+#include "math/vector.h"
namespace engine::math {
-class Mat4 {
+class Matrix4 {
public:
- static Mat4 idty();
- static Mat4 translate(MathVector3 v);
- static Mat4 scale(float fac);
- static Mat4 rot_x(float a);
- static Mat4 rot_y(float a);
- static Mat4 rot_z(float a);
- static Mat4 projection(float aspect_ratio, float min_z, float max_z);
+ static Matrix4 idty();
+ static Matrix4 translate(Vector3 v);
+ static Matrix4 scale(float fac);
+ static Matrix4 rot_x(float a);
+ static Matrix4 rot_y(float a);
+ static Matrix4 rot_z(float a);
+ static Matrix4 projection(float aspect_ratio, float min_z, float max_z);
std::array<float, 16> values;
- Mat4 operator+();
- Mat4 operator-();
- Mat4 operator+(Mat4 m);
- Mat4 operator-(Mat4 m);
- Mat4 operator*(Mat4 m);
- MathVector4 operator*(MathVector4 v);
- std::array<MathVector4, 4> to_vecs();
+ Matrix4 operator+();
+ Matrix4 operator-();
+ Matrix4 operator+(Matrix4 m);
+ Matrix4 operator-(Matrix4 m);
+ Matrix4 operator*(Matrix4 m);
+ Vector4 operator*(Vector4 v);
+ std::array<Vector4, 4> to_vecs();
};
-Mat4 operator*(float fac, Mat4 m);
+Matrix4 operator*(float fac, Matrix4 m);
}
diff --git a/src/math/vector.cpp b/src/math/vector.cpp
index aacff86..36e813d 100644
--- a/src/math/vector.cpp
+++ b/src/math/vector.cpp
@@ -1,97 +1,97 @@
-#include "math/math_vector.h"
+#include "math/vector.h"
#include <cmath>
using namespace engine::math;
-MathVector2::MathVector2() {
+Vector2::Vector2() {
}
-MathVector2::MathVector2(float x, float y) : x{x}, y{y} {
+Vector2::Vector2(float x, float y) : x{x}, y{y} {
}
-bool MathVector2::operator==(MathVector2 other) const {
+bool Vector2::operator==(Vector2 other) const {
return x == other.x && y == other.y;
}
-bool MathVector2::operator!=(MathVector2 other) const {
+bool Vector2::operator!=(Vector2 other) const {
return !(*this == other);
}
-MathVector2 MathVector2::operator+() const {
+Vector2 Vector2::operator+() const {
return *this;
}
-MathVector2 MathVector2::operator-() const {
+Vector2 Vector2::operator-() const {
return { -x, -y };
}
-MathVector2 MathVector2::operator+(MathVector2 other) const {
+Vector2 Vector2::operator+(Vector2 other) const {
return { x + other.x, y + other.y };
}
-MathVector2 MathVector2::operator-(MathVector2 other) const {
+Vector2 Vector2::operator-(Vector2 other) const {
return *this + (-other);
}
-float MathVector2::det(MathVector2 other) const {
+float Vector2::det(Vector2 other) const {
return this->x * other.y - other.x * this->y;
}
-MathVector2 MathVector2::round() const {
+Vector2 Vector2::round() const {
return { std::round(x), std::round(y) };
}
-MathVector2 engine::math::operator*(float n, MathVector2 other) {
+Vector2 engine::math::operator*(float n, Vector2 other) {
return { n * other.x, n * other.y };
}
-MathVector2 engine::math::operator*(MathVector2 other, float n) {
+Vector2 engine::math::operator*(Vector2 other, float n) {
return n * other;
}
-MathVector2 engine::math::operator/(MathVector2 other, float n) {
+Vector2 engine::math::operator/(Vector2 other, float n) {
return { other.x / n, other.y / n };
}
-MathVector3::MathVector3() {
+Vector3::Vector3() {
}
-MathVector3::MathVector3(float x, float y, float z) : x{x}, y{y}, z{z} {
+Vector3::Vector3(float x, float y, float z) : x{x}, y{y}, z{z} {
}
-bool MathVector3::operator==(MathVector3 other) const {
+bool Vector3::operator==(Vector3 other) const {
return x == other.x && y == other.y && z == other.z;
}
-bool MathVector3::operator!=(MathVector3 other) const {
+bool Vector3::operator!=(Vector3 other) const {
return !(*this == other);
}
-MathVector3 MathVector3::operator+() const {
+Vector3 Vector3::operator+() const {
return *this;
}
-MathVector3 MathVector3::operator-() const {
+Vector3 Vector3::operator-() const {
return { -x, -y, -z };
}
-MathVector3 MathVector3::operator+(MathVector3 other) const {
+Vector3 Vector3::operator+(Vector3 other) const {
return { x + other.x, y + other.y, z + other.z };
}
-MathVector3 MathVector3::operator-(MathVector3 other) const {
+Vector3 Vector3::operator-(Vector3 other) const {
return *this + (-other);
}
-MathVector3 MathVector3::round() const {
+Vector3 Vector3::round() const {
return { std::round(x), std::round(y), std::round(z) };
}
-MathVector2 MathVector3::xy() const {
+Vector2 Vector3::xy() const {
return { x, y };
}
-MathVector3 MathVector3::cross(MathVector3 other) const {
+Vector3 Vector3::cross(Vector3 other) const {
return {
y * other.z - z * other.y,
z * other.x - x * other.z,
@@ -99,77 +99,77 @@ MathVector3 MathVector3::cross(MathVector3 other) const {
};
}
-MathVector3 engine::math::operator*(float n, MathVector3 other) {
+Vector3 engine::math::operator*(float n, Vector3 other) {
return { n * other.x, n * other.y, n * other.z };
}
-MathVector3 engine::math::operator*(MathVector3 other, float n) {
+Vector3 engine::math::operator*(Vector3 other, float n) {
return n * other;
}
-MathVector3 engine::math::operator/(MathVector3 other, float n) {
+Vector3 engine::math::operator/(Vector3 other, float n) {
return { other.x / n, other.y / n, other.z / n };
}
-MathVector4::MathVector4() {
+Vector4::Vector4() {
}
-MathVector4::MathVector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} {
+Vector4::Vector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} {
}
-MathVector4::MathVector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} {
+Vector4::Vector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} {
}
-MathVector4::MathVector4(MathVector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} {
+Vector4::Vector4(Vector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} {
}
-MathVector4::MathVector4(MathVector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} {
+Vector4::Vector4(Vector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} {
}
-bool MathVector4::operator==(MathVector4 other) const {
+bool Vector4::operator==(Vector4 other) const {
return x == other.x && y == other.y && z == other.z && w == other.w;
}
-bool MathVector4::operator!=(MathVector4 other) const {
+bool Vector4::operator!=(Vector4 other) const {
return !(*this == other);
}
-MathVector4 MathVector4::operator+() const {
+Vector4 Vector4::operator+() const {
return *this;
}
-MathVector4 MathVector4::operator-() const {
+Vector4 Vector4::operator-() const {
return { -x, -y, -z, -w };
}
-MathVector4 MathVector4::operator+(MathVector4 other) const {
+Vector4 Vector4::operator+(Vector4 other) const {
return { x + other.x, y + other.y, z + other.z, w + other.w };
}
-MathVector4 MathVector4::operator-(MathVector4 other) const {
+Vector4 Vector4::operator-(Vector4 other) const {
return *this + (-other);
}
-MathVector4 MathVector4::round() const {
+Vector4 Vector4::round() const {
return { std::round(x), std::round(y), std::round(z), std::round(w) };
}
-MathVector3 MathVector4::xyz() const {
+Vector3 Vector4::xyz() const {
return { x, y, z };
}
-MathVector3 MathVector4::div_by_w() const {
+Vector3 Vector4::div_by_w() const {
return xyz() / w;
}
-MathVector4 engine::math::operator*(float n, MathVector4 other) {
+Vector4 engine::math::operator*(float n, Vector4 other) {
return { n * other.x, n * other.y, n * other.z, n * other.w };
}
-MathVector4 engine::math::operator*(MathVector4 other, float n) {
+Vector4 engine::math::operator*(Vector4 other, float n) {
return n * other;
}
-MathVector4 engine::math::operator/(MathVector4 other, float n) {
+Vector4 engine::math::operator/(Vector4 other, float n) {
return { other.x / n, other.y / n, other.z / n, other.w / n };
}
diff --git a/src/math/vector.h b/src/math/vector.h
index 28ae81e..8f7059a 100644
--- a/src/math/vector.h
+++ b/src/math/vector.h
@@ -1,73 +1,73 @@
-#ifndef MATH_MATH_VECTOR_H
-#define MATH_MATH_VECTOR_H
+#ifndef MATH_VECTOR_H
+#define MATH_VECTOR_H
namespace engine::math {
-class MathVector2 {
+class Vector2 {
public:
float x, y;
- MathVector2();
- MathVector2(float x, float y);
- bool operator==(MathVector2 other) const;
- bool operator!=(MathVector2 other) const;
- MathVector2 operator+() const;
- MathVector2 operator-() const;
- MathVector2 operator+(MathVector2 other) const;
- MathVector2 operator-(MathVector2 other) const;
- float det(MathVector2 other) const;
- MathVector2 round() const;
+ Vector2();
+ Vector2(float x, float y);
+ bool operator==(Vector2 other) const;
+ bool operator!=(Vector2 other) const;
+ Vector2 operator+() const;
+ Vector2 operator-() const;
+ Vector2 operator+(Vector2 other) const;
+ Vector2 operator-(Vector2 other) const;
+ float det(Vector2 other) const;
+ Vector2 round() const;
};
-MathVector2 operator*(float n, MathVector2 other);
-MathVector2 operator*(MathVector2 other, float n);
-MathVector2 operator/(MathVector2 other, float n);
+Vector2 operator*(float n, Vector2 other);
+Vector2 operator*(Vector2 other, float n);
+Vector2 operator/(Vector2 other, float n);
-class MathVector3 {
+class Vector3 {
public:
float x, y, z;
- MathVector3();
- MathVector3(float x, float y, float z);
- bool operator==(MathVector3 other) const;
- bool operator!=(MathVector3 other) const;
- MathVector3 operator+() const;
- MathVector3 operator-() const;
- MathVector3 operator+(MathVector3 other) const;
- MathVector3 operator-(MathVector3 other) const;
- MathVector3 round() const;
- MathVector2 xy() const;
- MathVector3 cross(MathVector3 other) const;
+ Vector3();
+ Vector3(float x, float y, float z);
+ bool operator==(Vector3 other) const;
+ bool operator!=(Vector3 other) const;
+ Vector3 operator+() const;
+ Vector3 operator-() const;
+ Vector3 operator+(Vector3 other) const;
+ Vector3 operator-(Vector3 other) const;
+ Vector3 round() const;
+ Vector2 xy() const;
+ Vector3 cross(Vector3 other) const;
};
-MathVector3 operator*(float n, MathVector3 other);
-MathVector3 operator*(MathVector3 other, float n);
-MathVector3 operator/(MathVector3 other, float n);
+Vector3 operator*(float n, Vector3 other);
+Vector3 operator*(Vector3 other, float n);
+Vector3 operator/(Vector3 other, float n);
-class MathVector4 {
+class Vector4 {
public:
float x, y, z, w;
- MathVector4();
- MathVector4(float x, float y, float z, float w);
- MathVector4(float x, float y, float z);
- MathVector4(MathVector3 v, float w);
- MathVector4(MathVector3 v);
- bool operator==(MathVector4 other) const;
- bool operator!=(MathVector4 other) const;
- MathVector4 operator+() const;
- MathVector4 operator-() const;
- MathVector4 operator+(MathVector4 other) const;
- MathVector4 operator-(MathVector4 other) const;
- MathVector4 round() const;
- MathVector3 xyz() const;
- MathVector3 div_by_w() const;
+ Vector4();
+ Vector4(float x, float y, float z, float w);
+ Vector4(float x, float y, float z);
+ Vector4(Vector3 v, float w);
+ Vector4(Vector3 v);
+ bool operator==(Vector4 other) const;
+ bool operator!=(Vector4 other) const;
+ Vector4 operator+() const;
+ Vector4 operator-() const;
+ Vector4 operator+(Vector4 other) const;
+ Vector4 operator-(Vector4 other) const;
+ Vector4 round() const;
+ Vector3 xyz() const;
+ Vector3 div_by_w() const;
};
-MathVector4 operator*(float n, MathVector4 other);
-MathVector4 operator*(MathVector4 other, float n);
-MathVector4 operator/(MathVector4 other, float n);
+Vector4 operator*(float n, Vector4 other);
+Vector4 operator*(Vector4 other, float n);
+Vector4 operator/(Vector4 other, float n);
}
-#endif // MATH_MATH_VECTOR_H
+#endif // MATH_VECTOR_H