[FEAT] Chapter 11 is done

This commit is contained in:
2024-03-12 22:25:57 +01:00
parent 2dd9475c04
commit bd5f92d38a

View File

@@ -783,3 +783,63 @@ SCENARIO("The Schlick approximation with a small angle and n2 > n1", "[features/
} }
} }
} }
/* ------------------------------------------------------------------------- */
SCENARIO("shade_hit() with a reflective, transparent material", "[features/world.feature]")
{
GIVEN("w <- default_world()")
{
World w = World::default_world();
AND_GIVEN("r <- ray(point(0, 0, -3), vector(0, -sqrt(2) / 2, sqrt(2) / 2))")
{
Ray r(Tuple::Point(0, 0, -3), Tuple::Vector(0, -sqrt(2) / 2, sqrt(2) / 2));
AND_GIVEN("floor <- plane() with:")
{
// | transform | translation(0, -1, 0) |
// | material.reflective | 0.5 |
// | material.transparency | 0.5 |
// | material.refractive_index | 1.5 |
Plane floor;
floor.set_transform(Matrix::translation(0, -1, 0));
floor.material().set_reflective(0.5);
floor.material().set_transparency(0.5);
floor.material().set_refractive_index(1.5);
AND_GIVEN("floor is added to w")
{
w.add_object(&floor);
AND_GIVEN("ball <- sphere() with:")
{
// | material.color | (1, 0, 0) |
// | material.ambient | 0.5 |
// | transform | translation(0, -3.5, -0.5) |
Sphere ball;
ball.material().set_color(Color(1, 0, 0));
ball.material().set_ambient(0.5);
ball.set_transform(Matrix::translation(0, -3.5, -0.5));
AND_GIVEN("ball is added to w")
{
w.add_object(&ball);
AND_GIVEN("xs <- intersections(sqrt(2):floor)")
{
Intersections xs = Intersections({Intersection(sqrt(2), &floor)});
WHEN("comps <- prepare_computations(xs[0], r, xs)")
{
IntersectionData comps = xs[0].prepare_computations(r, &xs);
AND_WHEN("color <- shade_hit(w, comps, 5)")
{
Color color = w.shade_hit(comps, 5);
THEN("color = color(0.93391, 0.69643, 0.69243)")
{
REQUIRE(color == Color(0.93391, 0.69643, 0.69243));
}
}
}
}
}
}
}
}
}
}
}