From 4251291170fdf3ca26f24f40cc255f0811902528 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Mon, 5 Feb 2024 22:20:51 +0100 Subject: [PATCH] [FEAT] Add some chaines test --- tests/04_transformations.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/04_transformations.cpp b/tests/04_transformations.cpp index cdadc4d..cdb6c2b 100644 --- a/tests/04_transformations.cpp +++ b/tests/04_transformations.cpp @@ -201,3 +201,36 @@ TEST_CASE("[04][Trans] A shearing transformation moves z in proportion to y", "[ REQUIRE(transform * p == Tuple::Point(2, 3, 7)); } + +/* ------------------------------------------------------------------------- */ + +TEST_CASE("[04][Trans] Individual transformations are applied in sequence", "[Matrix]") +{ + Tuple p = Tuple::Point(1, 0, 1); + Matrix a = Matrix::rotation_x(std::numbers::pi / 2); + Matrix b = Matrix::scaling(5, 5, 5); + Matrix c = Matrix::translation(10, 5, 7); + + // Appply rotation first. + Tuple p2 = a * p; + REQUIRE(p2 == Tuple::Point(1, -1, 0)); + // Then Apply scaling + Tuple p3 = b * p2; + REQUIRE(p3 == Tuple::Point(5, -5, 0)); + // Then Apply translation + Tuple p4 = c * p3; + REQUIRE(p4 == Tuple::Point(15, 0, 7)); +} + +/* ------------------------------------------------------------------------- */ + +TEST_CASE("[04][Trans] Chained transformation must be applied in rever order", "[Matrix]") +{ + Tuple p = Tuple::Point(1, 0, 1); + Matrix a = Matrix::rotation_x(std::numbers::pi / 2); + Matrix b = Matrix::scaling(5, 5, 5); + Matrix c = Matrix::translation(10, 5, 7); + Matrix t = c * b * a; + + REQUIRE(t * p == Tuple::Point(15, 0, 7)); +}