diff --git a/RayTracer/shape/LightShape.h b/RayTracer/shape/LightShape.h deleted file mode 100644 index 3b6b945d341d52c0d56e55506607151c6e61fb4e..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..ecff3f46362d1e85d715add83ec1cabf1d83c418 --- /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 0000000000000000000000000000000000000000..b824d426ac39f010b68e4cde4caefcdc273eac03 --- /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 799cc7e0734b5a7b325ceeaca0d5b2bf03b150a2..2d45bb6bcfea98393f89fe4c7dfa8866dd9317fd 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 288af495e2abd66692dbc1dacdaf6379ac33bc16..5f9d1ebbf7eb3ffa919b8e16b298f4dac35f0797 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