Adding the selectBranch

This commit is contained in:
samcake 2016-02-01 16:48:23 -08:00
parent 7cb0108457
commit ee7ca35c0c
2 changed files with 22 additions and 3 deletions

View file

@ -238,7 +238,7 @@ int Octree::select(ItemIDs& selection, const glm::vec4 frustum[6]) const {
}
int Octree::selectTraverse(Index cellID, ItemIDs& selection, const Coord4f frustum[6]) const {
int numItemsIn = selection.size();
int numSelectedsIn = selection.size();
auto cell = getConcreteCell(cellID);
auto intersection = Octree::Location::intersectCell(cell.getlocation(), frustum);
@ -249,7 +249,7 @@ int Octree::selectTraverse(Index cellID, ItemIDs& selection, const Coord4f frust
break;
case Octree::Location::Inside: {
// traverse all the Cell Branch and collect items in the selection
selection.push_back(cellID);
selectBranch(cellID, selection, frustum);
break;
}
case Octree::Location::Intersect:
@ -269,10 +269,28 @@ int Octree::selectTraverse(Index cellID, ItemIDs& selection, const Coord4f frust
}
}
return selection.size() - numItemsIn;
return selection.size() - numSelectedsIn;
}
int Octree::selectBranch(Index cellID, ItemIDs& selection, const Coord4f frustum[6]) const {
int numSelectedsIn = selection.size();
auto cell = getConcreteCell(cellID);
// Collect the items of this cell
selection.push_back(cellID);
// then traverse further
for (int i = 0; i < NUM_OCTANTS; i++) {
Index subCellID = cell.child((Link)i);
if (subCellID != INVALID) {
selectBranch(subCellID, selection, frustum);
}
}
return selection.size() - numSelectedsIn;
}
Octree::Location::Intersection Octree::Location::intersectCell(const Location& cell, const Coord4f frustum[6]) {
const Coord3f CornerOffsets[8] = {
{ 0.0, 0.0, 0.0 },

View file

@ -245,6 +245,7 @@ namespace render {
// Selection and traverse
int select(ItemIDs& selection, const Coord4f frustum[6]) const;
int selectTraverse(Index cellID, ItemIDs& selection, const Coord4f frustum[6]) const;
int selectBranch(Index cellID, ItemIDs& selection, const Coord4f frustum[6]) const;
protected:
Index allocateCell(Index parent, const Location& location);