[WIP] world is wip

This commit is contained in:
2024-02-22 00:23:01 +01:00
parent 288f26358e
commit 6acf43540f
9 changed files with 431 additions and 6 deletions

View File

@@ -53,9 +53,9 @@ SCENARIO("Creating a world", "[features/world.feature]")
SCENARIO("The default world", "[features/world.feature]")
{
GIVEN("light <- point_light(point(-10, 10, 10), color(1, 1, 1))")
GIVEN("light <- point_light(point(-10, 10, -10), color(1, 1, 1))")
{
PointLight light = PointLight(Tuple::Point(-10, 10, 10), Color(1, 1, 1));
PointLight light = PointLight(Tuple::Point(-10, 10, -10), Color(1, 1, 1));
AND_GIVEN("s1 <- sphere")
// with:
// | material.color | (0.8, 1.0, 0.6) |
@@ -130,3 +130,181 @@ SCENARIO("Intersect a world with a ray", "[features/world.feature]")
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Precompute the state of an intersection", "[features/intersections.feature]")
{
GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
AND_GIVEN("shape <- sphere()")
{
Sphere shape;
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
THEN("comps.t = i.t")
{
REQUIRE(comps.distance_t() == i.distance_t());
}
AND_THEN("comps.object = i.object")
{
REQUIRE(comps.object() == i.object());
}
AND_THEN("comps.point = point(0, 0, -1)")
{
REQUIRE(comps.point() == Tuple::Point(0, 0, -1));
}
AND_THEN("comps.eyev = vector(0, 0, -1)")
{
REQUIRE(comps.eyev() == Tuple::Vector(0, 0, -1));
}
AND_THEN("comps.normalv = vector(0, 0, -1)")
{
REQUIRE(comps.normalv() == Tuple::Vector(0, 0, -1));
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The hit, when an intersection occurs on the outside", "[features/intersections.feature]")
{
GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
AND_GIVEN("shape <- sphere()")
{
Sphere shape;
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
THEN("comps.inside = false")
{
REQUIRE(comps.is_inside() == false);
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("The hit, when an intersection occurs on the inside", "[features/intersections.feature]")
{
GIVEN("r <- ray(point(0, 0, 0), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
AND_GIVEN("shape <- sphere()")
{
Sphere shape;
AND_GIVEN("i <- intersection(1, shape)")
{
Intersection i(1, shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
THEN("comps.point = point(0, 0, 1)")
{
REQUIRE(comps.point() == Tuple::Point(0, 0, 1));
}
AND_THEN("comps.eyev = vector(0, 0, -1)")
{
REQUIRE(comps.eyev() == Tuple::Vector(0, 0, -1));
}
AND_THEN("comps.inside = false")
{
REQUIRE(comps.is_inside() == true);
}
AND_THEN("comps.normalv = vector(0, 0, -1)")
{
REQUIRE(comps.normalv() == Tuple::Vector(0, 0, -1));
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Shading an intersection", "[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));
AND_GIVEN("shape <- first object of w")
{
Shape *shape = w.objects(0);
AND_GIVEN("i <- intersection(4, shape)")
{
Intersection i(4, *shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
AND_WHEN("c <- shade_hit(w, comps)")
{
Color c = w.shade_hit(comps);
THEN("c = color(0.38066, 0.47583, 0.2855)")
{
REQUIRE(c == Color(0.38066, 0.47583, 0.2855));
}
}
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("Shading an intersection from the inside", "[features/world.feature]")
{
GIVEN("w <- default_world()")
{
World w = World::default_world();
AND_GIVEN("w.light <- point_light(point(0, 0.25, 0))")
{
w.set_light(PointLight(Tuple::Point(0, 0.25, 0), Color(1, 1, 1)));
AND_GIVEN("r <- ray(point(0, 0, 0), vector(0, 0, 1))")
{
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
AND_GIVEN("shape <- second object of w")
{
Shape *shape = w.objects(1);
AND_GIVEN("i <- intersection(0.5, shape)")
{
Intersection i(0.5, *shape);
WHEN("comps <- prepare_computations(i,r)")
{
IntersectionData comps = i.prepare_computations(r);
AND_WHEN("c <- shade_hit(w, comps)")
{
Color c = w.shade_hit(comps);
THEN("c = color(0.90498, 0.90498, 0.90498)")
{
REQUIRE(c == Color(0.90498, 0.90498, 0.90498));
}
}
}
}
}
}
}
}
}