From 23d01fd2d20ccb8cc63b28cbf66c986c05c8e6a7 Mon Sep 17 00:00:00 2001
From: Yoel <s73017@beuth-hochschule.de>
Date: Thu, 8 Oct 2020 16:50:26 +0200
Subject: [PATCH] SingleGroup now gets a LightShape instead of jsut a shape. It
 effectively splits the LightShape back in Light and Shape. Also provides a
 transform

---
 RayTracer/shape/SingleGroup.cpp |  9 +++++++--
 RayTracer/shape/SingleGroup.h   | 12 +++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/RayTracer/shape/SingleGroup.cpp b/RayTracer/shape/SingleGroup.cpp
index b7f8600..799cc7e 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 53a9e68..288af49 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
-- 
GitLab