[WIP] Add Intersection

This commit is contained in:
NADAL Jean-Baptiste
2024-02-08 19:54:50 +01:00
parent f7a450e736
commit af1b3ed2be
8 changed files with 280 additions and 10 deletions

View File

@@ -37,7 +37,7 @@ using namespace Raytracer;
TEST_CASE("[05][Rays] Creating and querying a ray", "[Rays]")
{
Tuple origin = Tuple::Point(1, 2, 3);
Tuple origin = Tuple::Point(1, 2, 3);
Tuple direction = Tuple::Vector(4, 5, 6);
Ray r(origin, direction);
@@ -59,7 +59,7 @@ TEST_CASE("[05][Rays] Computing a point from a distance", "[Rays]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] a ray intersects a sphere at two points", "[Rays]")
TEST_CASE("[05][Rays] a ray intersects a sphere at two points", "[Sphere]")
{
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
Sphere s;
@@ -72,7 +72,7 @@ TEST_CASE("[05][Rays] a ray intersects a sphere at two points", "[Rays]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] a ray intersects a sphere at a tangent", "[Rays]")
TEST_CASE("[05][Rays] a ray intersects a sphere at a tangent", "[Sphere]")
{
Ray r(Tuple::Point(0, 1, -5), Tuple::Vector(0, 0, 1));
Sphere s;
@@ -85,7 +85,7 @@ TEST_CASE("[05][Rays] a ray intersects a sphere at a tangent", "[Rays]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] a ray misses a sphere", "[Rays]")
TEST_CASE("[05][Rays] a ray misses a sphere", "[Sphere]")
{
Ray r(Tuple::Point(0, 2, -5), Tuple::Vector(0, 0, 1));
Sphere s;
@@ -96,7 +96,7 @@ TEST_CASE("[05][Rays] a ray misses a sphere", "[Rays]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] a originates inside a sphere", "[Rays]")
TEST_CASE("[05][Rays] a originates inside a sphere", "[Sphere]")
{
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
Sphere s;
@@ -109,7 +109,7 @@ TEST_CASE("[05][Rays] a originates inside a sphere", "[Rays]")
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] a sphere is behind a ray", "[Rays]")
TEST_CASE("[05][Rays] a sphere is behind a ray", "[Sphere]")
{
Ray r(Tuple::Point(0, 0, 5), Tuple::Vector(0, 0, 1));
Sphere s;
@@ -119,3 +119,42 @@ TEST_CASE("[05][Rays] a sphere is behind a ray", "[Rays]")
REQUIRE(xs[0] == -6.0);
REQUIRE(xs[1] == -4.0);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] Test Sphere Object", "[Sphere]")
{
Sphere s1;
Sphere s2 = s1;
Sphere s3;
REQUIRE(s1 == s2);
REQUIRE(s1 != s3);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] An intersection encapsulates t and object", "[Intersections]")
{
Sphere s;
Intersection i(3.5, s);
REQUIRE(i.distance_t() == 3.5);
REQUIRE(i.object() == s);
}
#if 0
/* ------------------------------------------------------------------------- */
TEST_CASE("[05][Rays] Aggregating intersections", "[Intersections]")
{
Sphere s;
Intersection i1(1, s);
Intersection i2(2, s);
Intersections xs = Intersections(i1, i2);
REQUIRE(xs.count() == 2);
REQUIRE(xs[0].t() == 1);
REQUIRE(xs[1].t() == 2);
}
#endif