为了减少每个例子重复添加头文件和静态链接库文件的代码编写工作,编写一个头文件“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为半径。