/*! * 07_making_scene.cpp * * Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * * @Author: NADAL Jean-Baptiste * @Date: 14/02/2024 * */ /*---------------------------------------------------------------------------*/ #include #include "raytracing.h" using namespace Raytracer; /* ------------------------------------------------------------------------- */ SCENARIO("Creating a world", "[features/world.feature]") { GIVEN("w <- world()") { World w; THEN("w contains no objects") { REQUIRE(w.objects_count() == 0); } AND_THEN("w has no light source") { REQUIRE(w.has_light() == false); } } } /* ------------------------------------------------------------------------- */ SCENARIO("The default world", "[features/world.feature]") { GIVEN("light <- point_light(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) | // | material.diffuse | 0.7 | // | material.specular | 0.2 | { Sphere s1; s1.material().set_color(Color(0.8, 1.0, 0.6)); s1.material().set_diffuse(0.7); s1.material().set_specular(0.2); AND_GIVEN("s2 <- sphere") // with: // | transform | scaling(0.5, 0.5, 0.5) | { Sphere s2; s2.set_transform(Matrix::scaling(0.5, 0.5, 0.5)); WHEN("w <- default_world") { World w = World::default_world(); THEN("w.light = light") { REQUIRE(w.light() == light); } AND_THEN("w contains s1") { REQUIRE(w.contains(s1) == true); } AND_THEN("w contains s2") { REQUIRE(w.contains(s2) == true); } } } } } } /* ------------------------------------------------------------------------- */ SCENARIO("Intersect a world with a ray", "[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("xs <- intersect_world(w,r)") { Intersections xs = w.intersect_world(r); THEN("xs.count = 4") { REQUIRE(xs.count() == 4); } AND_THEN("xs[0].t = 4") { REQUIRE(xs[0].distance_t() == 4); } AND_THEN("xs[1].t = 4.5") { REQUIRE(xs[1].distance_t() == 4.5); } AND_THEN("xs[2].t = 5.5") { REQUIRE(xs[2].distance_t() == 5.5); } AND_THEN("xs[3].t = 6") { REQUIRE(xs[3].distance_t() == 6); } } } } }