Added rotation functions for matrix
This commit is contained in:
@@ -20,15 +20,6 @@ namespace Juliet
|
|||||||
return result;
|
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)
|
[[nodiscard]] inline Matrix operator*(const Matrix& lhs, const Matrix& rhs)
|
||||||
{
|
{
|
||||||
Matrix result = {};
|
Matrix result = {};
|
||||||
@@ -45,6 +36,56 @@ namespace Juliet
|
|||||||
return result;
|
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)
|
inline Matrix LookAt(const Vector3& eye, const Vector3& target, const Vector3& up)
|
||||||
{
|
{
|
||||||
// Left-Handed convention
|
// Left-Handed convention
|
||||||
|
|||||||
@@ -120,7 +120,10 @@ void JulietApplication::Init()
|
|||||||
MeshID cube = AddCube();
|
MeshID cube = AddCube();
|
||||||
float x = static_cast<float>(col) * kSpacing - kOffset;
|
float x = static_cast<float>(col) * kSpacing - kOffset;
|
||||||
float y = static_cast<float>(row) * 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user