[FEAT] Add Transformation Rotation

This commit is contained in:
NADAL Jean-Baptiste
2024-02-05 18:18:04 +01:00
parent dbac8a37c4
commit 4e6ce30a1d
3 changed files with 96 additions and 2 deletions

View File

@@ -102,3 +102,52 @@ TEST_CASE("[04][TRANSFORMATION] Reflection is scaling by a negative value", "[Ma
REQUIRE(transform * p == Tuple::Point(-2, 3, 4));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] Rotating a point around the x axis", "[Matrix]")
{
Tuple p = Tuple::Point(0, 1, 0);
Matrix half_quarter = Matrix::rotation_x(std::numbers::pi / 4);
Matrix full_quarter = Matrix::rotation_x(std::numbers::pi / 2);
REQUIRE(half_quarter * p == Tuple::Point(0, sqrt(2) / 2, sqrt(2) / 2));
REQUIRE(full_quarter * p == Tuple::Point(0, 0, 1));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] The inverse of an x-rotation rotates in the opposite direction", "[Matrix]")
{
Tuple p = Tuple::Point(0, 1, 0);
Matrix half_quarter = Matrix::rotation_x(std::numbers::pi / 4);
Matrix inv = half_quarter.inverse();
REQUIRE(inv * p == Tuple::Point(0, sqrt(2) / 2, -sqrt(2) / 2));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] Rotating a point around the y axis", "[Matrix]")
{
Tuple p = Tuple::Point(0, 0, 1);
Matrix half_quarter = Matrix::rotation_y(std::numbers::pi / 4);
Matrix full_quarter = Matrix::rotation_y(std::numbers::pi / 2);
REQUIRE(half_quarter * p == Tuple::Point(sqrt(2) / 2, 0, sqrt(2) / 2));
REQUIRE(full_quarter * p == Tuple::Point(1, 0, 0));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[04][TRANSFORMATION] Rotating a point around the z axis", "[Matrix]")
{
Tuple p = Tuple::Point(0, 1, 0);
Matrix half_quarter = Matrix::rotation_z(std::numbers::pi / 4);
Matrix full_quarter = Matrix::rotation_z(std::numbers::pi / 2);
Tuple z = half_quarter * p;
REQUIRE(half_quarter * p == Tuple::Point(-sqrt(2) / 2, sqrt(2) / 2, 0));
REQUIRE(full_quarter * p == Tuple::Point(-1, 0, 0));
}