From 431015f009d2f46154edd8f5dfde826eb451878e Mon Sep 17 00:00:00 2001 From: Patedam Date: Sun, 22 Feb 2026 11:24:59 -0500 Subject: [PATCH] Added rotation functions for matrix --- Juliet/include/Core/Math/Matrix.h | 59 ++++++++++++++++++++++++++----- JulietApp/main.cpp | 5 ++- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Juliet/include/Core/Math/Matrix.h b/Juliet/include/Core/Math/Matrix.h index 569be81..2e599f5 100644 --- a/Juliet/include/Core/Math/Matrix.h +++ b/Juliet/include/Core/Math/Matrix.h @@ -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 diff --git a/JulietApp/main.cpp b/JulietApp/main.cpp index f221c93..12d34c0 100644 --- a/JulietApp/main.cpp +++ b/JulietApp/main.cpp @@ -120,7 +120,10 @@ void JulietApplication::Init() MeshID cube = AddCube(); float x = static_cast(col) * kSpacing - kOffset; float y = static_cast(row) * kSpacing - kOffset; - SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f)); + + float seed = static_cast(row * kGridSize + col); + Matrix rotation = MatrixRotation(seed * 0.73f, seed * 1.17f, seed * 0.53f); + SetMeshTransform(cube, MatrixTranslation(x, y, 0.0f) * rotation); } }