osg线段和模型求交点

  1. osg::Vec3 p_start(-100,0,0);  
  2.     osg::Vec3 p_end(100,0,0);  
  3.     osgUtil::LineSegmentIntersector::Intersections _intersections;  
  4.     osg::ref_ptr< osgUtil::LineSegmentIntersector > _lineSegmentIntersector = new osgUtil::LineSegmentIntersector(p_start,p_end);  
  5.     osgUtil::IntersectionVisitor _iv(_lineSegmentIntersector.get());  
  6.     cow->accept(_iv);  
  7.     _intersections=_lineSegmentIntersector->getIntersections();  
  8.     int _intersectionNumber=_intersections.size();          
  9.     if (_intersectionNumber!=0)  
  10.     {           
  11.         osgUtil::LineSegmentIntersector::Intersections::iterator hitr = _intersections.begin();  
  12.         osg::Vec3 vec3_p1 =hitr->getWorldIntersectPoint()*mt_cow->getMatrix();//这样得到的交点就是绝对的世界坐标了。  
  13.         mt_axes->setMatrix(osg::Matrix::translate(vec3_p1));//把坐标系原点移动到交点,可以测试现在的坐标系原点是不是刚好和牛相交!  
  14.         hitr++;  
  15.         osg::Vec3 vec3_p2 =hitr->getWorldIntersectPoint()*mt_cow->getMatrix();  
  16.     }  
posted @ 2013-04-10 11:42  酷熊  阅读(1303)  评论(0编辑  收藏  举报