diff --git a/src/gamematrix.cpp b/src/gamematrix.cpp index e69de29..ae65a96 100644 --- a/src/gamematrix.cpp +++ b/src/gamematrix.cpp @@ -0,0 +1,36 @@ +#include "gamematrix.h" +#include + +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; + }