[FEAT] add world.color_at

This commit is contained in:
2024-02-22 23:00:54 +01:00
parent 6acf43540f
commit ea33f1b985
4 changed files with 120 additions and 8 deletions

View File

@@ -308,3 +308,85 @@ SCENARIO("Shading an intersection from the inside", "[features/world.feature]")
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The color when a ray misses", "[features/world.feature]")
{
GIVEN("w <- default_world()")
{
World w = World::default_world();
AND_GIVEN("r <- ray(point(0, 0, -5), vector(0, 1, 0))")
{
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 1, 0));
WHEN("c <- color_at(w, r)")
{
Color c = w.color_at(r);
THEN("c = color(0, 0, 0)")
{
REQUIRE(c == Color(0, 0, 0));
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The color when a ray hits", "[features/world.feature]")
{
GIVEN("w <- default_world()")
{
World w = World::default_world();
AND_GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
WHEN("c <- color_at(w, r)")
{
Color c = w.color_at(r);
THEN("c = color(0.38066, 0.47583, 0.2855)")
{
REQUIRE(c == Color(0.38066, 0.47583, 0.2855));
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The color with an intersection behind the ray", "[features/world.feature]")
{
GIVEN("w <- default_world()")
{
World w = World::default_world();
AND_GIVEN("outer <- the first object in w")
{
Shape *outer = w.objects(0);
AND_GIVEN("outer.material.ambient <- 1")
{
outer->material().set_ambient(1);
AND_GIVEN("inner <- the second object in w")
{
Shape *inner = w.objects(1);
AND_GIVEN("inner.material.ambient <- 1")
{
inner->material().set_ambient(1);
AND_GIVEN("r <- ray(point(0, 0, 0.75), vector(0, 0, -1))")
{
Ray r(Tuple::Point(0, 0, 0.75), Tuple::Vector(0, 0, -1));
WHEN("c <- color_at(w, r)")
{
Color c = w.color_at(r);
THEN("c = inner.material.color")
{
REQUIRE(c == inner->material().color());
}
}
}
}
}
}
}
}
}