aboutsummaryrefslogtreecommitdiff
path: root/src/math/mat4.cpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2023-12-05 10:42:35 +0100
committervimene <vincent.menegaux@gmail.com>2023-12-05 10:42:35 +0100
commit9b70ca7b3a1b7bfd3bf434d8b84bde42f5572ca0 (patch)
tree7078a70f7fc5b590c61386f55f4fbcc67e36b0f3 /src/math/mat4.cpp
parent48ec7df0fd27fab05c9918e83a3a7da1cc32d7a0 (diff)
downloadengine-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/mat4.cpp')
-rw-r--r--src/math/mat4.cpp24
1 files changed, 17 insertions, 7 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] },