Implement Matrix4x4::RotateX() RotateY() RotateZ()
Some checks failed
Run tests / Explore-Gitea-Actions (push) Failing after 34s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 34s

This commit is contained in:
2024-05-27 11:11:07 -04:00
parent a78b8208e2
commit ee86082c84
2 changed files with 46 additions and 2 deletions

View File

@@ -221,8 +221,7 @@ namespace J3ML::LinearAlgebra {
/** Calling RotateX, RotateY, or RotateZ is slightly faster than calling the more generic RotateAxisAngle function.
@param radians The angle to rotate by, in radians. For example, Pi/4.f equals 45 degrees.
@param pointOnAxis If specified, the rotation is performed about an axis that passes through this point,
and not through the origin. The returned matrix will not be a pure rotation matrix, but will also contain translation.
*/
and not through the origin. The returned matrix will not be a pure rotation matrix, but will also contain translation. */
static Matrix4x4 RotateX(float radians, const Vector3 &pointOnAxis);
/// [similarOverload: RotateX] [hideIndex]
static Matrix4x4 RotateX(float radians);
@@ -379,6 +378,8 @@ namespace J3ML::LinearAlgebra {
void SetCol(int col, const Vector4& colVector);
void SetCol(int col, float m_c0, float m_c1, float m_c2, float m_c3);
void SetCol3(int col, float x, float y, float z);
/// Returns the given row.
/** @param The zero-based index [0, 3] of the row to get */
Vector4 GetRow(int row) const;

View File

@@ -889,6 +889,49 @@ namespace J3ML::LinearAlgebra {
return Matrix4x4::Translate(translate) * Matrix4x4(rotate) * Matrix4x4::Scale(scale);
}
void Matrix4x4::SetCol3(int col, float x, float y, float z) {
// TODO: implement assertations
At(0, col) = x;
At(1, col) = y;
At(2, col) = z;
}
Matrix4x4 Matrix4x4::RotateZ(float radians) {
Matrix4x4 r;
r.SetRotatePartZ(radians);
r.SetRow(3, 0, 0, 0, 1);
r.SetCol3(3, 0, 0, 0);
return r;
}
Matrix4x4 Matrix4x4::RotateZ(float radians, const Vector3 &pointOnAxis) {
return Matrix4x4::Translate(pointOnAxis) * RotateY(radians) * Matrix4x4::Translate(-pointOnAxis);
}
Matrix4x4 Matrix4x4::RotateY(float radians) {
Matrix4x4 r;
r.SetRotatePartY(radians);
r.SetRow(3, 0, 0, 0, 1);
r.SetCol3(3, 0, 0, 0);
return r;
}
Matrix4x4 Matrix4x4::RotateY(float radians, const Vector3 &pointOnAxis) {
return Matrix4x4::Translate(pointOnAxis) * RotateY(radians) * Matrix4x4::Translate(-pointOnAxis);
}
Matrix4x4 Matrix4x4::RotateX(float radians) {
Matrix4x4 r;
r.SetRotatePartX(radians);
r.SetRow(3, 0, 0, 0, 1);
r.SetCol3(3, 0, 0, 0);
return r;
}
Matrix4x4 Matrix4x4::RotateX(float radians, const Vector3 &pointOnAxis) {
return Matrix4x4::Translate(pointOnAxis) * RotateX(radians) * Matrix4x4::Translate(-pointOnAxis);
}
Matrix4x4 Matrix4x4::Scale(const Vector3 &scale) {
Matrix4x4 m;
m.SetRow(0, scale.x, 0, 0, 0);