diff --git a/RayTracer/shape/Group.cpp b/RayTracer/shape/Group.cpp index b9f6ca6bc93617919de570e0d1a69e80402c5d41..2ce3282431ff895dcff77b07d534c408dd1347b3 100644 --- a/RayTracer/shape/Group.cpp +++ b/RayTracer/shape/Group.cpp @@ -20,12 +20,14 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { std::shared_ptr<cam::Hit> result; for (std::shared_ptr<Shape> s : shapeList) { - std::shared_ptr<cam::Hit> temp = s->intersect(imagR); - if (temp != nullptr) { - if (result == nullptr) { - result = temp; - } else if (result->t > temp->t) { - result = temp; + if (s->bounds().intersects(imagR)) { + std::shared_ptr<cam::Hit> temp = s->intersect(imagR); + if (temp != nullptr) { + if (result == nullptr) { + result = temp; + } else if (result->t > temp->t) { + result = temp; + } } } } @@ -38,7 +40,7 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { return result; } util::AxisAlignedBoundingBox Group::bounds() const { - return util::AxisAlignedBoundingBox(); + return boundingVolume; } void Group::add(const std::shared_ptr<Shape>& shape) { shapeList.push_back(shape);