1. 程式人生 > >OSG拾取點和線當然面也能拾取

OSG拾取點和線當然面也能拾取

if (ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
{
	osg::ref_ptr<osgUtil::PolytopeIntersector> picker = new osgUtil::PolytopeIntersector(osgUtil::Intersector::WINDOW, ea.getX()-5.0, ea.getY()-5.0,ea.getX()+5.0,ea.getY()+5.0);
	osgUtil::IntersectionVisitor iv(picker.get());
	//osgViewer::View* pView = dynamic_cast<osgViewer::View*>(&us);
_view->getCamera()->accept(iv); if (picker->containsIntersections()) { osg::Vec3f ptWorldIntersectPointFirst = picker->getFirstIntersection().intersectionPoints[0]; osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(ptWorldIntersectPointFirst, 2.0); osg::ref_ptr<osg::ShapeDrawable>
sd = new osg::ShapeDrawable(sphere); sd->setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0)); _view->getSceneData()->asGroup()->addChild(sd.release()); } }

其中之意自己翻原始碼,只可意會不可言傳。