[WIP] sart intergration of cylinders

This commit is contained in:
NADAL Jean-Baptiste
2024-03-18 16:35:12 +01:00
parent b2ba503d24
commit e17ac42b4a
7 changed files with 228 additions and 5 deletions

View File

@@ -32,3 +32,93 @@
using namespace Raytracer;
/* ------------------------------------------------------------------------- */
class CylinderTestIntersect
{
public:
Tuple origin;
Tuple direction;
double t0 = -1;
double t1 = -1;
};
/* ------------------------------------------------------------------------- */
SCENARIO("A Ray misses a cylinder", "[features/cylinders.feature]")
{
// | origin | direction |
// | point(1, 0, 0) | vector(0, 1, 0) |
// | point(0, 0, 0) | vector(0, 1, 0) |
// | point(0, 0, -5) | vector(1, 1, 1) |
CylinderTestIntersect the_test[] = {
{Tuple::Point(1, 0, 0), Tuple::Vector(0, 1, 0)},
{Tuple::Point(0, 0, 0), Tuple::Vector(0, 1, 0)},
{Tuple::Point(0, 0, -5), Tuple::Vector(1, 1, 1)}
};
GIVEN("cyl <- cylinder()")
{
Cylinder cyl;
AND_GIVEN("r <- ray(<origin>, <direction>)")
{
WHEN("xs <- local_intersect(cyl,r)")
{
for (int i = 0; i < 3; i++)
{
Ray r(the_test[i].origin, the_test[i].direction);
Intersections xs = cyl.local_intersect(r);
THEN("xs.count = 0")
{
REQUIRE(xs.count() == 0);
}
}
}
}
}
}
/* ------------------------------------------------------------------------- */
SCENARIO("A Ray strikes a cylinder", "[features/cylinders.feature]")
{
// | origin | direction | t0 | t1 |
// | point(1, 0, -5) | vector(0, 0, 1) | 5 | 5 |
// | point(0, 0, -5) | vector(0, 0, 1) | 4 | 6 |
// | point(0.5, 0, -5) | vector(0.1, 1, 1) | 6.80798 | 7.08872 |
CylinderTestIntersect the_test[] = {
{ Tuple::Point(1, 0, -5), Tuple::Vector(0, 0, 1), 5, 5},
{ Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 4, 6},
{Tuple::Point(0.5, 0, -5), Tuple::Vector(0.1, 1, 1), 6.80798, 7.08872}
};
GIVEN("cyl <- cylinder()")
{
Cylinder cyl;
AND_GIVEN("direction <- normalize(<direction>)")
{
AND_GIVEN("r <- ray(<origin>, direction)")
{
WHEN("xs <- local_intersect(cyl,r)")
{
for (int i = 0; i < 3; i++)
{
Tuple direction = the_test[i].direction.normalize();
Ray r(the_test[i].origin, direction);
Intersections xs = cyl.local_intersect(r);
THEN("xs.count = 2")
{
REQUIRE(xs.count() == 2);
}
AND_THEN("xs[0].t = <t1>")
{
REQUIRE(xs[0].distance_t() == the_test[i].t0);
}
AND_THEN("xs[1].t = <t2>")
{
REQUIRE(xs[1].distance_t() == the_test[i].t1);
}
}
}
}
}
}
}