m4x4 identity

This commit is contained in:
h4570
2022-08-10 19:22:59 +02:00
parent 5cc5862810
commit 0df43e5a08
4 changed files with 24 additions and 15 deletions
+13 -11
View File
@@ -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);
}
+4 -4
View File
@@ -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;
}
+3
View File
@@ -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));
}
+4
View File
@@ -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);