osg 自动漫游
2015-07-22 17:38
295 查看
介绍两种漫游方式,都是操作器的方式,但是都有所不同。
第一种为节点跟踪漫游器(NodeTrackerManipulator),主要是当前视点跟随这个节点的包围盒中心点,所以只要设置这个节点一个路径动画,那么当前视点就跟着节点一起漫游了。
第二种为路径漫游器(AnimationPathManipulator),主要是提前设置路径(AnimationPath),可以设置这个路径上的每个位置上的时间和旋转量,但是在漫游过程中不能修改当前的视点距离,只能按照提前设置好的视角和位置进行观察。
下面给出这两种方式的简单示例代码:其中的路径设置函数可以参考我前面文章关于路径动画的介绍,也可以自己写。
其中main2使用的节点跟踪漫游器(可以一直跟者飞机移动视点),main使用的路径漫游器(当前视点会从牛屁股里出来)。
第一种为节点跟踪漫游器(NodeTrackerManipulator),主要是当前视点跟随这个节点的包围盒中心点,所以只要设置这个节点一个路径动画,那么当前视点就跟着节点一起漫游了。
第二种为路径漫游器(AnimationPathManipulator),主要是提前设置路径(AnimationPath),可以设置这个路径上的每个位置上的时间和旋转量,但是在漫游过程中不能修改当前的视点距离,只能按照提前设置好的视角和位置进行观察。
下面给出这两种方式的简单示例代码:其中的路径设置函数可以参考我前面文章关于路径动画的介绍,也可以自己写。
其中main2使用的节点跟踪漫游器(可以一直跟者飞机移动视点),main使用的路径漫游器(当前视点会从牛屁股里出来)。
int main2() { osgViewer::Viewer viewer; viewer.addEventHandler(new ChangeWindow); osg::Group *pGroup = new osg::Group; osg::MatrixTransform* mt = new osg::MatrixTransform; osg::Node*glider = osgDB::readNodeFile("glider.osg"); mt->addChild(glider); osg::Vec3 ptS = osg::Vec3(0,0,0); osg::Vec3 ptE = osg::Vec3(-1000, 0, 0); osg::AnimationPath* path = createAnimationPath(ptS, ptE, 0, 1000); osg::NodeCallback* nc = new osg::AnimationPathCallback(path); mt->setUpdateCallback(nc); osgGA::NodeTrackerManipulator *tm = new osgGA::NodeTrackerManipulator; osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; tm->setTrackerMode(trackerMode); tm->setRotationMode(rotationMode); tm->setTrackNode(glider); pGroup->addChild(mt); pGroup->addChild(osgDB::readNodeFile("cow.osg")); viewer.setCameraManipulator(tm); viewer.setSceneData(pGroup); viewer.run(); return 0; } int main() { osgViewer::Viewer viewer; viewer.addEventHandler(new ChangeWindow); osg::Group *pGroup = new osg::Group; osg::MatrixTransform* mt = new osg::MatrixTransform; osg::Node*glider = osgDB::readNodeFile("glider.osg"); mt->addChild(glider); osg::Vec3 ptS = osg::Vec3(0,0,0); osg::Vec3 ptE = osg::Vec3(-1000, 0, 0); osg::AnimationPath* path = createAnimationPath(ptS, ptE, 0, 1000); osg::NodeCallback* nc = 0; nc = new osg::AnimationPathCallback(path); osgGA::AnimationPathManipulator *pAn = new osgGA::AnimationPathManipulator(path); pGroup->addChild(mt); pGroup->addChild(osgDB::readNodeFile("cow.osg")); viewer.setCameraManipulator(pAn); viewer.setSceneData(pGroup); viewer.run(); return 0; }
相关文章推荐
- 安卓关机重启
- Linux下OpenSSL 安装图文详解
- 【IOCP】 IOCP模型属于一种通讯模型- 较难
- Ubuntu下交叉编译zlib,libpng,freetype
- 为什么使用 Redis及其产品定位
- 深入C++之C++模板类别
- MySQL本地可以连接,远程连接不上的解决
- HDOJ 题目1520 Anniversary party(树形dp)
- 工作篇-电商项目需求总结下
- java 同步 Synchonized 锁 ReentrantLock 原理 源码
- 怎么样excel其产生的条形码(10分钟的时间excel)从而出现了条形码
- vs2015全新nuget使用全析
- 30个值得收藏的CSS代码片段
- 2015 Multi-University Training Contest 1 - 10010 Y sequence
- HDU 月之数
- git学习笔记
- 建设局安全施工监控指挥系统
- Android网络应用之Socket(一)
- "阿里巴巴分布式服务框架 Dubbo
- 基于Hama并联平台Finding a Maximal Independent Set 设计与实现算法