src/3D/BVH.cpp
// returns true if something hit (recursively)
//
// populates outparam with all AABB hits in depth-first order
returns true if something hit (recursively)
populates outparam with all AABB hits in depth-first order
returns true if something hit ( recursively ) populates outparam with all AABB hits in depth - first order
static bool BVH_GetRayAABBCollisionsRecursive(
        BVH const& bvh,
        Line const& ray,
        int nodeidx,
        std::vector<BVHCollision>& out) {
    BVHNode const& node = bvh.nodes[nodeidx];
    RayCollision res = GetRayCollisionAABB(ray, node.bounds);
    if (!res.hit) {
        return false;  
    }
    if (node.nlhs == -1) {
        out.push_back(BVHCollision{bvh.prims[node.firstPrimOffset].id, res.distance});
        return true;
    }
    bool lhs = BVH_GetRayAABBCollisionsRecursive(bvh, ray, nodeidx+1, out);
    bool rhs = BVH_GetRayAABBCollisionsRecursive(bvh, ray, nodeidx+node.nlhs+1, out);
    return lhs || rhs;
}
static bool BVH_GetRayAABBCollisionsRecursive ( BVH const & bvh , Line const & ray , int nodeidx , std :: vector < BVHCollision > & out ) { BVHNode const & node = bvh . nodes [ nodeidx ] ; RayCollision res = GetRayCollisionAABB ( ray , node . bounds ) ; if ( ! res . hit ) { return false ; } if ( node . nlhs == -1 ) { out . push_back ( BVHCollision { bvh . prims [ node . firstPrimOffset ] . id , res . distance } ) ; return true ; } bool lhs = BVH_GetRayAABBCollisionsRecursive ( bvh , ray , nodeidx + 1 , out ) ; bool rhs = BVH_GetRayAABBCollisionsRecursive ( bvh , ray , nodeidx + node . nlhs + 1 , out ) ; return lhs || rhs ; }
returns true if something hit (recursively)
populates outparam with all AABB hits in depth-first order
returns true if something hit ( recursively ) populates outparam with all AABB hits in depth - first order
// check ray-AABB intersection with the BVH node // no intersection with this node at all // it's a leaf node, so we've sucessfully found the AABB that intersected // else: we've "hit" an internal node and need to recurse to find the leaf