[FEAT] Add Transformation Rotation
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user