OSG 路径动画学习
1、动画的实现方法:
要点1)、通过设置回调函数使得节点按路径移动。这个路径回调只能是添加到osg::PositionAttitudeTransform(位置变换节点)或者osg::MatrixTransform(矩阵变换节点)等节点上面才会有效,因为路径动画的实现原理就是改变节点的位置和旋转角度。
要点2)、动画的实体节点作为子节点添加到添加了路径动画回调的那个节点上面。
给节点添加回调函数
// 位置节点,用来添加动画路径(用一个旋转节点也行)osg::ref_ptr<osg::PositionAttitudeTransform> pat = new osg::PositionAttitudeTransform();//创建路径osg::ref_ptr<osg::AnimationPath> animationPath = new osg::AnimationPath();animationPath = createAnimationPath(ptStart, ptEnd, timeRange.GetStartTime(), timeRange.GetEndTime()) ;// 创建一个路径//设置更新回调pat->setUpdateCallback(new osg::AnimationPathCallback(animationPath.get(),0.0f,1.0f));
我们在来看看AnimationPathCallback::update函数里面做了些什么
bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& controlPoint) const// 根据时间计算出该时间对应的位置和旋转量
{if (_timeControlPointMap.empty()) return false;switch(_loopMode){case(SWING):{double modulated_time = (time - getFirstTime())/(getPeriod()*2.0);double fraction_part = modulated_time - floor(modulated_time);if (fraction_part>0.5) fraction_part = 1.0-fraction_part;time = getFirstTime()+(fraction_part*2.0) * getPeriod();break;}case(LOOP):{double modulated_time = (time - getFirstTime())/getPeriod();double fraction_part = modulated_time - floor(modulated_time);time = getFirstTime()+fraction_part * getPeriod();break;}case(NO_LOOPING):// no need to modulate the time.break;}TimeControlPointMap::const_iterator second = _timeControlPointMap.lower_bound(time);if (second==_timeControlPointMap.begin()){controlPoint = second->second;}else if (second!=_timeControlPointMap.end()){TimeControlPointMap::const_iterator first = second;--first;// we have both a lower bound and the next item.// delta_time = second.time - first.timedouble delta_time = second->first - first->first;if (delta_time==0.0)controlPoint = first->second;else{controlPoint.interpolate((time - first->first)/delta_time,first->second,second->second);}}else // (second==_timeControlPointMap.end()){controlPoint = _timeControlPointMap.rbegin()->second;}return true;
}
double AnimationPathCallback::getAnimationTime() const
{return ((_latestTime-_firstTime)-_timeOffset)*_timeMultiplier;// 获得对应时间
}
void AnimationPathCallback::update(osg::Node& node)
{AnimationPath::ControlPoint cp;if (_animationPath->getInterpolatedControlPoint(getAnimationTime(),cp)){AnimationPathCallbackVisitor apcv(cp,_pivotPoint,_useInverseMatrix);node.accept(apcv);}
}
其它AnimationPathCallback相关具体代码参考osg源代码文件
反正就是在某个时间会更新它的_latestTime,然后调用update这个就获得这个时间的位置和旋转量,然后将其设置到对应节点上。
下面给出我写的直线路径的计算函数(起始时间在起点,到终止时间移动到终点)
//创建路径
osg::ref_ptr<osg::AnimationPath> createAnimationPath(osg::Vec3& ptStart,osg::Vec3 &ptEnd,float timeBegin, float timeEnd)
{//创建一个Path对象osg::ref_ptr<osg::AnimationPath> animationPath = new osg::AnimationPath() ;//设置动画模式为循环(LOOP)(LOOP:循环,SWING:单摆,NO_LOOPING:不循环)animationPath->setLoopMode(osg::AnimationPath::NO_LOOPING) ;//插入Path,把关键点与时间压入形成PathanimationPath->insert(timeBegin,osg::AnimationPath::ControlPoint(ptStart));animationPath->insert(timeEnd,osg::AnimationPath::ControlPoint(ptEnd));//返回Pathreturn animationPath.get() ;
}
这个是最简单的路径,没有旋转,而且只有两个路径数据值。
OSG 路径动画学习相关推荐
- android路径动画学习笔记
先上效果图: 效果图由于是用studio录制视频,然后转码gif,再经过photoshop裁剪,有些颜色已经丢失,也没有实际效果那么流畅了. 这种线条动画,完全由android 原生的SDK就可以做出 ...
- Flash动画学习指南七:运动路径
转自:http://bbs.9ria.com/thread-76164-1-1.html 本帖最后由 chocoZero 于 2011-3-16 14:18 编辑 准备知识:Flash工作空间的基本知 ...
- OSG 飞机路径动画控制
OSG 飞机路径动画控制 注:摘自<三维渲染引擎编程指南> 本文实现一个飞机,在地图上空盘旋,读者可以根据自己需要进行更改: 代码如下: //2017. 8 .29 #include &l ...
- geopandas学习(八)Python+Kepler.gl制作路径动画
geopandas学习(八)Python+Kepler.gl制作路径动画 1.简介 Kepler.gl相信很多人都听说过,作为Uber几年前开源的交互式地理信息可视化工具,kepler.gl依托Web ...
- dotween路径移动_Unity---DOTween插件学习(3)---获取数据、协程、路径动画
[Toc] 本文及系列参考于Andy老师的DOTween系列 欢迎大家关注**Andy老师** 10.获取数据 类方法 返回所有暂停的动画,没有则返回null var list = DOTween.P ...
- python炫酷动画源代码_(数据科学学习手札85)Python+Kepler.gl轻松制作酷炫路径动画...
1 简介 Kepler.gl相信很多人都听说过,作为Uber几年前开源的交互式地理信息可视化工具,kepler.gl依托WebGL强大的图形渲染能力,可以在浏览器端以多种形式轻松展示大规模数据集. 图 ...
- 【Python应用】Python+Kepler.gl轻松制作酷炫路径动画
文章来源于Python大数据分析,作者费弗里 本文示例代码.数据已上传至Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 ...
- Cinemachine教程 | Unity中如何制作路径动画?
摘要:在Unity中制作路径动画是有挺多方式的,基于Cinemachine的Dolly Path是一个简单便捷的方法,咱们来快速的学习一下吧! 洪流学堂,让你快人几步.你好,我是跟着大智(VX: zh ...
- OSG路径漫游实现与应用
路径漫游简介 路径漫游在OSG中即为视点或者模型按照我们自己设定的路径进行漫游的一种方法,原本在OsgViewer中就有,在第一次按键盘小写"z"开始记录动画路径,大写" ...
最新文章
- spring 声明式事务
- 编译可在Android上运行的qemu user mode
- android 无线调试
- 创业互联网公司如何搭建自己的技术框架
- fillstyle属性_HTML canvas
- Kafka学习 之 第一个例子(一)
- pcl里面使用KdTree来搜索
- linux 恢复操作系统,如何恢复Linux操作系统的GRUB引导程?
- SQLite | Where 子句
- 王自如、罗永浩将一起出镜直播带货?罗永浩亲自回应
- JavaScript 工具库:Cloudgamer JavaScript Library v0.1 发布
- 智能优化算法之模拟退火(Simulated Annealing,SA)-附源码
- 计算机设置开机密码时间屏保,电脑屏幕保护密码设置方法
- LCD3D打印机和DLP3D打印技术的区别详解
- 9.Vue中mounted的简单理解
- 如何在outlook里面把收件箱分组,以便快速的查看最重要的email。
- 为什么华为 200 万招聘 AI 博士,马斯克却推出脑机接口对抗 AI?
- c语言 rsa算法 分段,python3 实现RSA算法分段加密解密
- 机器学习之离散值处理
- mediapipe 实现AI 虚拟鼠标
热门文章
- python 三列求correlation_Python新手写爬虫全过程记录分析
- matlab 改变信号频率,使用插值和重定位来改变八度和matlab中的信号频率
- SpringCloud微服务项目启动报错解决方案
- 怎么用keil5实现MSP432E401Y点灯
- 音画欣赏 | 荷塘月色
- PTA 7-234 荷塘月色
- Gen2-UHF-RFID-Reader学习(七)reader.py
- mysql decimal 实现_mysql中decimal的使用
- 阿黛尔 优秀的两首音乐作品(live)
- visual studio如何不使用system(“pause”)仍可暂停