void OctTree::rebase(int whichChildAmI) { UTIL_ASSERT(parent == NULL); UTIL_ASSERT(whichChildAmI >= 0 && whichChildAmI < kNumNodes); UTIL_ASSERT(GUtils::norm(boundingBox.getDimensions()) < 100000); OctTree * copy = createChild(boundingBox); copy->enclosedObjects = enclosedObjects; enclosedObjects.clear(); for (int i = 0; i < kNumNodes; i++) { copy->children[i] = children[i]; if (children[i] != NULL) copy->children[i]->parent = copy; children[i] = NULL; } copy->address = whichChildAmI; copy->activeChildren = activeChildren; activeChildren = 0; setChildActive(whichChildAmI, copy->isActive()); children[whichChildAmI] = copy; boundingBox = boundingBoxForParent(whichChildAmI); updateActiveStates(copy); }
void OctTree::pruneEmptyBranches() { for (int i = 0; i < kNumNodes; i++) { if (children[i] != NULL && children[i]->activeChildren == 0 && children[i]->numDirectlyHeldObjects() == 0) { UTIL_ASSERT(children[i]->totalNumberOfObjectsInHierarchy() == 0); children[i]->pruneEverything(); delete children[i]; children[i] = NULL; setChildActive(i, false); } } }
void IntersectActor::setupChildrenPriorities(void) { UInt32 numChildren = getNumChildren (); UInt32 numExtraChildren = getNumExtraChildren(); Real32 scaleFactor = getScaleFactor(); Real32 hitDist = getHitDistance(); Real32 bvEnter; Real32 bvExit; setChildrenListEnabled(true); for(UInt32 i = 0; i < numChildren; ++i) { #ifndef OSG_2_PREP const DynamicVolume &vol = getChild(i)->editVolume(true); #else const BoxVolume &vol = getChild(i)->editVolume(true); #endif if((vol.intersect(getRay(), bvEnter, bvExit) == true ) && (bvEnter * scaleFactor < hitDist) ) { setChildPriority(i, -bvEnter * scaleFactor); } else { setChildActive (i, false); } } for(UInt32 i = 0; i < numExtraChildren; ++i) { #ifndef OSG_2_PREP const DynamicVolume &vol = getChild(i)->editVolume(true); #else const BoxVolume &vol = getChild(i)->editVolume(true); #endif if((vol.intersect(getRay(), bvEnter, bvExit) == true ) && (bvEnter * scaleFactor < hitDist) ) { setExtraChildPriority(i, -bvEnter * scaleFactor); } else { setExtraChildActive (i, false); } } }