为了减少每个例子重复添加头文件和静态链接库文件的代码编写工作,编写一个头文件“libs.h”,该文件直接放入到OSG的include\osg目录中。
#include <osg/libs.h>
//创建动画路径,如下图所示:
osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime)
{
osg::AnimationPath* animationPath = new osg::AnimationPath;
animationPath->setLoopMode(osg::AnimationPath::LOOP);
int numSamples = 40;
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=0;i<numSamples;++i)
{
osg::Vec3 position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f));//平移到圆上,center中心点,yaw为旋转角度值,radius为半径。
//围绕Y轴旋转30度,实现右倾滚转

本文档通过E3_OSG_animate.cpp代码示例,详细讲解了如何利用OpenSceneGraph(osg)库中的osganimate模块,创建一个飞机在三维空间中盘旋的动画效果。首先介绍了一个通用头文件'libs.h',接着展示了创建动画路径的函数,包括设置循环模式和路径点。然后,代码构建了一个黑白格子地面作为背景,并创建了两个飞行模型(glider和cessna),通过调整矩阵变换实现飞机的动画。最后,将所有元素组合成一个场景并展示。
&spm=1001.2101.3001.5002&articleId=44499327&d=1&t=3&u=f5257553a25240428c3aff807d135f42)
4971

被折叠的 条评论
为什么被折叠?



