From f3fe0b6bbe6c690540948b8f6d393f1bed437cef Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 30 Nov 2020 17:28:07 -0600 Subject: [PATCH] feat(matrix): add C44Matrix::RotateAroundZ --- tempest/matrix/C44Matrix.cpp | 4 ++++ tempest/matrix/C44Matrix.hpp | 1 + test/Matrix.cpp | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/tempest/matrix/C44Matrix.cpp b/tempest/matrix/C44Matrix.cpp index 823cfcc..d472ca2 100644 --- a/tempest/matrix/C44Matrix.cpp +++ b/tempest/matrix/C44Matrix.cpp @@ -60,6 +60,10 @@ C44Matrix C44Matrix::Inverse(float det) const { return this->Adjoint() * (1.0f / det); } +void C44Matrix::RotateAroundZ(float angle) { + *this = C44Matrix::RotationAroundZ(angle) * *this; +} + C44Matrix operator*(const C44Matrix& l, float a) { float a0 = l.a0 * a; float a1 = l.a1 * a; diff --git a/tempest/matrix/C44Matrix.hpp b/tempest/matrix/C44Matrix.hpp index 7a65633..0b59ea8 100644 --- a/tempest/matrix/C44Matrix.hpp +++ b/tempest/matrix/C44Matrix.hpp @@ -46,6 +46,7 @@ class C44Matrix { C44Matrix Adjoint() const; float Determinant() const; C44Matrix Inverse(float det) const; + void RotateAroundZ(float angle); }; C44Matrix operator*(const C44Matrix& l, float a); diff --git a/test/Matrix.cpp b/test/Matrix.cpp index 0fccf8a..93bde16 100644 --- a/test/Matrix.cpp +++ b/test/Matrix.cpp @@ -235,6 +235,29 @@ TEST_CASE("C44Matrix::Inverse", "[matrix]") { } } +TEST_CASE("C44Matrix::RotateAroundZ", "[matrix]") { + SECTION("rotates around z-axis by given angle") { + auto matrix = C44Matrix(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 20.0f, 30.0f, 40.0f, 1.0f); + matrix.RotateAroundZ(3.1415927f); + CHECK(matrix.a0 == Approx(-1.0f)); + CHECK(matrix.a1 == Approx(-1.0f)); + CHECK(matrix.a2 == Approx(-1.0f)); + CHECK(matrix.a3 == 0.0f); + CHECK(matrix.b0 == Approx(-1.0f)); + CHECK(matrix.b1 == Approx(-1.0f)); + CHECK(matrix.b2 == Approx(1.0f)); + CHECK(matrix.b3 == 0.0f); + CHECK(matrix.c0 == Approx(1.0f)); + CHECK(matrix.c1 == Approx(-1.0f)); + CHECK(matrix.c2 == Approx(1.0f)); + CHECK(matrix.c3 == 0.0f); + CHECK(matrix.d0 == 20.0f); + CHECK(matrix.d1 == 30.0f); + CHECK(matrix.d2 == 40.0f); + CHECK(matrix.d3 == 1.0f); + } +} + TEST_CASE("C44Matrix global operators", "[matrix]") { SECTION("C44Matrix * float") { auto matrix1 = C44Matrix(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f);