Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Hit Testing

Hit testing is accomplished using the RayIntersectTraverser class. NVSG does not use OpenGL-specific hit testing. Instead, NVSG performs hit testing directly on the scenegraph data, making it device independent.

The following sample code makes use of RayIntersectTraverser. In this example we try to determine the nearest object the ray hits, starting at the origin.

//[...]

// setup the RayIntersectTraverser
RayIntersectTraverser * pPicker;
pPicker = new RayIntersectTraverser;
pPicker->addRef();
pPicker->setRay(rayOrigin, rayDirection);

// do the hit test
pPicker->apply(m_viewState, m_scene);

// determine the nearest object
Drawable * pHitObject = NULL;
if (pPicker->getNumberOfIntersections() > 0)
{
  Intersection intersection = picker->getNearest();
  pHitObject = intersection.getDrawable();
  pHitObject->addRef();
}

//[...]

// clean up
pPicker->removeRef();
pPicker = NULL;

if (pHitObject)
{
  pHitObject->removeRef();
  pHitObject = NULL;
}

//[...]

See nvtraverser::Intersection and nvtraverser::RayIntersectTraverser documentation for further details.

Back to:


Generated on Tue Mar 1 13:20:21 2005 for NVSGSDK by NVIDIA