diff --git a/engine/inc/math/m4x4.hpp b/engine/inc/math/m4x4.hpp index 994e627..a009c14 100644 --- a/engine/inc/math/m4x4.hpp +++ b/engine/inc/math/m4x4.hpp @@ -20,10 +20,12 @@ class M4x4 { public: MATRIX data alignas(sizeof(float) * 16); + static M4x4 Identity; + /** - * @param identity true = identity matrix, false = random values + * Create matrix with random values */ - explicit M4x4(const bool& identity = true); + explicit M4x4(); M4x4(const M4x4& v) { copy(this, v); } explicit M4x4(const float* v) { copy(this, v); } inline M4x4(const float& m11, const float& m12, const float& m13, @@ -76,7 +78,7 @@ class M4x4 { const float& m44); void translate(const Vec4& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.translationX(v.x); temp.translationY(v.y); temp.translationZ(v.z); @@ -84,26 +86,26 @@ class M4x4 { } void translateX(const float& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.translationX(v); cross(this->data, temp.data, this->data); } void translateY(const float& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.translationY(v); cross(this->data, temp.data, this->data); } void translateZ(const float& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.translationZ(v); cross(this->data, temp.data, this->data); } /** Rotate M4x4. */ void rotate(const Vec4& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.rotationZ(v.z); cross(this->data, temp.data, this->data); @@ -119,21 +121,21 @@ class M4x4 { /** Rotate M4x4 by X. */ void rotateX(const float& radians) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.rotationX(radians); cross(this->data, temp.data, this->data); } /** Rotate M4x4 by Y. */ void rotateY(const float& radians) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.rotationY(radians); cross(this->data, temp.data, this->data); } /** Rotate M4x4 by Z. */ void rotateZ(const float& radians) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.rotationZ(radians); cross(this->data, temp.data, this->data); } @@ -151,7 +153,7 @@ class M4x4 { void scaleZ(const float& v) { scale(Vec4(1.0F, 1.0F, v, 1.0F)); } void scale(const Vec4& v) { - M4x4 temp = M4x4(true); + M4x4 temp = M4x4::Identity; temp.setScale(v); cross(this->data, temp.data, this->data); } diff --git a/engine/src/math/m4x4.cpp b/engine/src/math/m4x4.cpp index 9a1bc0c..4b8fb6a 100644 --- a/engine/src/math/m4x4.cpp +++ b/engine/src/math/m4x4.cpp @@ -17,10 +17,10 @@ namespace Tyra { VECTOR M4x4::upVec = {0.0F, 1.0F, 0.0F, 1.0F}; VECTOR M4x4::viewVec = {0.0F, 0.0F, 0.0F, 1.0F}; +M4x4 M4x4::Identity = M4x4(1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, + 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F); -M4x4::M4x4(const bool& t_identity) { - if (t_identity) identity(); -} +M4x4::M4x4() {} void M4x4::copy(M4x4* out, const float* in) { asm volatile( @@ -131,7 +131,7 @@ M4x4 M4x4::perspective(const float& fov, const float& width, } M4x4 M4x4::lookAt(const Vec4& position, const Vec4& target) { - M4x4 res(true); + M4x4 res = M4x4::Identity; lookAt(&res, position, target); return res; } diff --git a/engine/src/renderer/3d/mesh/mesh.cpp b/engine/src/renderer/3d/mesh/mesh.cpp index a6df2e6..d4ae8f8 100644 --- a/engine/src/renderer/3d/mesh/mesh.cpp +++ b/engine/src/renderer/3d/mesh/mesh.cpp @@ -54,6 +54,9 @@ Mesh::~Mesh() { void Mesh::init() { id = rand() % 1000000; materialsCount = 0; + translation = M4x4::Identity; + rotation = M4x4::Identity; + scale = M4x4::Identity; translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F)); } diff --git a/tutorials/01-hello/src/tutorial_01.cpp b/tutorials/01-hello/src/tutorial_01.cpp index bca23a9..da2be89 100644 --- a/tutorials/01-hello/src/tutorial_01.cpp +++ b/tutorials/01-hello/src/tutorial_01.cpp @@ -112,6 +112,10 @@ void Tutorial01 ::init() { u32 column = i % columns; u32 row = i / rows; + translations[i].identity(); + rotations[i].identity(); + scales[i].identity(); + translations[i].translateX(row * offset - center); translations[i].translateY(column * offset - center); translations[i].translateZ(-10.0F);