#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventHandler>
#include <osgFX/Outline>
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();
//点击节点切换高亮
osg::ref_ptr<osg::Group> parent = new osg::Group;
parent = dynamic_cast<osg::Group*> (nodePath[nodePath.size() - 2]);//当前选择节点的父节点
osgFX::Outline *ot = dynamic_cast<osgFX::Outline*>(parent.get());
if (!ot) //若ot不存在(未高亮) (node->parent)=>(node->outline->parent)
{
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载