From abaa3299842c6f07dc88ab27048c10565b94d1d5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 21 Dec 2015 10:55:07 -0800 Subject: [PATCH] parents AACube should encompass all children's --- libraries/shared/src/AACube.cpp | 7 +++++++ libraries/shared/src/AACube.h | 2 ++ libraries/shared/src/SpatiallyNestable.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/libraries/shared/src/AACube.cpp b/libraries/shared/src/AACube.cpp index 32a304872c..4378dbb89b 100644 --- a/libraries/shared/src/AACube.cpp +++ b/libraries/shared/src/AACube.cpp @@ -465,3 +465,10 @@ AABox AACube::clamp(float min, float max) const { return temp.clamp(min, max); } +AACube& AACube::operator += (const glm::vec3& point) { + _corner = glm::min(_corner, point); + glm::vec3 scale = point - _corner; + _scale = glm::max(_scale, scale.x, scale.y, scale.z); + + return (*this); +} diff --git a/libraries/shared/src/AACube.h b/libraries/shared/src/AACube.h index d301207429..fbbbe9992a 100644 --- a/libraries/shared/src/AACube.h +++ b/libraries/shared/src/AACube.h @@ -64,6 +64,8 @@ public: AABox clamp(const glm::vec3& min, const glm::vec3& max) const; AABox clamp(float min, float max) const; + AACube& operator += (const glm::vec3& point); + private: glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const; glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const; diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 48e9b14271..0880d39356 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -585,6 +585,19 @@ bool SpatiallyNestable::setPuffedQueryAACube() { _queryAACube = AACube(currentAACube.getCorner() - glm::vec3(currentAACube.getScale()), currentAACube.getScale() * 3.0f); // _queryAACube = AACube(currentAACube.getCorner(), currentAACube.getScale()); _queryAACubeSet = true; + + getThisPointer()->forEachDescendant([&](SpatiallyNestablePointer descendant) { + bool success; + AACube descendantAACube = descendant->getMaximumAACube(success); + if (success) { + if (_queryAACube.contains(currentAACube)) { + return; + } + _queryAACube += descendantAACube.getMinimumPoint(); + _queryAACube += descendantAACube.getMaximumPoint(); + } + }); + return true; }