TEST(KDTree, shouldSearchInTree) { KDTree tree; vector<RTShape*> shapes; RTSphere sphere0(Vector(2.5, 2.5, 2.5), 2.4); RTSphere sphere1(Vector(2.5, 2.5, 7.5), 2.4); RTSphere sphere2(Vector(2.5, 7.5, 7.5), 2.4); RTSphere sphere3(Vector(2.5, 7.5, 2.5), 2.4); RTSphere sphere4(Vector(7.5, 2.5, 2.5), 2.4); RTSphere sphere5(Vector(7.5, 2.5, 7.5), 2.4); RTSphere sphere6(Vector(7.5, 7.5, 7.5), 2.4); RTSphere sphere7(Vector(7.5, 7.5, 2.5), 2.4); shapes.push_back(&sphere0); shapes.push_back(&sphere1); shapes.push_back(&sphere2); shapes.push_back(&sphere3); shapes.push_back(&sphere4); shapes.push_back(&sphere5); shapes.push_back(&sphere6); shapes.push_back(&sphere7); BoundingBox box(Vector(0,0,0), Vector(10,10,10)); tree.setBoundingBox(box); tree.setTerminationCondition(1); tree.build(shapes, 0); Ray ray(Vector(7.5, 7.5, -2 ), Vector(0,0,1)); IntersectionPtr intersection = tree.intersect(ray); CHECK( intersection != nullptr ); CHECK( intersection->getShape() == &sphere7 ); }
void BoundingSphere::Test() { BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f); BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f); BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f); BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f); IntersectData sphere1IntersectSphere2 = sphere1.IntersectBoundingSphere(sphere2); IntersectData sphere1IntersectSphere3 = sphere1.IntersectBoundingSphere(sphere3); IntersectData sphere1IntersectSphere4 = sphere1.IntersectBoundingSphere(sphere4); assert(sphere1IntersectSphere2.GetDoesIntersect() == false); assert(sphere1IntersectSphere2.GetDistance() == 1.0f); assert(sphere1IntersectSphere3.GetDoesIntersect() == false); assert(sphere1IntersectSphere3.GetDistance() == 0.0f); assert(sphere1IntersectSphere4.GetDoesIntersect() == true); assert(sphere1IntersectSphere4.GetDistance() == -1.0f); // std::cout << "Sphere1 intersect Sphere2: " << sphere1IntersectSphere2.GetDoesIntersect() // << ", Distance: " << sphere1IntersectSphere2.GetDistance() << std::endl; // std::cout << "Sphere1 intersect Sphere3: " << sphere1IntersectSphere3.GetDoesIntersect() // << ", Distance: " << sphere1IntersectSphere3.GetDistance() << std::endl; // std::cout << "Sphere1 intersect Sphere4: " << sphere1IntersectSphere4.GetDoesIntersect() // << ", Distance: " << sphere1IntersectSphere4.GetDistance() << std::endl; }
void Plane::Test() { BoundingSphere sphere1(Vector3f(0.0f, 0.0f, 0.0f), 1.0f); BoundingSphere sphere2(Vector3f(0.0f, 3.0f, 0.0f), 1.0f); BoundingSphere sphere3(Vector3f(0.0f, 0.0f, 2.0f), 1.0f); BoundingSphere sphere4(Vector3f(1.0f, 0.0f, 0.0f), 1.0f); Plane plane1(Vector3f(0.0f, 1.0f, 0.0f), 0.0f); IntersectData plane1IntersectSphere1 = plane1.IntersectSphere(sphere1); IntersectData plane1IntersectSphere2 = plane1.IntersectSphere(sphere2); IntersectData plane1IntersectSphere3 = plane1.IntersectSphere(sphere3); IntersectData plane1IntersectSphere4 = plane1.IntersectSphere(sphere4); assert(plane1IntersectSphere1.GetDoesIntersect() == true); assert(plane1IntersectSphere1.GetDistance() == 1.0f); assert(plane1IntersectSphere2.GetDoesIntersect() == false); assert(plane1IntersectSphere2.GetDistance() == 2.0f); assert(plane1IntersectSphere3.GetDoesIntersect() == true); assert(plane1IntersectSphere3.GetDistance() == 1.0f); assert(plane1IntersectSphere4.GetDoesIntersect() == true); assert(plane1IntersectSphere4.GetDistance() == 1.0f); // std::cout << "Plane1 intersect Sphere1: " << plane1IntersectSphere1.GetDoesIntersect() // << ", Distance: " << plane1IntersectSphere1.GetDistance() << std::endl; // // std::cout << "Plane1 intersect Sphere2: " << plane1IntersectSphere2.GetDoesIntersect() // << ", Distance: " << plane1IntersectSphere2.GetDistance() << std::endl; // // std::cout << "Plane1 intersect Sphere3: " << plane1IntersectSphere3.GetDoesIntersect() // << ", Distance: " << plane1IntersectSphere3.GetDistance() << std::endl; // // std::cout << "Plane1 intersect Sphere4: " << plane1IntersectSphere4.GetDoesIntersect() // << ", Distance: " << plane1IntersectSphere4.GetDistance() << std::endl; }