- osg::Vec3 p_start(-100,0,0);
- osg::Vec3 p_end(100,0,0);
- osgUtil::LineSegmentIntersector::Intersections _intersections;
- osg::ref_ptr< osgUtil::LineSegmentIntersector > _lineSegmentIntersector = new osgUtil::LineSegmentIntersector(p_start,p_end);
- osgUtil::IntersectionVisitor _iv(_lineSegmentIntersector.get());
- cow->accept(_iv);
- _intersections=_lineSegmentIntersector->getIntersections();
- int _intersectionNumber=_intersections.size();
- if (_intersectionNumber!=0)
- {
- osgUtil::LineSegmentIntersector::Intersections::iterator hitr = _intersections.begin();
- osg::Vec3 vec3_p1 =hitr->getWorldIntersectPoint()*mt_cow->getMatrix();//这样得到的交点就是绝对的世界坐标了。
- mt_axes->setMatrix(osg::Matrix::translate(vec3_p1));//把坐标系原点移动到交点,可以测试现在的坐标系原点是不是刚好和牛相交!
- hitr++;
- osg::Vec3 vec3_p2 =hitr->getWorldIntersectPoint()*mt_cow->getMatrix();
- }