|
本帖最后由 ldj 于 2013-6-2 14:57 编辑
//事件处理函数
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:USH):
{
m_x=ea.getX();
m_y=ea.getY();
pick(viewer,m_x,m_y);
return false;
}
//每一帧
// case(osgGA::GUIEventAdapter::RELEASE):
//{
// if(m_x==ea.getX()&&m_y==ea.getY())
//
// //执行PICK动作
//
//
//
// return false;
//}
default:
return false;
}
}
//PICK动作
void CPickHandler::pick(osgViewer::Viewer* viewer,double x,double y)
{
if(!viewer->getSceneData())
return ;
double w(0.5),h(0.5);
osgUtil::PolytopeIntersector *picker=new osgUtil::PolytopeIntersector(osgUtil::Intersector::PROJECTION,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);
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->ickNodeCallBack(node);
}
}
请高手帮助看下。 |
|