1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:27:45 +00:00

LibGfx+Demos: Make Matrix4x4 a true alias for Matrix<4,T>

Matrix4x4 was defined as a derived class of Matrix<N,T> before.
Furthermore, some code was duplicated and it was overall just messy.
This commit turns Matrix4x4 into a simple alias for Matrix<4,T>.
This commit is contained in:
Stephan Unverwerth 2021-05-13 21:33:17 +02:00 committed by Andreas Kling
parent 0833db0874
commit c2d84efaae
5 changed files with 103 additions and 117 deletions

View file

@ -44,8 +44,8 @@ public:
constexpr Matrix operator*(const Matrix& other) const
{
Matrix product;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) {
auto& element = product.m_elements[i][j];
if constexpr (N == 4) {
@ -75,6 +75,31 @@ public:
return product;
}
constexpr static Matrix identity()
{
Matrix result;
for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) {
if (i == j)
result.m_elements[i][j] = 1;
else
result.m_elements[i][j] = 0;
}
}
return result;
}
constexpr Matrix transpose() const
{
Matrix result;
for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) {
result.m_elements[i][j] = m_elements[j][i];
}
}
return result;
}
private:
T m_elements[N][N];
};