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

group now has bool for auto rebuild. added setBounds method

parent eab7b922
No related branches found
No related tags found
No related merge requests found
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include "../tools/Vec3.h" #include "../tools/Vec3.h"
namespace shapes { namespace shapes {
Group::Group(const util::Transformation& transform) Group::Group(const util::Transformation& transform, bool rebuildBB)
: shapeList(std::vector<std::shared_ptr<Shape>>()), transform(transform) { : shapeList(std::vector<std::shared_ptr<Shape>>()),
transform(transform),
rebuildBB(rebuildBB) {
} }
Group::Group(const util::Mat4& matrix) Group::Group(const util::Mat4& matrix, bool rebuildBB)
: shapeList(std::vector<std::shared_ptr<Shape>>()), : shapeList(std::vector<std::shared_ptr<Shape>>()),
transform(util::Transformation(matrix)) { transform(util::Transformation(matrix)),
rebuildBB(rebuildBB) {
} }
std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const { std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const {
...@@ -23,10 +26,12 @@ std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const { ...@@ -23,10 +26,12 @@ std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const {
if (s->bounds().intersects(imagR)) { if (s->bounds().intersects(imagR)) {
std::optional<cam::Hit> temp = s->intersect(imagR); std::optional<cam::Hit> temp = s->intersect(imagR);
if (temp) { if (temp) {
if (!result) { if (imagR.in_range(temp->scalar())) {
result = temp; if (!result) {
} else if (result->scalar() > temp->scalar()) { result = temp;
result = temp; } else if (result->scalar() > temp->scalar()) {
result = temp;
}
} }
} }
} }
...@@ -43,6 +48,9 @@ std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const { ...@@ -43,6 +48,9 @@ std::optional<cam::Hit> Group::intersect(const cam::Ray& r) const {
util::AxisAlignedBoundingBox Group::bounds() const { util::AxisAlignedBoundingBox Group::bounds() const {
return boundingVolume; return boundingVolume;
} }
void Group::setBounds(const util::AxisAlignedBoundingBox& bb) {
boundingVolume = bb;
}
void Group::add(const Group& group) { void Group::add(const Group& group) {
add(std::make_shared<Group>(group)); add(std::make_shared<Group>(group));
} }
...@@ -51,7 +59,7 @@ void Group::add(const ShapeSingleGroup& group) { ...@@ -51,7 +59,7 @@ void Group::add(const ShapeSingleGroup& group) {
} }
void Group::add(const std::shared_ptr<Shape>& shape) { void Group::add(const std::shared_ptr<Shape>& shape) {
shapeList.push_back(shape); shapeList.push_back(shape);
rebuildBoundingVolume(); if (rebuildBB) rebuildBoundingVolume();
} }
void Group::rebuildBoundingVolume() { void Group::rebuildBoundingVolume() {
......
...@@ -10,22 +10,25 @@ ...@@ -10,22 +10,25 @@
namespace shapes { namespace shapes {
class Group : public Shape { class Group : public Shape {
public: public:
Group(const util::Transformation& trans); Group(const util::Transformation& trans, bool rebuildBB = true);
Group(const util::Mat4& matrix); Group(const util::Mat4& matrix, bool rebuildBB = true);
std::optional<cam::Hit> intersect(const cam::Ray& r) const override; std::optional<cam::Hit> intersect(const cam::Ray& r) const override;
util::AxisAlignedBoundingBox bounds() const override; util::AxisAlignedBoundingBox bounds() const override;
void setBounds(const util::AxisAlignedBoundingBox& bb);
void add(const Group& group); void add(const Group& group);
void add(const ShapeSingleGroup& group); void add(const ShapeSingleGroup& group);
// protected: // protected:
void add(const std::shared_ptr<shapes::Shape>& shape); void add(const std::shared_ptr<shapes::Shape>& shape);
std::vector<std::shared_ptr<Shape>> shapeList;
private: private:
void rebuildBoundingVolume(); void rebuildBoundingVolume();
bool rebuildBB;
util::AxisAlignedBoundingBox boundingVolume; util::AxisAlignedBoundingBox boundingVolume;
std::vector<std::shared_ptr<Shape>> shapeList;
util::Transformation transform; util::Transformation transform;
}; };
} // namespace shapes } // 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