[WIP] World in progress

This commit is contained in:
2024-02-20 23:10:49 +01:00
parent 6901cefbbc
commit 288f26358e
18 changed files with 452 additions and 38 deletions

View File

@@ -227,32 +227,6 @@ SCENARIO("A sphere is behind a ray", "[features/spheres.feature]")
/* ------------------------------------------------------------------------- */
SCENARIO("Test Sphere Object", "[features/spheres.feature]")
{
GIVEN("s1 <- sphere()")
{
Sphere s1;
AND_GIVEN("s2 <- s1")
{
Sphere s2 = s1;
AND_GIVEN("s3 <- sphere()")
{
Sphere s3;
THEN("s1 = s2")
{
REQUIRE(s1 == s2);
}
AND_THEN("s1 != s3")
{
REQUIRE(s1 != s3);
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("An intersection encapsulates t and object", "[features/intersections.feature]")
{
GIVEN("s <- sphere()")

132
tests/07_making_scene.cpp Normal file
View File

@@ -0,0 +1,132 @@
/*!
* 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 <catch.hpp>
#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);
}
}
}
}
}

View File

@@ -17,6 +17,7 @@ add_executable(raytracing_test
04_transformations.cpp
05_rays.cpp
06_light_shading.cpp
07_making_scene.cpp
)
include_directories("${CMAKE_SOURCE_DIR}/tests")