diff --git a/RayTracer/shape/Group.cpp b/RayTracer/shape/Group.cpp index 2ce3282431ff895dcff77b07d534c408dd1347b3..9d62d6e0f26f79a00d6d627a0c90425729e30f6b 100644 --- a/RayTracer/shape/Group.cpp +++ b/RayTracer/shape/Group.cpp @@ -31,6 +31,7 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { } } } + if (result != nullptr) { result = std::make_shared<cam::Hit>( cam::Hit(transform.toWorld.transformPoint(result->hit), @@ -42,10 +43,15 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { util::AxisAlignedBoundingBox Group::bounds() const { return boundingVolume; } +void Group::add(const Group& group) { + shapeList.push_back(std::make_shared<Group>(group)); + rebuildBoundingVolume(); +} void Group::add(const std::shared_ptr<Shape>& shape) { shapeList.push_back(shape); rebuildBoundingVolume(); } + void Group::rebuildBoundingVolume() { util::AxisAlignedBoundingBox bb = shapeList[0]->bounds(); for (auto shape_bb : shapeList) { @@ -53,5 +59,10 @@ void Group::rebuildBoundingVolume() { } boundingVolume = bb; } +Group shapeGroup(util::Mat4& matrix, std::shared_ptr<Shape> shape) { + Group g(matrix); + g.add(shape); + return g; +} } // namespace shapes \ No newline at end of file diff --git a/RayTracer/shape/Group.h b/RayTracer/shape/Group.h index 39eb7f1aefedc7eb758f1dd2a28e1de5b8f7f26f..e637bc3b228d039226b1606f70cadce79ccf9499 100644 --- a/RayTracer/shape/Group.h +++ b/RayTracer/shape/Group.h @@ -14,7 +14,10 @@ class Group : public Shape { std::shared_ptr<cam::Hit> intersect(const cam::Ray& r) const override; util::AxisAlignedBoundingBox bounds() const override; - // protected:TODO + void add(const Group& group); + friend Group shapeGroup(util::Mat4& matrix, std::shared_ptr<Shape> shape); + + protected: void add(const std::shared_ptr<shapes::Shape>& shape); private: