在osg中添加相机动画路径请参考:http://www.cnblogs.com/lyggqm/p/8075277.html

这里的代码是在osgearth中添加相机动画路径漫游器:

#include <osg/Image>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/Registry>
#include <osgEarthSymbology/Geometry>
#include <osgEarthSymbology/GeometryRasterizer>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarth/ImageToHeightFieldConverter>
#include <osgEarth/ImageUtils>
#include <osgEarth/FileUtils>
#include <osgEarth/Registry>
#include <osgEarth/MapFrame>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile> #include <osgEarthUtil/ExampleResources>
#include <math.h> #include <osgGA/NodeTrackerManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
using namespace osgEarth;
using namespace osgEarth::Util;
using namespace osgEarth::Symbology; int main(int argc, char** argv)
{
//正常的.earth文件加载
osg::ArgumentParser arguments(&argc, argv);
osgViewer::Viewer viewer(arguments);
MapNode* s_mapNode = 0L;
osg::Node* earthFile = MapNodeHelper().load(arguments, &viewer);
if (earthFile)
s_mapNode = MapNode::get(earthFile);
if (!s_mapNode)
{
OE_WARN << "Unable to load earth file." << std::endl;
return -;
}
osg::Group* root = new osg::Group();
root->addChild(earthFile);
viewer.setSceneData(root); //模型漫游器
osgGA::NodeTrackerManipulator* nodeTrack = new osgGA::NodeTrackerManipulator();
nodeTrack->setTrackNode(root); /*************************************动画漫游器**下*********************************/
GeoPoint gPoint1(s_mapNode->getMap()->getSRS(), , , );
osg::Matrix gMatrix1;
gPoint1.createLocalToWorld(gMatrix1);//获取当前地球上的正确姿态
//由于相机,自身向下看,所以在当前姿态基础上抬起60度,注意是前乘!
gMatrix1.preMultRotate(osg::Quat(osg::DegreesToRadians(60.0), osg::X_AXIS));
osg::Quat q1; gMatrix1.get(q1);//获取当前矩阵姿态
osg::Vec3d vPos1 = gMatrix1.getTrans();//获取当前矩阵位置 GeoPoint gPoint2(s_mapNode->getMap()->getSRS(), 32.01, 118.01, );
osg::Matrix gMatrix2;
gPoint2.createLocalToWorld(gMatrix2);
gMatrix2.preMultRotate(osg::Quat(osg::DegreesToRadians(60.0), osg::X_AXIS));
osg::Quat q2;
gMatrix2.get(q2);
osg::Vec3d vPos2 = gMatrix2.getTrans(); GeoPoint gPoint3(s_mapNode->getMap()->getSRS(), 32.02, 118.02, );
osg::Matrix gMatrix3;
gPoint3.createLocalToWorld(gMatrix3);
osg::Quat q3;
gMatrix3.get(q3);
osg::Vec3d vPos3 = gMatrix3.getTrans();
//获取相机之后再顺旋转,其实是错误的姿态
osg::Quat qbuf(osg::DegreesToRadians(60.0), osg::X_AXIS);
q3 *= qbuf; //使用动画漫游器
osgGA::AnimationPathManipulator *animationPathMp = new osgGA::AnimationPathManipulator();
//给动画漫游器添加关键帧
osg::AnimationPath* _animationPath = new osg::AnimationPath;
_animationPath->insert(0.0, osg::AnimationPath::ControlPoint(vPos1, q1));//姿态正确
_animationPath->insert(3.0, osg::AnimationPath::ControlPoint(vPos2, q2));//姿态正确
_animationPath->insert(6.0, osg::AnimationPath::ControlPoint(vPos3, q3));//姿态错误!
_animationPath->setLoopMode(osg::AnimationPath::SWING);//设置路径是回摆的
animationPathMp->setAnimationPath(_animationPath);
/*************************************动画漫游器**上*********************************/ //这里添加三个漫游器,使用一个控制漫游器选择,按键盘‘3’就切换到路径动画漫游器了
osgGA::KeySwitchMatrixManipulator* keyPtr = new osgGA::KeySwitchMatrixManipulator();
keyPtr->addMatrixManipulator('', "earthMan", new EarthManipulator());
keyPtr->addMatrixManipulator('', "trakerMan", nodeTrack);
keyPtr->addMatrixManipulator('', "animationPathMan", animationPathMp);
viewer.setCameraManipulator(keyPtr); return viewer.run();
}

有几点要注意:

1.这个dome在vs运行时,需要添加外部earth文件参数:

红色部分填写适合当前earth版本的‘.earth’文件

2.添加的其实是一个漫游器,基于路径点的相机漫游器

3.添加的路径点有两个姿态的变幻,展示一个正确相机姿态调整方式,一个错误的:

正确的:

错误的:

[原][osgEarth]在osgearth中添加相机路径动画的更多相关文章

  1. PowerPoint 2013中创建自定义路径动画的方法

    1.在幻灯片中选择对象,在“动画”选项卡的“高级动画”组中单击“添加动画”按钮,在打开的下拉列表中选择“自定义路径”选项,如图1所示. 图1 选择“自定义路径”选项 2.此时鼠标指针变为十字形,在幻灯 ...

  2. (原)visual studio 2015中添加dll路径

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9922033.html 使用vs2015调用opencv 3.4时,除了需要在“VC++目录”中”包含 ...

  3. HTML网页中添加音频视频动画...(转)

    在网页中适当嵌入音频和视频能够充分显示网页的多媒体特性,特别是随着宽带网的普及,使得网络广播和网络视频成为现实,网页音频和视频的重要性也日益突显.具体来说,网页音频和视频的嵌入方法主要有三种: 一.b ...

  4. 有效解决js中添加border后动画bug问题

    做了个demo发现如果一个div不加border属性,用对象的offsetWidth属性来控制width没问题,但是如果一旦加了border属性,问题就来了. 其实offsetWidth属性获取的的是 ...

  5. (原)netbeans中添加anaconda3安装的opencv

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9974310.html 新装了ubuntu16.04后,直接安装了anaconda3,调试c++程序时 ...

  6. Matlab中添加路径与去除路径

    今天在使用Matlab调用内部的PCA函数的时候,报错: 错误使用 pca输入参数太多. 如下图所示: 网上查找原因之后发现是因为我之前下载过开源的工具包toolbox,并且将它的路径add到了Mat ...

  7. linux 中添加自己的库路径的方法 cannot open shared object file: No such file or directory

    本文转自:http://blog.csdn.net/maotianwang/article/details/44619197 库文档在连接(静态库和共享库)和运行(仅限于使用共享库的程式)时被使用,其 ...

  8. VS中添加第三方库及相对路径设置

    原文 VS中添加第三方库及相对路径设置 对于一些第三方的SDK,一般会包含头文件(*.h),静态库文件(*.lib)和动态库文件(*.dll). 1.  文件位置:为了提高程序的可移植性,将第三库放在 ...

  9. Eclipse中如何添加相对路径的外部jar包

    在eclipse中进行java编程的时候,常常需要引用外部jar包.而采用相对路径引用jar包可以大大方便java工程的拷贝,这样使得java工程从一个路径转移到另一个路径时不用大费周章的修改外包ja ...

随机推荐

  1. Eclipse导入MyEclipse创建的WEB项目无法识别的解决方案

    Eclipse导入MyEclipse创建的WEB项目无法识别的解决方案

  2. Kattis之旅——Fractional Lotion

    Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...

  3. redis 入门笔记

    http://www.cnblogs.com/xinysu/p/7366142.html

  4. xtrabackup 对pxc节点进行备份恢复

    xtrabackup 对pxc节点进行备份恢复 全量备份一个节点的数据,当节点挂掉时,使用备份恢复到最近状态,再启动节点加入集群. 备份 xtrabackup 命令小解释: --defaults-fi ...

  5. Mysql 利用拷贝data目录文件的方式迁移mysql数据库

    Mysql 利用拷贝data目录文件的方式迁移mysql数据库 步骤如下: 1.首先要确定data目录 这个问题困扰了我很久,因为网上的帖子大部分只是说拷贝mysql数据库目录下的data文件夹中的数 ...

  6. 15:element/Vue Admin

    1.1 简介 1.Vue Admin 简介 1. Vue Admin 是一个基于 Vue 2.0 & Bulma 0.3 的后台管理面板(管理系统),相当于是 Vue 版本的 Bootstra ...

  7. linux 关于redis-trib.rb构建redis集群

    之前搭建集群漏下的坑, 今次再搭一次. 环境 ruby环境 yum install ruby rubygems -y redis的gem环境 gem install redis-3.2.2.gem 部 ...

  8. bzoj 2091 The Minima Game - 动态规划 - 博弈论

    题目传送门 需要验证权限的传送门 题目大意 Alice和Bob轮流取$n$个正整数,Alice先进行操作.每次每人可以取任意多的数,得分是这一次取的所有数中的最小值.Alice和Bob都足够聪明,他们 ...

  9. Codeforces 581F Zublicanes and Mumocrates - 树形动态规划

    It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...

  10. 【安装】Matlab7.0简介及安装

    一.简介 Matlab下载官方版是美国MathWorks公司出品的商业数学软件,Matlab7.0下载官方版用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MAT ...