Hi,
I'm just starting using OSG for an application I'm writing, so there is probably a lot of mistakes in the code... It is an OSG API usage question. _What I'm trying to do:_ *I'd like to write a function that finds all elements of a scene that intersect a given bounding box which is given in world coordinates. * Here are my open issues: 1. Is there a simpler way to do this that I've missed in the documentation and example code? 2. Is PolytopeIntersector the best Intersector class for doing this or is the PlaneIntersector better? 3. When defining the PolytopeIntersector, is osgUtil::Intersector::MODEL the right enumeration for world coordinates? Below is a rough implementation of the function. Any help would be greatly appreciated. Thanks in advance, Eyal. Rough Implementation: ----------------------- /** * Finds all elements in the scene that intersect the given bounding box. * @param minCorner The minimum corner of the bounding box (in world coordinates). * @param maxCorner The maximum corner of the bounding box (in world coordinates). * @param viewer The Viewer associated with the scene. */ static void findIntersectingSceneElements( osg::Vec3 minCorner, osg::Vec3 maxCorner, osgViewer::Viewer* viewer ) { osg::Node* node = 0; osg::Group* parent = 0; osgUtil::PolytopeIntersector* picker; // Defines the six planes of the bounding box. osg::Polytope boudndingBoxPolytope; // The code below is not efficient or pretty. Just for making the code clearer. // The eight corners of the bounding box. osg::Vec3 corner0( minCorner.x(), minCorner.y(), minCorner.z() ); osg::Vec3 corner1( maxCorner.x(), minCorner.y(), minCorner.z() ); osg::Vec3 corner2( maxCorner.x(), maxCorner.y(), minCorner.z() ); osg::Vec3 corner3( minCorner.x(), maxCorner.y(), minCorner.z() ); osg::Vec3 corner4( minCorner.x(), minCorner.y(), maxCorner.z() ); osg::Vec3 corner5( maxCorner.x(), minCorner.y(), maxCorner.z() ); osg::Vec3 corner6( maxCorner.x(), maxCorner.y(), maxCorner.z() ); osg::Vec3 corner7( minCorner.x(), maxCorner.y(), maxCorner.z() ); // Create the six planes that define the bounding box. boudndingBoxPolytope.add(osg::Plane( corner0, corner1, corner4 ) ); // Does the order of vertices matter? boudndingBoxPolytope.add(osg::Plane( corner1, corner2, corner5 )); boudndingBoxPolytope.add(osg::Plane( corner2, corner3, corner6 )); boudndingBoxPolytope.add(osg::Plane( corner3, corner0, corner7 )); boudndingBoxPolytope.add(osg::Plane( corner1, corner2, corner2 )); boudndingBoxPolytope.add(osg::Plane( corner4, corner5, corner7 )); // Is the MODEL the right enumeration to use? picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::MODEL, boudndingBoxPolytope ); osgUtil::IntersectionVisitor iv( picker ); viewer->getCamera()->accept( iv ); if (picker->containsIntersections()) { osgUtil::PolytopeIntersector::Intersections& intersections = picker->getIntersections(); for (osgUtil::PolytopeIntersector::Intersections::iterator it=intersections.begin(); it!=intersections.end(); ++it) { osgUtil::PolytopeIntersector::Intersection intersection=*it; osg::NodePath& nodePath = intersection.nodePath; node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0; parent = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0; if (node) std::cout<<" Hits "<<node->className()<<" nodePath size"<<nodePath.size()<<std::endl; //toggleScribe(parent, node); } } } _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org