This example demonstrates oriented bounding box (OBB) tree construction and ray tracing. It shows how to load a triangular mesh, build an oriented bounding box tree for spatial queries, and perform ray tracing through the mesh to calculate intersection distances and facets. The OBB tree provides efficient spatial partitioning for ray tracing and collision detection applications.
#include <iostream>
#include <cmath>
int main(
int argc,
char** argv )
{
if( 1 == argc )
{
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
return 0;
}
double box_center[3], box_axis1[3], box_axis2[3], box_axis3[3], pnt_start[3], ray_length;
"Couldn't get box for tree root set" );
ray_length = 2. * sqrt( box_axis1[0] * box_axis1[0] + box_axis1[1] * box_axis1[1] + box_axis1[2] * box_axis1[2] );
std::vector< double > intersections;
std::vector< moab::EntityHandle > intersection_facets;
for( int i = 0; i < 3; i++ )
pnt_start[i] = box_center[i] - box_axis1[i];
if( ray_length > 0 )
{
for( int j = 0; j < 3; j++ )
box_axis1[j] = 2 * box_axis1[j] / ray_length;
}
box_axis1, &ray_length ),
"Couldn't perform ray tracing" );
std::cout << "ray start point: " << pnt_start[0] << " " << pnt_start[1] << " " << pnt_start[2] << std::endl;
std::cout << " ray direction: " << box_axis1[0] << " " << box_axis1[1] << " " << box_axis1[2] << "\n";
std::cout << "# of intersections : " << intersections.size() << std::endl;
std::cout << "intersection distances are on";
for( unsigned int i = 0; i < intersections.size(); i++ )
std::cout << " " << intersections[i];
std::cout << " of ray length " << ray_length << std::endl;
return 0;
}