|
本帖最后由 wwwanghao 于 2014-7-2 10:13 编辑
采用下面的方式创建一条路径,用于控制物体的运动,但是实际运行结果并不是想象的那样,都说路径是由时间、位置和姿态角控制,
path->insert(time,osg::AnimationPath::ControlPoint(postion,rotation));
那么我的疑问有:
1.这里的time,是相对于什么的时间,是实际的时间,比如单位是秒,还是什么时间?
2.position固定以后,按理说物体的运动路径就固定了,改变yaw,roll,pitch只会导致物体的姿态发生变化,为什么我改变姿态后发现运动路径都会变?
3.这里的姿态应该指的是物体自身坐标系下的参数吧。
- ref_ptr<osg::AnimationPath> createAnimatePath(Vec3 & center,float radius,float looptime)
- {
- ref_ptr<osg::AnimationPath> path= new osg::AnimationPath;
- path->setLoopMode(osg::AnimationPath::LOOP);
- //number of key points
- int numPoint=60;
- //rotate angle
- float yaw =0.f;
- //step angle
- float yaw_delta=2*osg::PI/(numPoint-1);
- //倾斜角//
- float roll=osg::inDegrees(45.f);
- //the total run time
- float time =0.f;
- //delta time
- float time_delta=looptime/(numPoint);
- for (int i=0;i<numPoint;i++)
- {
- Vec3 postion(center + Vec3(cosf(yaw)*radius,sinf(yaw)*radius,0));
- // key point angle
- //osg::Quat rotation( osg::Quat(roll,osg::Vec3(0,1,0)) * osg::Quat( -yaw+osg::inDegrees(90.f),Vec3(0,0,1) ) );
- osg::Quat rotation( yaw,Vec3(0,1,0));
- path->insert(time,osg::AnimationPath::ControlPoint(postion,rotation));
- time += time_delta;
- yaw += yaw_delta;
- }
- std::ofstream fout("path100.path");
- path->write(fout);
- fout.close();
- return path;
- }
复制代码
|
-
osg::Quat rotation( yaw,Vec3(0,0,1));物体在平面上方
-
osg::Quat rotation( yaw,Vec3(0,1,0));物体运动到平面下面去了
|