// casts a single ray through the scene geometry and finds the closest hit bool RayTracer::CastRay(const Ray &ray, Hit &h, bool use_sphere_patches) const { bool answer = false; h.clear(); // intersect each of the quads for (int i = 0; i < mesh->numQuadFaces(); i++) { Face *f = mesh->getFace(i); if (f->intersect(ray,h,args->intersect_backfacing)) answer = true; } // intersect each of the spheres (either the patches, or the original spheres) if (use_sphere_patches) { for (int i = mesh->numQuadFaces(); i < mesh->numFaces(); i++) { Face *f = mesh->getFace(i); if (f->intersect(ray,h,args->intersect_backfacing)) answer = true; } } else { const vector<Sphere*> &spheres = mesh->getSpheres(); for (unsigned int i = 0; i < spheres.size(); i++) { if (spheres[i]->intersect(ray,h)) answer = true; } } return answer; }