Commit 8e4b20d8 authored by Lukas Werner's avatar Lukas Werner
Browse files

Updated Raytracing test for refactored intersection code

parent eb76d4d9
Pipeline #6816 failed with stage
in 23 minutes and 27 seconds
......@@ -34,21 +34,21 @@ void SphereIntersectsTest()
Ray ray1(Vec3(3,-5,3), Vec3(0,1,0));
WALBERLA_LOG_INFO("RAY -> SPHERE");
WALBERLA_CHECK(intersects(&sp1, &ray1, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(6)))
WALBERLA_CHECK(intersects(&sp1, ray1, t));
WALBERLA_CHECK_FLOAT_EQUAL(t, real_t(6));
// ray tangential
Ray ray2(Vec3(3,-5,3), Vec3(0,7.5,real_t(std::sqrt(real_t(15))/real_t(2))).getNormalized());
WALBERLA_CHECK(!intersects(&sp1, &ray2, &t));
WALBERLA_CHECK(!intersects(&sp1, ray2, t));
// sphere behind ray origin
Sphere sp2(123, 1, Vec3(3,-8,3), Vec3(0,0,0), Quat(), 2, iron, false, true, false);
WALBERLA_CHECK(!intersects(&sp2, &ray1, &t));
WALBERLA_CHECK(!intersects(&sp2, ray1, t));
// sphere around ray origin
Sphere sp3(123, 1, Vec3(3,-5,3), Vec3(0,0,0), Quat(), 2, iron, false, true, false);
WALBERLA_CHECK(intersects(&sp3, &ray1, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(2)));
WALBERLA_CHECK(intersects(&sp3, ray1, t));
WALBERLA_CHECK_FLOAT_EQUAL(t, real_t(2));
}
void PlaneIntersectsTest() {
......@@ -60,20 +60,20 @@ void PlaneIntersectsTest() {
real_t t;
WALBERLA_LOG_INFO("RAY -> PLANE");
WALBERLA_CHECK(intersects(&pl1, &ray1, &t), "ray through center did not hit");
WALBERLA_CHECK(realIsEqual(t, real_t(8)), "distance between ray and plane is incorrect");
WALBERLA_CHECK(intersects(&pl1, ray1, t), "ray through center did not hit");
WALBERLA_CHECK_FLOAT_EQUAL(t, real_t(8), "distance between ray and plane is incorrect");
Ray ray2(Vec3(-5,3,3), Vec3(1,0,-1).getNormalized());
WALBERLA_CHECK(intersects(&pl1, &ray2, &t), "ray towards random point on plane didn't hit");
WALBERLA_CHECK(realIsEqual(t, real_t(sqrt(real_t(128)))), "distance between ray and plane is incorrect");
WALBERLA_CHECK(intersects(&pl1, ray2, t), "ray towards random point on plane didn't hit");
WALBERLA_CHECK_FLOAT_EQUAL(t, real_t(sqrt(real_t(128))), "distance between ray and plane is incorrect");
// plane with center 3,3,3 and parallel to x-z plane
Plane pl2(1, 1, Vec3(3, 3, 3), Vec3(0, 1, 0), real_t(1.0), iron);
WALBERLA_CHECK(!intersects(&pl2, &ray1, &t), "ray parallel to plane shouldnt hit");
WALBERLA_CHECK(!intersects(&pl2, ray1, t), "ray parallel to plane shouldnt hit");
// plane with center -10,3,3 and parallel to y-z plane
Plane pl4(1, 1, Vec3(-10, 3, 3), Vec3(1, 0, 0), real_t(1.0), iron);
WALBERLA_CHECK(!intersects(&pl4, &ray1, &t), "ray hit plane behind origin");
WALBERLA_CHECK(!intersects(&pl4, ray1, t), "ray hit plane behind origin");
}
void BoxIntersectsTest() {
......@@ -84,34 +84,34 @@ void BoxIntersectsTest() {
Box box1(127, 5, Vec3(0, -15, 0), Vec3(0, 0, 0), Quat(), Vec3(10, 10, 10), iron, false, true, false);
Ray ray1(Vec3(3,-5,3), Vec3(0,1,0));
WALBERLA_CHECK(!intersects(&box1, &ray1, &t));
WALBERLA_CHECK(!intersects(&box1, ray1, t));
Box box2(128, 5, Vec3(0, -2, 0), Vec3(0, 0, 0), Quat(), Vec3(10, 10, 10), iron, false, true, false);
WALBERLA_CHECK(intersects(&box2, &ray1, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(8), 1e-7));
WALBERLA_CHECK(intersects(&box2, ray1, t));
WALBERLA_CHECK_FLOAT_EQUAL_EPSILON(t, real_t(8), 1e-7);
Box box3(128, 5, Vec3(0, 5, 0), Vec3(0, 0, 0), Quat(), Vec3(10, 10, 10), iron, false, true, false);
WALBERLA_CHECK(intersects(&box3, &ray1, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(5)));
WALBERLA_CHECK(intersects(&box3, ray1, t));
WALBERLA_CHECK_FLOAT_EQUAL(t, real_t(5));
// ray origin within box
Ray ray2(Vec3(-2,0,0), Vec3(1,0,1).getNormalized());
WALBERLA_CHECK(intersects(&box3, &ray2, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(7.0710), 1e-4));
WALBERLA_CHECK(intersects(&box3, ray2, t));
WALBERLA_CHECK_FLOAT_EQUAL_EPSILON(t, real_t(7.0710), 1e-4);
Ray ray3(Vec3(3,-5,3), Vec3(2, -1.5, 0.5).getNormalized());
Box box4(128, 5, Vec3(0, 8, 0), Vec3(0, 0, 0), Quat(), Vec3(10, 10, 10), iron, false, true, false);
WALBERLA_CHECK(!intersects(&box4, &ray3, &t));
WALBERLA_CHECK(!intersects(&box4, ray3, t));
Ray ray4(Vec3(3,-5,3), Vec3(-2, 3, 0.5).getNormalized());
WALBERLA_CHECK(intersects(&box4, &ray4, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(9.7068), 1e-4));
WALBERLA_CHECK(intersects(&box4, ray4, t));
WALBERLA_CHECK_FLOAT_EQUAL_EPSILON(t, real_t(9.7068), 1e-4);
Box box5(128, 5, Vec3(4, 0, 0), Vec3(0, 0, 0), Quat(), Vec3(4, 4, 4), iron, false, true, false);
box5.rotate(0,0,math::M_PI/4);
Ray ray5(Vec3(0,1.5,0), Vec3(1,0,0));
WALBERLA_CHECK(intersects(&box5, &ray5, &t));
WALBERLA_CHECK(realIsEqual(t, real_t(2.67157), 1e-4));
WALBERLA_CHECK(intersects(&box5, ray5, t));
WALBERLA_CHECK_FLOAT_EQUAL_EPSILON(t, real_t(2.67157), 1e-4);
}
int main( int argc, char** argv )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment