OSG 添加快捷键(1)

  • A+
所属分类:GIS应用
  1. #include<osgViewer/Viewer>
  2. #include<osgDB/ReadFile>
  3. #include "../../ConsoleApplication1/ConsoleApplication1/Common.h"
  4. #include <osgGA/GUIEventAdapter>
  5. #include<osgViewer/ViewerEventHandlers>
  6. //#ifdef _DEBUG
  7. //#pragma comment(lib,"../Debug/Commond.lib")
  8. //#else
  9. //#pragma comment(lib,"../Release/Common.lib")
  10. //#endif // _DEBUG
  11. //模拟一个事件类
  12. class PrintName :public osgGA::GUIEventHandler
  13. {
  14. public:
  15.     //点击h之后弹出的字幕,告知用户使用快捷键k,触发某个功能
  16.     virtual void getUsage(osg::ApplicationUsage& usage) const
  17.     {
  18.         usage.addKeyboardMouseBinding("k""call handler func");
  19.     }
  20.     //处理方法,返回true不向下传递;返回false向下传递
  21.     virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
  22.     {
  23.         //TODO 编写具体功能
  24.         return false;
  25.     }
  26.     //另外还有个设置快捷键的方法,表明按下此快捷键,则出发handler方法
  27. };
  28. int main(int argc, char *argv[])
  29. {
  30.     osg::ref_ptr<osgViewer::Viewer> viewer= new osgViewer::Viewer;
  31.     osg::ref_ptr<osg::Node> node = new osg::Node;
  32.     //读取模型
  33.     node = osgDB::readNodeFile("glider.osg");
  34.     //添加帮助事件
  35.     viewer->addEventHandler(new osgViewer::HelpHandler);//添加h快捷键,弹出快捷键功能说明字幕
  36.     viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);//添加截屏快捷键 c
  37.     viewer->addEventHandler(new osgViewer::StatsHandler);//添加帧率显示快捷键 s
  38.     viewer->addEventHandler(new osgViewer::WindowSizeHandler);//添加窗口缩放快捷键 f
  39.     viewer->addEventHandler(new PrintName);//添加自定义快捷键 k
  40.     viewer->setSceneData(node.get());
  41.     return viewer->run();
  42. }

依赖库

  1. #pragma comment(lib,"osgd.lib")
  2. #pragma comment(lib,"osgDBd.lib")
  3. #pragma comment(lib,"osgViewerd.lib")
  4. #pragma comment(lib,"OpenThreadsd.lib")
  5. #pragma comment(lib,"osgGAd.lib")

 

腾讯云推广
阿拉灯aladeng