Advertisement
Guest User

intersection groups

a guest
Feb 16th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. bool normalAndHot(const osg::Vec3d& position, osgViewer::CompositeViewer& viewer, osg::Vec3& normal, osg::Vec3d& hot)
  2. {  
  3.     osgSim::LineOfSight los;
  4.  
  5.     osg::Vec3d s = position + osg::Vec3d(0, 0, 10000);
  6.     osg::Vec3d e = position - osg::Vec3d(0, 0, 10000);
  7.     los.addLOS(s, e);
  8.  
  9.     if (viewer.getView(0)->getSceneData())
  10.     {
  11.         osg::ref_ptr<osgUtil::IntersectorGroup> intersectorGroup = new osgUtil::IntersectorGroup();
  12.         osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(s, e);
  13.         intersectorGroup->addIntersector(intersector.get());
  14.  
  15.         osgUtil::IntersectionVisitor intersectVisitor(intersectorGroup.get());
  16.  
  17.         viewer.getView(0)->getSceneData()->accept(intersectVisitor);
  18.  
  19.         if (intersectorGroup->containsIntersections())
  20.         {
  21.             osgUtil::IntersectorGroup::Intersectors& intersectors = intersectorGroup->getIntersectors();
  22.             for (osgUtil::IntersectorGroup::Intersectors::iterator intersector_itr = intersectors.begin();
  23.                 intersector_itr != intersectors.end();
  24.                 ++intersector_itr)
  25.             {
  26.                 osgUtil::LineSegmentIntersector* lsi = dynamic_cast<osgUtil::LineSegmentIntersector*>(intersector_itr->get());
  27.                 if (lsi)
  28.                 {
  29.                     osgUtil::LineSegmentIntersector::Intersections& intersections = lsi->getIntersections();
  30.                     for (osgUtil::LineSegmentIntersector::Intersections::iterator itr = intersections.begin();
  31.                         itr != intersections.end();
  32.                         ++itr)
  33.                     {
  34.                         const osgUtil::LineSegmentIntersector::Intersection& intersection = *itr;
  35.  
  36.                         normal = intersection.getWorldIntersectNormal();
  37.                         hot = intersection.getWorldIntersectPoint();
  38.  
  39.                         std::cout << "HOT: " << hot << std::endl;
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement