[FEAT] RAY: Add transform method

This commit is contained in:
NADAL Jean-Baptiste
2024-02-12 18:24:38 +01:00
parent 8c8e378ebd
commit 768838670f
5 changed files with 43 additions and 9 deletions

View File

@@ -227,3 +227,27 @@ TEST_CASE("[05][Rays] The hit is always the lowest nonnegative intersection", "[
REQUIRE(i == i4);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] Translating a ray", "[Rays]")
{
Ray r(Tuple::Point(1, 2, 3), Tuple::Vector(0, 1, 0));
Matrix m = Matrix::translation(3, 4, 5);
Ray r2 = r.transform(m);
REQUIRE(r2.origin() == Tuple::Point(4, 6, 8));
REQUIRE(r2.direction() == Tuple::Vector(0, 1, 0));
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] Scaling a ray", "[Rays]")
{
Ray r(Tuple::Point(1, 2, 3), Tuple::Vector(0, 1, 0));
Matrix m = Matrix::scaling(2, 3, 4);
Ray r2 = r.transform(m);
REQUIRE(r2.origin() == Tuple::Point(2, 6, 12));
REQUIRE(r2.direction() == Tuple::Vector(0, 3, 0));
}