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

Groups can now only add other Groups. Added friend function that builds Groups...

Groups can now only add other Groups. Added friend function that builds Groups with a single Shape in it
parent 8678445a
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { ...@@ -31,6 +31,7 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const {
} }
} }
} }
if (result != nullptr) { if (result != nullptr) {
result = std::make_shared<cam::Hit>( result = std::make_shared<cam::Hit>(
cam::Hit(transform.toWorld.transformPoint(result->hit), cam::Hit(transform.toWorld.transformPoint(result->hit),
...@@ -42,10 +43,15 @@ std::shared_ptr<cam::Hit> Group::intersect(const cam::Ray& r) const { ...@@ -42,10 +43,15 @@ std::shared_ptr<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::add(const Group& group) {
shapeList.push_back(std::make_shared<Group>(group));
rebuildBoundingVolume();
}
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(); rebuildBoundingVolume();
} }
void Group::rebuildBoundingVolume() { void Group::rebuildBoundingVolume() {
util::AxisAlignedBoundingBox bb = shapeList[0]->bounds(); util::AxisAlignedBoundingBox bb = shapeList[0]->bounds();
for (auto shape_bb : shapeList) { for (auto shape_bb : shapeList) {
...@@ -53,5 +59,10 @@ void Group::rebuildBoundingVolume() { ...@@ -53,5 +59,10 @@ void Group::rebuildBoundingVolume() {
} }
boundingVolume = bb; boundingVolume = bb;
} }
Group shapeGroup(util::Mat4& matrix, std::shared_ptr<Shape> shape) {
Group g(matrix);
g.add(shape);
return g;
}
} // namespace shapes } // namespace shapes
\ No newline at end of file
...@@ -14,7 +14,10 @@ class Group : public Shape { ...@@ -14,7 +14,10 @@ class Group : public Shape {
std::shared_ptr<cam::Hit> intersect(const cam::Ray& r) const override; std::shared_ptr<cam::Hit> intersect(const cam::Ray& r) const override;
util::AxisAlignedBoundingBox bounds() const override; util::AxisAlignedBoundingBox bounds() const override;
// protected:TODO void add(const Group& group);
friend Group shapeGroup(util::Mat4& matrix, std::shared_ptr<Shape> shape);
protected:
void add(const std::shared_ptr<shapes::Shape>& shape); void add(const std::shared_ptr<shapes::Shape>& shape);
private: private:
......
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