HPC Magazine avril 2013 - L'Atelier CUDA - Listing 1.

Identification récursive des objets chevauchés.


void traverseRecursive(
  CollisionList& list,
  const BVH& bvh, 
  const AABB& queryAABB,
  int queryObjectIdx,
  NodePtr node)
{
  // L'enveloppe chevauche => traitement du noeud.
  if (checkOverlap(bvh.getAABB(node), queryAABB)) {
    // Descendant final => collision.
    if (bvh.isLeaf(node))
      list.add(queryObjectIdx, bvh.getObjectIdx(node));
    // Internal intermediaire => recursion.
    else {
      NodePtr childL = bvh.getLeftChild(node);
      NodePtr childR = bvh.getRightChild(node);
      traverseRecursive(bvh, list, queryAABB, queryObjectIdx, childL);
      traverseRecursive(bvh, list, queryAABB, queryObjectIdx, childR);
    }
  }
}