diff options
author | vimene <vincent.menegaux@gmail.com> | 2023-12-05 10:42:35 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2023-12-05 10:42:35 +0100 |
commit | 9b70ca7b3a1b7bfd3bf434d8b84bde42f5572ca0 (patch) | |
tree | 7078a70f7fc5b590c61386f55f4fbcc67e36b0f3 /src/math | |
parent | 48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0 (diff) | |
download | engine-9b70ca7b3a1b7bfd3bf434d8b84bde42f5572ca0.tar.gz |
added renderer, improved various things
- Added renderer to unify frame buffers
- Added FrameBuffer class as a parent for frame buffers' classes
- Improved formatting in Makefile.am
- Added const modifier in Matrix4's methods
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/mat4.cpp | 24 | ||||
-rw-r--r-- | src/math/mat4.h | 15 |
2 files changed, 25 insertions, 14 deletions
diff --git a/src/math/mat4.cpp b/src/math/mat4.cpp index f1f28b7..b9dff15 100644 --- a/src/math/mat4.cpp +++ b/src/math/mat4.cpp @@ -22,6 +22,7 @@ Matrix4 Matrix4::translate(Vector3 v) { 0.f, 0.f, 0.f, 1.f, }; } + Matrix4 Matrix4::scale(float fac) { return { fac, 0.f, 0.f, 0.f, @@ -31,6 +32,15 @@ Matrix4 Matrix4::scale(float fac) { }; } +Matrix4 Matrix4::scale(Vector3 facs) { + return { + facs.x, 0.f, 0.f, 0.f, + 0.f, facs.y, 0.f, 0.f, + 0.f, 0.f, facs.z, 0.f, + 0.f, 0.f, 0.f, 1.f, + }; +} + Matrix4 Matrix4::rot_x(float a) { float c = std::cos(a); float s = std::sin(a); @@ -73,11 +83,11 @@ Matrix4 Matrix4::projection(float aspect_ratio, float min_z, float max_z) { }}; } -Matrix4 Matrix4::operator+() { +Matrix4 Matrix4::operator+() const { return *this; } -Matrix4 Matrix4::operator-() { +Matrix4 Matrix4::operator-() const { return { -values[ 0], -values[ 1], -values[ 2], -values[ 3], -values[ 4], -values[ 5], -values[ 6], -values[ 7], @@ -86,7 +96,7 @@ Matrix4 Matrix4::operator-() { }; } -Matrix4 Matrix4::operator+(Matrix4 m) { +Matrix4 Matrix4::operator+(Matrix4 m) const { 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,11 +105,11 @@ Matrix4 Matrix4::operator+(Matrix4 m) { }; } -Matrix4 Matrix4::operator-(Matrix4 m) { +Matrix4 Matrix4::operator-(Matrix4 m) const { return *this + (-m); } -Matrix4 Matrix4::operator*(Matrix4 m) { +Matrix4 Matrix4::operator*(Matrix4 m) const { Matrix4 ret; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { @@ -111,7 +121,7 @@ Matrix4 Matrix4::operator*(Matrix4 m) { return ret; } -Vector4 Matrix4::operator*(Vector4 v) { +Vector4 Matrix4::operator*(Vector4 v) const { 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 +130,7 @@ Vector4 Matrix4::operator*(Vector4 v) { }; } -std::array<Vector4, 4> Matrix4::to_vecs() { +std::array<Vector4, 4> Matrix4::to_vecs() const { return {{ { values[ 0], values[ 4], values[ 8], values[12] }, { values[ 1], values[ 5], values[ 9], values[13] }, diff --git a/src/math/mat4.h b/src/math/mat4.h index 66d6cd2..35b1ad2 100644 --- a/src/math/mat4.h +++ b/src/math/mat4.h @@ -11,6 +11,7 @@ class Matrix4 { static Matrix4 idty(); static Matrix4 translate(Vector3 v); static Matrix4 scale(float fac); + static Matrix4 scale(Vector3 facs); static Matrix4 rot_x(float a); static Matrix4 rot_y(float a); static Matrix4 rot_z(float a); @@ -18,13 +19,13 @@ class Matrix4 { std::array<float, 16> values; - 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(); + Matrix4 operator+() const; + Matrix4 operator-() const; + Matrix4 operator+(Matrix4 m) const; + Matrix4 operator-(Matrix4 m) const; + Matrix4 operator*(Matrix4 m) const; + Vector4 operator*(Vector4 v) const; + std::array<Vector4, 4> to_vecs() const; }; Matrix4 operator*(float fac, Matrix4 m); |