Skip to content
Snippets Groups Projects
Commit 7d951204 authored by Yoel's avatar Yoel
Browse files

ShapeGroups are now a seperate class: SingleGroup, which can only contain a single Shape

parent b895a6f0
No related branches found
No related tags found
No related merge requests found
#include "SingleGroup.h"
#include "../material/Material.h"
#include "../tools/Vec3.h"
namespace shapes {
SingleGroup::SingleGroup(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<Shape> shape)
: shape(shape), transform(util::Transformation(matrix)) {
boundingVolume = shape->bounds() * transform.toWorld;
}
std::optional<cam::Hit> SingleGroup::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);
std::optional<cam::Hit> result = std::nullopt;
if (shape->bounds().intersects(imagR)) {
result = shape->intersect(imagR);
}
if (result) {
result = std::optional<cam::Hit>(
{transform.toWorld.transformPoint(result->point()),
transform.toWorldN.transformDir(result->normal()),
result->scalar(), result->material});
}
return result;
}
util::AxisAlignedBoundingBox SingleGroup::bounds() const {
return boundingVolume;
}
} // namespace shapes
\ No newline at end of file
#pragma once
#include "../tools/Mat4.h"
#include "../tools/Transformation.h"
#include "Shape.h"
namespace shapes {
class SingleGroup : public Shape {
public:
SingleGroup(const util::Transformation& trans,
std::shared_ptr<Shape> shape);
SingleGroup(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;
private:
util::AxisAlignedBoundingBox boundingVolume;
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