[FEAT] Not working yet. Move intersect to object and sphere instead of RAy.
This commit is contained in:
@@ -63,7 +63,7 @@ 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;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].distance_t() == 4.0);
|
||||
@@ -76,7 +76,7 @@ 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;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].distance_t() == 5.0);
|
||||
@@ -89,7 +89,7 @@ TEST_CASE("[05][Rays] a ray misses a sphere", "[Sphere]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 2, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 0);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ TEST_CASE("[05][Rays] a originates inside a sphere", "[Sphere]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].distance_t() == -1.0);
|
||||
@@ -113,7 +113,7 @@ 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;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].distance_t() == -6.0);
|
||||
@@ -163,7 +163,7 @@ TEST_CASE("[05][Rays] Intersect set the object on the intersection", "[Intersect
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
Intersections xs = r.intersect(s);
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].object() == s);
|
||||
@@ -207,9 +207,9 @@ TEST_CASE("[05][Rays] The hit, when all intersections have negative t", "[Inters
|
||||
Intersection i2(-1, s);
|
||||
Intersections xs = Intersections({i1, i2});
|
||||
|
||||
Intersection i = xs.hit();
|
||||
auto i = xs.hit();
|
||||
|
||||
REQUIRE(i.object().is_nothing());
|
||||
// REQUIRE(i.has_value());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -251,3 +251,47 @@ TEST_CASE("[05][Rays] Scaling a ray", "[Rays]")
|
||||
REQUIRE(r2.origin() == Tuple::Point(2, 6, 12));
|
||||
REQUIRE(r2.direction() == Tuple::Vector(0, 3, 0));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] A sphere's default transformation", "[Sphere]")
|
||||
{
|
||||
Sphere s;
|
||||
REQUIRE(s.transform() == Matrix::identity());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Changing a sphere's transformation", "[Sphere]")
|
||||
{
|
||||
Sphere s;
|
||||
Matrix t = Matrix::translation(2, 3, 4);
|
||||
s.set_transform(t);
|
||||
REQUIRE(s.transform() == t);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
#if 0
|
||||
TEST_CASE("[05][Rays] Intersecting a scaled sphere with a ray", "[Sphere]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
s.set_transform(Matrix::scaling(2, 2, 2));
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 2);
|
||||
REQUIRE(xs[0].distance_t() == 3);
|
||||
REQUIRE(xs[1].distance_t() == 7);
|
||||
}
|
||||
#endif
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[05][Rays] Intersecting a translated sphere with a ray", "[Sphere]")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
Sphere s;
|
||||
s.set_transform(Matrix::translation(5, 0, 0));
|
||||
Intersections xs = s.intersect(r);
|
||||
|
||||
REQUIRE(xs.count() == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user