- Timestamp:
- 10/07/08 16:01:14 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgspheresegment/osgspheresegment.cpp
r7648 r8998 28 28 29 29 #include <osgUtil/SmoothingVisitor> 30 #include <osgUtil/IntersectVisitor>31 30 32 31 #include <osgDB/ReadFile> … … 318 317 osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y) 319 318 { 320 osgUtil::IntersectVisitor iv;321 osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;322 323 319 const osg::BoundingSphere& bs = subgraph->getBound(); 324 320 float zMax = bs.center().z()+bs.radius(); 325 321 float zMin = bs.center().z()-bs.radius(); 326 322 327 segDown->set(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax)); 328 iv.addLineSegment(segDown.get()); 323 osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = 324 new osgUtil::LineSegmentIntersector(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax)); 325 326 osgUtil::IntersectionVisitor iv(intersector.get()); 329 327 330 328 subgraph->accept(iv); 331 329 332 if (iv.hits()) 333 { 334 osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); 335 if (!hitList.empty()) 336 { 337 osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); 338 return ip; 339 } 330 if (intersector->containsIntersections()) 331 { 332 return intersector->getFirstIntersection().getWorldIntersectPoint(); 340 333 } 341 334
