|
我从3DsMax里面导出一个简单的长方体模型,其中心点不在原点,加入osg程序中,用AnimationPath建立动画,为了达到绕其自身中心点z轴转动的目的,有代码如下:
osg::AnimationPath* createAnimationPath(osg::Vec3& center,float radius,double looptime)
{
osg::AnimationPath* animationPath = new osg::AnimationPath;
animationPath->setLoopMode(osg::AnimationPath:OOP);
int numSamples = 60;
float yaw = 0.0f;
float yaw_delta = 2.0f*osg:I/((float)numSamples-1.0f);
double time=0.0f;
double time_delta = looptime/(double)numSamples;
osg::Vec3 oriPt(0,0,0);
for(int i=0;i<numSamples;++i)
{
osg::Matrix m1,m2,m3;
m1.makeTranslate(center*-1.0);
m2.makeRotate(yaw,osg::Vec3(0,0,1));
m3.makeTranslate(center);
osg::Vec3 position =oriPt*(m1*m2*m3);
osg:uat rotation(osg::Quat(yaw,osg::Vec3(0,0,1)));
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
yaw += yaw_delta;
time += time_delta;
}
return animationPath;
}
问题:上述代码能达到中心坐标不在原点的长方体绕其自身中心点z轴转动的目的,但却伴随着明显的前后抖动。如果把numSamples增大,抖动就不很明显了。这是怎么回事呢,请教大家。 |
|