Gamematrix erstellt

This commit is contained in:
Kai Graap 2025-11-17 14:10:13 +01:00
parent a561b26425
commit c3dc997071

View File

@ -0,0 +1,36 @@
#include "gamematrix.h"
#include <cmath>
namespace Matrix3D {
Mat4 identity() {
Mat4 m{};
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
m[i][j] = (i == j) ? 1.0 : 0.0;
}
}
return m;
}
Mat4 matmul(const Mat4& A, const Mat4& B) {
Mat4 R{};
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
double sum = 0.0;
for(int k = 0; k < 4; k++) {
sum += A[i][k] * B[k][j];
}
R[i][j] = sum;
}
}
return R;
}
Mat4 translate(const Vec3& pos) {
Mat4 t = identity();
t[0][3] = pos.x;
t[1][3] = pos.y;
t[2][3] = pos.z;
return t;
}