diff --git a/RayTracer/shape/SingleGroup.cpp b/RayTracer/shape/SingleGroup.cpp index b7f8600c0a77fc0b4858b79d117f518f3ec97f6a..799cc7e0734b5a7b325ceeaca0d5b2bf03b150a2 100644 --- a/RayTracer/shape/SingleGroup.cpp +++ b/RayTracer/shape/SingleGroup.cpp @@ -5,11 +5,12 @@ namespace shapes { SingleGroup::SingleGroup(const util::Transformation& transform, - std::shared_ptr<Shape> shape) + std::shared_ptr<LightShape> shape) : shape(shape), transform(transform) { boundingVolume = shape->bounds() * transform.toWorld; } -SingleGroup::SingleGroup(const util::Mat4& matrix, std::shared_ptr<Shape> shape) +SingleGroup::SingleGroup(const util::Mat4& matrix, + std::shared_ptr<LightShape> shape) : shape(shape), transform(util::Transformation(matrix)) { boundingVolume = shape->bounds() * transform.toWorld; } @@ -37,4 +38,8 @@ util::AxisAlignedBoundingBox SingleGroup::bounds() const { return boundingVolume; } +util::SurfacePoint SingleGroup::sampleLight() const { + return shape->sampleLight(); +} + } // namespace shapes \ No newline at end of file diff --git a/RayTracer/shape/SingleGroup.h b/RayTracer/shape/SingleGroup.h index 53a9e68966c0097043cf8075e18e615dda3e96fd..288af495e2abd66692dbc1dacdaf6379ac33bc16 100644 --- a/RayTracer/shape/SingleGroup.h +++ b/RayTracer/shape/SingleGroup.h @@ -2,21 +2,23 @@ #include "../tools/Mat4.h" #include "../tools/Transformation.h" -#include "Shape.h" +#include "LightShape.h" namespace shapes { -class SingleGroup : public Shape { +class SingleGroup : public Shape, public Light { public: SingleGroup(const util::Transformation& trans, - std::shared_ptr<Shape> shape); - SingleGroup(const util::Mat4& matrix, std::shared_ptr<Shape> shape); + std::shared_ptr<LightShape> shape); + SingleGroup(const util::Mat4& matrix, std::shared_ptr<LightShape> shape); std::optional<cam::Hit> intersect(const cam::Ray& r) const override; util::AxisAlignedBoundingBox bounds() const override; + util::SurfacePoint sampleLight() const override; + private: util::AxisAlignedBoundingBox boundingVolume; - std::shared_ptr<Shape> shape; + std::shared_ptr<LightShape> shape; util::Transformation transform; }; } // namespace shapes