OSG程序设计之Hello World 3.0
作者:互联网
直接上代码:
#include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgGA/TrackballManipulator> #include <osgGA/FlightManipulator> #include <osgGA/DriveManipulator> #include <osgGA/KeySwitchMatrixManipulator> #include <osgGA/StateSetManipulator> #include <osgGA/AnimationPathManipulator> #include <osgGA/TerrainManipulator> void main() { osgViewer::Viewer viewer; viewer.setSceneData(osgDB::readNodeFile("glider.osg")); //添加状态事件 viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); //窗口大小变化事件 viewer.addEventHandler(new osgViewer::WindowSizeHandler); //添加一些常用状态设置 viewer.addEventHandler(new osgViewer::StatsHandler); //添加一些操作器 osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; keyswitchManipulator->addMatrixManipulator('1', "Trackball", new osgGA::TrackballManipulator()); keyswitchManipulator->addMatrixManipulator('2', "Flight", new osgGA::FlightManipulator()); keyswitchManipulator->addMatrixManipulator('3', "Drive", new osgGA::DriveManipulator()); keyswitchManipulator->addMatrixManipulator('4', "Terrain", new osgGA::TerrainManipulator()); viewer.setCameraManipulator(keyswitchManipulator.get()); //添加路径记录 viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); viewer.realize(); viewer.run(); }
3.0版本主要是添加了一些操作器。
关于什么是操作器,菜鸟表示完全不懂。现在的理解就是:不同的操作器对应不同的交互模式。
从Hello World1.0可知,用户通过鼠标可以操作模型。添加操作器之后,用户通过1 、2、3、4按键选择不同的操作器,就会对应不同的交互模式。
转载于:https://www.cnblogs.com/gattaca/p/4527353.html
标签:viewer,keyswitchManipulator,添加,osgGA,3.0,new,include,Hello,OSG 来源: https://blog.csdn.net/weixin_34364071/article/details/93401736