Skip to content

Commit 957b3cb

Browse files
committed
Merge branch 'matrix-math' of https://github.com/crux-bphc/physics-engine into eqn-solver
latest changes from matrix math
2 parents b2aebee + 19e9998 commit 957b3cb

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

include/math/matrix.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstddef>
5+
6+
namespace math {
7+
8+
template <size_t _rows, size_t _cols, typename T>
9+
10+
class Matrix {
11+
static_assert(sizeof(T) == 4, "Matrix has not been implemented for non 4-byte types yet!");
12+
private:
13+
std::array<T, _rows * _cols> data;
14+
15+
public:
16+
Matrix() {
17+
data.fill(T{});
18+
}
19+
20+
inline T& operator()(size_t row, size_t col) {
21+
return data[row * _cols + col];
22+
}
23+
24+
inline const T& operator()(size_t row, size_t col) const {
25+
return data[row * _cols + col];
26+
}
27+
28+
inline T& operator[](size_t index) {
29+
return data[index];
30+
}
31+
32+
inline const T& operator[](size_t index) const {
33+
return data[index];
34+
}
35+
};
36+
37+
template <size_t R1, size_t C1R2, size_t C2, typename T>
38+
Matrix<R1, C2, T> matmul(const Matrix<R1, C1R2, T>& m1, const Matrix<C1R2, C2, T>& m2) {
39+
Matrix<R1, C2, T> res;
40+
for(size_t i = 0; i < R1; i++) {
41+
for(size_t j = 0; j < C2; j++) {
42+
for(size_t k = 0; k < C1R2; k++) {
43+
res(i, j) += m1(i, k) * m2(k, j);
44+
}
45+
}
46+
}
47+
48+
return res;
49+
}
50+
}

src/graphics/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <raylib.h>
22

3-
#include "math/vec.hpp"
3+
#include "math/vector.hpp"
4+
#include "math/matrix.hpp"
45

56

67
#define WINDOW_TITLE "Window title"

0 commit comments

Comments
 (0)