Octree returns correct boxes when testing along an axis by searching through the correct child subtrees.
This commit is contained in:
@@ -15,6 +15,8 @@ AABB::AABB(const glm::vec3& minPos, const glm::vec3& maxPos)
|
||||
m_MinCorner.y = glm::min(m_MaxCorner.y, m_MinCorner.y);
|
||||
m_MaxCorner.z = glm::max(m_MaxCorner.z, m_MinCorner.z);
|
||||
m_MinCorner.z = glm::min(m_MaxCorner.z, m_MinCorner.z);
|
||||
m_Origin = 0.5f * (m_MaxCorner + m_MinCorner);
|
||||
m_HalfSize = 0.5f * (m_MaxCorner - m_MinCorner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -352,9 +352,13 @@ std::vector<int> Octree::Child::childIndicesContainingBox(const AABB& box) const
|
||||
//the dimensions they are responsible for (which octant).
|
||||
bits.flip();
|
||||
//At this point the bits necessarily have exactly one bit set.
|
||||
//Check the same bit in the minInd as the one set in bits.
|
||||
int setOrUnset = (bits.to_ulong() & minInd);
|
||||
for (int c = 0; c < 8; ++c) {
|
||||
//If the child index have the same bit set as the bits, add box to it.
|
||||
if (bits.to_ulong() & c) {
|
||||
//Check the same bit in the child index as the one set in bits.
|
||||
//Enter here if both c and minInd have the bit set, or if neither have it set.
|
||||
//I.e, if they are on the same side (+ or -) in the dimension marked by the bit in bits.
|
||||
if (!((bits.to_ulong() & c) ^ setOrUnset)) {
|
||||
ret.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user