Added rotation functions for matrix

This commit is contained in:
2026-02-22 11:24:59 -05:00
parent a7947bfa17
commit 431015f009
2 changed files with 54 additions and 10 deletions

View File

@@ -20,15 +20,6 @@ namespace Juliet
return result;
}
[[nodiscard]] inline Matrix MatrixTranslation(float x, float y, float z)
{
Matrix result = MatrixIdentity();
result.m[0][3] = x;
result.m[1][3] = y;
result.m[2][3] = z;
return result;
}
[[nodiscard]] inline Matrix operator*(const Matrix& lhs, const Matrix& rhs)
{
Matrix result = {};
@@ -45,6 +36,56 @@ namespace Juliet
return result;
}
[[nodiscard]] inline Matrix MatrixTranslation(float x, float y, float z)
{
Matrix result = MatrixIdentity();
result.m[0][3] = x;
result.m[1][3] = y;
result.m[2][3] = z;
return result;
}
[[nodiscard]] inline Matrix MatrixRotationX(float radians)
{
float c = cosf(radians);
float s = sinf(radians);
Matrix result = MatrixIdentity();
result.m[1][1] = c;
result.m[1][2] = -s;
result.m[2][1] = s;
result.m[2][2] = c;
return result;
}
[[nodiscard]] inline Matrix MatrixRotationY(float radians)
{
float c = cosf(radians);
float s = sinf(radians);
Matrix result = MatrixIdentity();
result.m[0][0] = c;
result.m[0][2] = s;
result.m[2][0] = -s;
result.m[2][2] = c;
return result;
}
[[nodiscard]] inline Matrix MatrixRotationZ(float radians)
{
float c = cosf(radians);
float s = sinf(radians);
Matrix result = MatrixIdentity();
result.m[0][0] = c;
result.m[0][1] = -s;
result.m[1][0] = s;
result.m[1][1] = c;
return result;
}
[[nodiscard]] inline Matrix MatrixRotation(float x, float y, float z)
{
return MatrixRotationX(x) * MatrixRotationY(y) * MatrixRotationZ(z);
}
inline Matrix LookAt(const Vector3& eye, const Vector3& target, const Vector3& up)
{
// Left-Handed convention

View File

@@ -120,7 +120,10 @@ void JulietApplication::Init()
MeshID cube = AddCube();
float x = static_cast<float>(col) * kSpacing - kOffset;
float y = static_cast<float>(row) * kSpacing - kOffset;
SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f));
float seed = static_cast<float>(row * kGridSize + col);
Matrix rotation = MatrixRotation(seed * 0.73f, seed * 1.17f, seed * 0.53f);
SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f) * rotation);
}
}