#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventHandler>
class nodePick :public osgGA::GUIEventHandler
{
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer*> (&aa);
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::PUSH:
{
osgUtil::LineSegmentIntersector::Intersections intersections;
osg::ref_ptr<osg::Node> node = new osg::Node;
if (viewer->computeIntersections(ea.getX(), ea.getY(), intersections))
{
//得到选择的节点
osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
osg::NodePath& nodePath = intersection.nodePath;
node = nodePath.back();
//点击节点透明
node->setNodeMask(0);
}
}
default:
return false;
}
}
};
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osg