Skip to content
Snippets Groups Projects
Commit 45929aae authored by Yoel's avatar Yoel
Browse files

Deleted LightShape interface and split up SIngleGroup to one for Light and one for Shape

parent 5b5ee8bc
No related branches found
No related tags found
No related merge requests found
#pragma once
#include "Light.h"
#include "Shape.h"
namespace shapes {
class LightShape : public Light, public Shape {};
} // namespace shapes
\ No newline at end of file
#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
#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
#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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment