From 45929aae4c47a3e08b2009e2170d92c5a708f0ae Mon Sep 17 00:00:00 2001 From: Yoel <s73017@beuth-hochschule.de> Date: Fri, 16 Oct 2020 16:23:55 +0200 Subject: [PATCH] Deleted LightShape interface and split up SIngleGroup to one for Light and one for Shape --- RayTracer/shape/LightShape.h | 8 ------ RayTracer/shape/LightSingleGroup.cpp | 28 +++++++++++++++++++ RayTracer/shape/LightSingleGroup.h | 22 +++++++++++++++ .../{SingleGroup.cpp => ShapeSingleGroup.cpp} | 19 +++++-------- .../{SingleGroup.h => ShapeSingleGroup.h} | 14 ++++------ 5 files changed, 63 insertions(+), 28 deletions(-) delete mode 100644 RayTracer/shape/LightShape.h create mode 100644 RayTracer/shape/LightSingleGroup.cpp create mode 100644 RayTracer/shape/LightSingleGroup.h rename RayTracer/shape/{SingleGroup.cpp => ShapeSingleGroup.cpp} (64%) rename RayTracer/shape/{SingleGroup.h => ShapeSingleGroup.h} (53%) diff --git a/RayTracer/shape/LightShape.h b/RayTracer/shape/LightShape.h deleted file mode 100644 index 3b6b945..0000000 --- a/RayTracer/shape/LightShape.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Light.h" -#include "Shape.h" - -namespace shapes { -class LightShape : public Light, public Shape {}; -} // namespace shapes \ No newline at end of file diff --git a/RayTracer/shape/LightSingleGroup.cpp b/RayTracer/shape/LightSingleGroup.cpp new file mode 100644 index 0000000..ecff3f4 --- /dev/null +++ b/RayTracer/shape/LightSingleGroup.cpp @@ -0,0 +1,28 @@ +#include "LightSingleGroup.h" + +#include "../material/Material.h" +#include "../tools/Vec3.h" + +namespace shapes { +LightSingleGroup::LightSingleGroup(const util::Transformation& transform, + std::shared_ptr<Light> light) + : light(light), transform(transform) { +} +LightSingleGroup::LightSingleGroup(const util::Mat4& matrix, + std::shared_ptr<Light> light) + : light(light), transform(util::Transformation(matrix)) { +} + +util::SurfacePoint LightSingleGroup::sampleLight() const { + auto sample = light->sampleLight(); + return util::SurfacePoint(transform.toWorld.transformPoint(sample.point()), + transform.toWorldN.transformDir(sample.normal()), + sample.material); +} +util::Vec3 LightSingleGroup::calculateLightEmission(const util::SurfacePoint& p, + const util::Vec3& d) const { + return light->calculateLightEmission(p, + transform.fromWorld.transformDir(d)); +} + +} // namespace shapes \ No newline at end of file diff --git a/RayTracer/shape/LightSingleGroup.h b/RayTracer/shape/LightSingleGroup.h new file mode 100644 index 0000000..b824d42 --- /dev/null +++ b/RayTracer/shape/LightSingleGroup.h @@ -0,0 +1,22 @@ +#pragma once + +#include "../tools/Mat4.h" +#include "../tools/Transformation.h" +#include "Light.h" + +namespace shapes { +class LightSingleGroup : public Light { + public: + LightSingleGroup(const util::Transformation& trans, + std::shared_ptr<Light> shape); + LightSingleGroup(const util::Mat4& matrix, std::shared_ptr<Light> shape); + + util::SurfacePoint sampleLight() const override; + util::Vec3 calculateLightEmission(const util::SurfacePoint& p, + const util::Vec3& d) const override; + + private: + std::shared_ptr<Light> light; + util::Transformation transform; +}; +} // namespace shapes diff --git a/RayTracer/shape/SingleGroup.cpp b/RayTracer/shape/ShapeSingleGroup.cpp similarity index 64% rename from RayTracer/shape/SingleGroup.cpp rename to RayTracer/shape/ShapeSingleGroup.cpp index 799cc7e..2d45bb6 100644 --- a/RayTracer/shape/SingleGroup.cpp +++ b/RayTracer/shape/ShapeSingleGroup.cpp @@ -1,21 +1,20 @@ -#include "SingleGroup.h" +#include "ShapeSingleGroup.h" #include "../material/Material.h" #include "../tools/Vec3.h" namespace shapes { -SingleGroup::SingleGroup(const util::Transformation& transform, - std::shared_ptr<LightShape> shape) +ShapeSingleGroup::ShapeSingleGroup(const util::Transformation& transform, + std::shared_ptr<Shape> shape) : shape(shape), transform(transform) { boundingVolume = shape->bounds() * transform.toWorld; } -SingleGroup::SingleGroup(const util::Mat4& matrix, - std::shared_ptr<LightShape> shape) +ShapeSingleGroup::ShapeSingleGroup(const util::Mat4& matrix, + std::shared_ptr<Shape> shape) : shape(shape), transform(util::Transformation(matrix)) { boundingVolume = shape->bounds() * transform.toWorld; } - -std::optional<cam::Hit> SingleGroup::intersect(const cam::Ray& r) const { +std::optional<cam::Hit> ShapeSingleGroup::intersect(const cam::Ray& r) const { cam::Ray imagR(transform.fromWorld.transformPoint(r.x0), transform.fromWorld.transformDir(r.d), r.tmin, r.tmax, r.normalize); @@ -34,12 +33,8 @@ std::optional<cam::Hit> SingleGroup::intersect(const cam::Ray& r) const { } return result; } -util::AxisAlignedBoundingBox SingleGroup::bounds() const { +util::AxisAlignedBoundingBox ShapeSingleGroup::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/ShapeSingleGroup.h similarity index 53% rename from RayTracer/shape/SingleGroup.h rename to RayTracer/shape/ShapeSingleGroup.h index 288af49..5f9d1eb 100644 --- a/RayTracer/shape/SingleGroup.h +++ b/RayTracer/shape/ShapeSingleGroup.h @@ -2,23 +2,21 @@ #include "../tools/Mat4.h" #include "../tools/Transformation.h" -#include "LightShape.h" +#include "Shape.h" namespace shapes { -class SingleGroup : public Shape, public Light { +class ShapeSingleGroup : public Shape { public: - SingleGroup(const util::Transformation& trans, - std::shared_ptr<LightShape> shape); - SingleGroup(const util::Mat4& matrix, std::shared_ptr<LightShape> shape); + ShapeSingleGroup(const util::Transformation& trans, + std::shared_ptr<Shape> shape); + ShapeSingleGroup(const util::Mat4& matrix, std::shared_ptr<Shape> 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<LightShape> shape; + std::shared_ptr<Shape> shape; util::Transformation transform; }; } // namespace shapes -- GitLab