void Octree::_FattenedRayLookup(int nindex,const Ray3D& ray,Real radius,vector<int>& nodeindices) const { const OctreeNode& node = nodes[nindex]; //this is kinda slower than it needs to be... can determine intersecting //children directly without testing all bb's if(IsLeaf(node)) { //fine grained test if(ray.distance(node.bb) <= radius) nodeindices.push_back(nindex); } else { vector<pair<Real,int> > children; for(int i=0;i<8;i++) { Real tmin = 0; Real tmax = Inf; AABB3D fattened = nodes[node.childIndices[i]].bb; fattened.bmin -= Vector3(radius); fattened.bmax += Vector3(radius); if(ray.intersects(fattened,tmin,tmax)) children.push_back(pair<Real,int>(tmin,node.childIndices[i])); } //loop through children, sorted by distance sort(children.begin(),children.end()); for(size_t i=0;i<children.size();i++) _FattenedRayLookup(children[i].second,ray,radius,nodeindices); } }