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

Added function contains for bb. Fixed partially contains.

parent 6fe247f0
No related branches found
No related tags found
No related merge requests found
...@@ -91,17 +91,37 @@ bool AxisAlignedBoundingBox::contains(const Vec3& v) const { ...@@ -91,17 +91,37 @@ bool AxisAlignedBoundingBox::contains(const Vec3& v) const {
return x && y && z; return x && y && z;
} }
bool AxisAlignedBoundingBox::contains(const AxisAlignedBoundingBox& bb) const {
std::array<Vec3, 8> vertices = {
Vec3(bb.minBound().x(), bb.minBound().y(), bb.minBound().z()),
Vec3(bb.minBound().x(), bb.minBound().y(), bb.maxBound().z()),
Vec3(bb.minBound().x(), bb.maxBound().y(), bb.minBound().z()),
Vec3(bb.minBound().x(), bb.maxBound().y(), bb.maxBound().z()),
Vec3(bb.maxBound().x(), bb.minBound().y(), bb.minBound().z()),
Vec3(bb.maxBound().x(), bb.minBound().y(), bb.maxBound().z()),
Vec3(bb.maxBound().x(), bb.maxBound().y(), bb.minBound().z()),
Vec3(bb.maxBound().x(), bb.maxBound().y(), bb.maxBound().z())};
for (Vec3 v : vertices)
if (!contains(v)) return false;
return true;
}
// This Method is not entirely correct. It only checks if the corners of this bb // This Method is not entirely correct. It only checks if the corners of this bb
// is inside the arguments bb. This should be enough for the splitting algorithm // is inside the arguments bb. This should be enough for the splitting algorithm
// to create a hierarchy. Theoretically there are overlapping bbs, where no // to create a hierarchy. Theoretically there are overlapping bbs, where no
// corner is inside the others. // corner is inside the others.
bool AxisAlignedBoundingBox::partiallyContains( bool AxisAlignedBoundingBox::partiallyContains(
const AxisAlignedBoundingBox bb) { const AxisAlignedBoundingBox& bb) const {
std::array<Vec3, 8> vertices = { std::array<Vec3, 8> vertices = {
Vec3(min.x(), min.y(), min.z()), Vec3(min.x(), min.y(), max.z()), Vec3(bb.minBound().x(), bb.minBound().y(), bb.minBound().z()),
Vec3(min.x(), max.y(), min.z()), Vec3(min.x(), max.y(), max.z()), Vec3(bb.minBound().x(), bb.minBound().y(), bb.maxBound().z()),
Vec3(max.x(), min.y(), min.z()), Vec3(max.x(), min.y(), max.z()), Vec3(bb.minBound().x(), bb.maxBound().y(), bb.minBound().z()),
Vec3(max.x(), max.y(), min.z()), Vec3(max.x(), max.y(), max.z())}; Vec3(bb.minBound().x(), bb.maxBound().y(), bb.maxBound().z()),
Vec3(bb.maxBound().x(), bb.minBound().y(), bb.minBound().z()),
Vec3(bb.maxBound().x(), bb.minBound().y(), bb.maxBound().z()),
Vec3(bb.maxBound().x(), bb.maxBound().y(), bb.minBound().z()),
Vec3(bb.maxBound().x(), bb.maxBound().y(), bb.maxBound().z())};
for (Vec3 v : vertices) for (Vec3 v : vertices)
if (bb.contains(v)) return true; if (bb.contains(v)) return true;
return false; return false;
...@@ -123,7 +143,7 @@ void AxisAlignedBoundingBox::orientate() { ...@@ -123,7 +143,7 @@ void AxisAlignedBoundingBox::orientate() {
std::max<float>(min.y(), max.y()), std::max<float>(min.y(), max.y()),
std::max<float>(min.z(), max.z())); std::max<float>(min.z(), max.z()));
} }
// Pair is 0->Left 1->Right
std::array<AxisAlignedBoundingBox, 2> splitAABB(AxisAlignedBoundingBox box) { std::array<AxisAlignedBoundingBox, 2> splitAABB(AxisAlignedBoundingBox box) {
util::Vec3 size2 = (box.maxBound() - box.minBound()) / 2; util::Vec3 size2 = (box.maxBound() - box.minBound()) / 2;
AxisAlignedBoundingBox left; AxisAlignedBoundingBox left;
......
...@@ -18,7 +18,8 @@ class AxisAlignedBoundingBox { ...@@ -18,7 +18,8 @@ class AxisAlignedBoundingBox {
// Methods // Methods
bool intersects(const cam::Ray& r) const; bool intersects(const cam::Ray& r) const;
bool contains(const Vec3& v) const; bool contains(const Vec3& v) const;
bool partiallyContains(const AxisAlignedBoundingBox bb); bool contains(const AxisAlignedBoundingBox& bb) const;
bool partiallyContains(const AxisAlignedBoundingBox& bb) const;
Vec3 center() const; Vec3 center() const;
Vec3 minBound() const; Vec3 minBound() const;
Vec3 maxBound() const; Vec3 maxBound() const;
......
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