|
本帖最后由 ldj 于 2013-6-22 09:58 编辑
root是场景根节点,下面有多个plod,每个plod 里面设置多个文件和距离,鼠标查询无效。请高手帮忙
//事件处理函数
bool CPickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
//AfxMessageBox(_T("ddd"));
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
if (!viewer)
return false;
switch(ea.getEventType())
{
/* case(osgGA::GUIEventAdapter:: PUSH):
{
m_x=ea.getX();
m_y=ea.getY();
pick(viewer,m_x,m_y);
return false;
}*/
//每一帧
case(osgGA::GUIEventAdapter::RELEASE):
{
m_x=ea.getX();
m_y=ea.getY();
pick(viewer,m_x,m_y);
return false;
}
default:
return false;
}
}
//PICK动作
void CPickHandler:: pick(osgViewer::Viewer* viewer,double x,double y)
{
if(!viewer->getSceneData())
return ;
double w(0.05),h(0.05);
osgUtil:: PolytopeIntersector * picker=new osgUtil:: PolytopeIntersector(osgUtil::Intersector::WINDOW,x-h,y-h,x+h,y+h);
osgUtil::IntersectionVisitor iv(picker);
osg::Node *node=viewer->getSceneData();
osg::Group *group=node->asGroup();
group->accept(iv);
//viewer->getCamera()->accept(iv);
if(picker->containsIntersections())
{
osg::NodePath& nodepath= picker->getFirstIntersection().nodePath ;
unsigned int idx=nodepath.size();
osg::Node *node= dynamic_cast<osg::Node *>(nodepath[idx-1]);
m_osgHandle-> PickNodeCallBack(node);
}
} |
|