|
楼主 |
发表于 2011-8-18 09:35:37
|
显示全部楼层
我的的意思就是说:
- mHudCamera->addChild(mArtRoot);
- mHudCamera->addChild(mToolRoot);
- mHudCamera->addChild(mBackGeode);
- mHudCamera->addEventCallback(new C3DCameraEvent(this));
复制代码 在这个camera下添加了一个事件回调,用来检测是否单击了mArtRoot、mToolRoot这两个节点下的某个按钮,事件回调的函数如下:
- class C3DCameraEvent: public osg::NodeCallback
- {
- public:
- C3DCameraEvent(CArt3D* art3d);
- ~C3DCameraEvent(void);
- virtual void operator()(osg::Node* n, osg::NodeVisitor* nv)
- {
- osgGA::EventVisitor* eventVisitor=dynamic_cast<osgGA::EventVisitor*>(nv);
- osg::Camera* node=dynamic_cast<osg::Camera*>(n);
- if (!eventVisitor || !node)
- {
- std::cout<<"Camera listener fail"<<std::endl;
- return;
- }
- osgGA::EventQueue::Events& events=eventVisitor->getEvents();
- for (osgGA::EventQueue::Events::const_iterator ite = events.begin(); ite != events.end(); ite++)
- {
- double mx;
- double my;
- double w;
- double h;
- osgUtil::PolytopeIntersector* intersector = NULL;
- osgUtil::IntersectionVisitor iv;
- osgUtil::PolytopeIntersector* intersector1 = NULL;
- osgUtil::IntersectionVisitor iv1;
- switch ((*ite)->getEventType())
- {
- case osgGA::GUIEventAdapter::PUSH:
- {
- mx = (*ite)->getXnormalized();
- my = (*ite)->getYnormalized();
- w = 0.005;
- h = 0.005;
- intersector = new osgUtil::PolytopeIntersector( osgUtil::Intersector::PROJECTION, mx-w, my-h, mx+w, my+h );
- iv.setIntersector(intersector);
- node->accept(iv);
- if (intersector->containsIntersections())
- {
- osgUtil::PolytopeIntersector::Intersection intersection = intersector->getFirstIntersection();
- osg::NodePath& nodePath = intersection.nodePath;
- osg::Node* internode = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
- std::string name = internode->getName();
- std::string classname = internode->className();
- mArt3D->mousePush(name);
- }
- }
- break;
- case osgGA::GUIEventAdapter::MOVE:
- {
- mx = (*ite)->getXnormalized();
- my = (*ite)->getYnormalized();
- w = 0.005;
- h = 0.005;
- intersector1 = new osgUtil::PolytopeIntersector( osgUtil::Intersector::PROJECTION, mx-w, my-h, mx+w, my+h );
- iv1.setIntersector(intersector1);
- node->accept(iv1);
- if (intersector1->containsIntersections())
- {
- osgUtil::PolytopeIntersector::Intersection intersection = intersector1->getFirstIntersection();
- osg::NodePath& nodePath = intersection.nodePath;
- osg::Node* internode = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
- std::string name = internode->getName();
- std::string classname = internode->className();
- mArt3D->mouseEnter(name);
- }
- }
- break;
- case osgGA::GUIEventAdapter::DRAG:
- {
- //
- mArt3D->mouseDrag();
- }
- break;
- default:
- break;
- }
- }
- traverse(n,nv);
- }
- public:
- CArt3D* mArt3D;
复制代码 然后我直接在VS2010调试程序,单击上面的运行调试程序,在这种情况下是没有问题,按键都可以响应到。
但是我单击在它生成的(debug)EXE程序时就会出现有些按钮不能响应。
就是直线在编译器运行调试程序跟在debug生成的程序不一样。 |
|