查看: 2720|回复: 2

osg的键盘问题

[复制链接]

该用户从未签到

发表于 2008-6-23 18:40:05 | 显示全部楼层 |阅读模式
各位朋友,我在写键盘事件的时候,有一个getKey(),我想取得光标KEY_Up,进行事件触发,在switch代码块中的case (*) :应该怎么填写呀,谢谢,当然其他的也类似.如果我用字母我可以直接写为case 'w' :.其他的我就不知道了.请大侠给予帮助
谢谢

该用户从未签到

发表于 2008-6-23 21:25:10 | 显示全部楼层
  1.     bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
  2.     {
  3.         osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
  4.         if (!viewer) return false;

  5.         switch(ea.getEventType())
  6.         {
  7.             case(osgGA::GUIEventAdapter::KEYUP):
  8.             {
  9.                 if (ea.getKey()=='s')
  10.                 {
  11.                     saveSelectedModel(viewer->getSceneData());
  12.                 }               
  13.                 else if (ea.getKey()=='o')
  14.                 {
  15.                     osg::notify(osg::NOTICE)<<"Saved model to file 'saved_model.osg'"<<std::endl;
  16.                     osgDB::writeNodeFile(*(viewer->getSceneData()), "saved_model.osg");
  17.                 }
  18.                 else if (ea.getKey()=='p')
  19.                 {
  20.                     _usePolytopeIntersector = !_usePolytopeIntersector;
  21.                     if (_usePolytopeIntersector)
  22.                     {
  23.                         osg::notify(osg::NOTICE)<<"Using PolytopeIntersector"<<std::endl;
  24.                     } else {
  25.                         osg::notify(osg::NOTICE)<<"Using LineSegmentIntersector"<<std::endl;
  26.                     }
  27.                 }
  28.                 else if (ea.getKey()=='c')
  29.                 {
  30.                     _useWindowCoordinates = !_useWindowCoordinates;
  31.                     if (_useWindowCoordinates)
  32.                     {
  33.                         osg::notify(osg::NOTICE)<<"Using window coordinates for picking"<<std::endl;
  34.                     } else {
  35.                         osg::notify(osg::NOTICE)<<"Using projection coordiates for picking"<<std::endl;
  36.                     }
  37.                 }
  38.                 else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Delete || ea.getKey()==osgGA::GUIEventAdapter::KEY_BackSpace)
  39.                 {
  40.                     osg::notify(osg::NOTICE)<<"Delete"<<std::endl;
  41.                     DeleteSelectedNodesVisitor dsnv;
  42.                     viewer->getSceneData()->accept(dsnv);
  43.                     dsnv.pruneSelectedNodes();
  44.                 }
  45.                 return false;
  46.             }
  47.             case(osgGA::GUIEventAdapter::PUSH):
  48.             case(osgGA::GUIEventAdapter::MOVE):
  49.             {
  50.                 _mx = ea.getX();
  51.                 _my = ea.getY();
  52.                 return false;
  53.             }
  54.             case(osgGA::GUIEventAdapter::RELEASE):
  55.             {
  56.                 if (_mx == ea.getX() && _my == ea.getY())
  57.                 {
  58.                     // only do a pick if the mouse hasn't moved
  59.                     pick(ea,viewer);
  60.                 }
  61.                 return true;
  62.             }   

  63.             default:
  64.                 return false;
  65.         }
  66.     }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表