Learning OSG programing---osgAnimation(1)
- osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime)
- {
- // set up the animation path
- osg::AnimationPath* animationPath = new osg::AnimationPath;
- animationPath->setLoopMode(osg::AnimationPath::LOOP);
- int numSamples = ;
- float yaw = 0.0f;
- float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f);
- float roll = osg::inDegrees(30.0f);
- double time=0.0f;
- double time_delta = looptime/(double)numSamples;
- for(int i=;i<numSamples;++i)
- {
- osg::Vec3 position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f));
- osg::Quat rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0)));
- animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
- yaw += yaw_delta;
- time += time_delta;
- }
- return animationPath;
- }
第一个函数:createAnimationPath,创建仿真路径。接受一个中心点坐标参数,和一个循环时间参数。(猜测后一个参数的作用是确定每次回环持续的秒数。)函数中用到了四元数表达旋转。其构造函数为osg::Quat quat(float radians, const Vec3f& axis),其中radians是旋转弧度, 后面的axis是旋转轴向量。根据其构造函数的含义不难看出,一个四元数表示围绕轴axis旋转radians弧度。其中的旋转分量, x轴是俯仰(pitch), y轴是横滚(roll), z轴是航向角度(yaw)。根据以上知识,不难看出以下这条语句的含义:
- osg::Quat rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0)));
上语句可表达为:先绕y轴旋转roll弧度,再绕z轴旋转逆时针(俯视)(yaw+π/2)弧度。经过这两次旋转,组成rotation变换矩阵。每次循环都更新横滚量yaw和时间。整个循环会使模型旋转一周。
注意第19行代码向模拟路径中添加控制点,函数原型为:
- void osg::AnimationPath::insert( double time,const ControlPoint &controlPoint )
而ControlPoint具有构造函数:
- ControlPoint (const osg::Vec3d &position, const osg::Quat &rotation)
所以第19行代码在向模拟路径中添加元素,控制time时刻模型的位置 position 和姿态 rotation.
第7行中,变量numSamples决定模型在looptime(即旋转一周)内所细分的次数,其值越大,模拟效果越平滑。
第10行中,变量roll被设定为30度,并在此后的程序中不会改变,以使飞机模型始终向运动中心侧倾斜30度。
Learning OSG programing---osgAnimation(1)的更多相关文章
- Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现(转)
Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文, ...
- Deep Learning论文笔记之(八)Deep Learning最新综述
Deep Learning论文笔记之(八)Deep Learning最新综述 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文,但老感觉看完 ...
- Deep Learning论文笔记之(六)Multi-Stage多级架构分析
Deep Learning论文笔记之(六)Multi-Stage多级架构分析 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些 ...
- Learning Cocos2d-x for WP8(2)——深入刨析Hello World
原文:Learning Cocos2d-x for WP8(2)--深入刨析Hello World cocos2d-x框架 在兄弟篇Learning Cocos2d-x for XNA(1)——小窥c ...
- Learning Cocos2d-x for WP8(1)——创建首个项目
原文:Learning Cocos2d-x for WP8(1)--创建首个项目 Cocos2d-x for WP8开发语言是C++,系列文章将参考兄弟篇Learning Cocos2d-x for ...
- Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主
原文:Learning Cocos2d-x for WP8(9)--Sprite到哪,我做主 工程文件TouchesTest.h和TouchesTest.cpp 相关素材文件 事件驱动同样适用于coc ...
- Learning Cocos2d-x for WP8(8)——动作Action
原文:Learning Cocos2d-x for WP8(8)--动作Action 游戏很大程度上是由动作画面支撑起来的. 动作分为两大类:瞬间动作和延时动作. 瞬间动作基本等同于设置节点的属性,延 ...
- Learning Cocos2d-x for WP8(7)——让Sprite动起来
原文:Learning Cocos2d-x for WP8(7)--让Sprite动起来 C#(wp7)兄弟篇Learning Cocos2d-x for XNA(7)——让Sprite动起来 本讲将 ...
- Learning Cocos2d-x for WP8(6)——场景切换和场景过渡效果
原文:Learning Cocos2d-x for WP8(6)--场景切换和场景过渡效果 C#(wp7)兄弟篇 Learning Cocos2d-x for XNA(6)——场景切换和场景过渡效果 ...
- Learning Cocos2d-x for WP8(5)——详解Menu菜单
原文:Learning Cocos2d-x for WP8(5)--详解Menu菜单 C#(wp7)兄弟篇Learning Cocos2d-x for XNA(5)——详解Menu菜单 菜单是游戏必不 ...
随机推荐
- python学习笔记(6)关键字与循环控制
一.变量和类型 1.基本变量类型 (1)整数 (2)浮点数 (3)字符串 (4)布尔值 (5)空值 (6)函数 (7)模块 (8)类型 (9)自定义类型 print(type()) print(typ ...
- Dubbo源码学习总结系列七---注册中心
Dubbo注册中心是框架的核心模块,提供了服务注册发现(包括服务提供者.消费者.路由策略.覆盖规则)的功能,该功能集中体现了服务治理的特性.该模块结合Cluster模块实现了集群服务.Dubbo管理控 ...
- 2018-8-10-C#-TimeSpan-时间计算
title author date CreateTime categories C# TimeSpan 时间计算 lindexi 2018-08-10 19:16:51 +0800 2018-06-1 ...
- Spring Data Elasticsearch 用户指南
https://www.jianshu.com/p/27e1d583aafb 翻译自官方文档英文版,有删减. BioMed Central Development Team version 2.1.3 ...
- 搭建Keepalived+LNMP架构web动态博客 实现高可用与负载均衡
环境准备: 192.168.193.80 node1 192.168.193.81 node2 关闭防火墙 [root@node1 ~]# systemctl stop firewalld #两台都 ...
- maven 提取jar包 依赖及打包排除
<properties> <project.targetDir>D:\jar</project.targetDir> <project.targetServe ...
- redis心得体会
redis简介: 在我们日常的Java Web开发中,无不都是使用数据库来进行数据的存储,由于一般的系统任务中通常不会存在高并发的情况,所以这样看起来并没有什么问题,可是一旦涉及大数据量的需求,比如一 ...
- APP稳定性测试-monkey执行
Monkey命令行可用的全部选项 *示例 : adb shell monkey -p cn.lejiayuan.alpha --pct-touch 30 --pct-motion 15 --pct-t ...
- 【leetcode】1073. Adding Two Negabinary Numbers
题目如下: Given two numbers arr1 and arr2 in base -2, return the result of adding them together. Each nu ...
- kwargs - Key words arguments in python function
This is a tutorial of how to use *args and **kwargs For defining the default value of arguments that ...