|
本帖最后由 osg小菜 于 2013-9-23 13:57 编辑
写了一个动画回调,希望根据时间变化调用不同的动画路径,可是运行的时候发现“参考时间与当前时间差”只是在刚运行的时候有值,之后不变,对“nv->getFrameStamp()->getReferenceTime()”这个也不是太了解,版主教我啊??
class AnimateCallback : public osg::NodeCallback
{
public:
AnimateCallback(){ }
virtual void operator() (osg::Node* node, osg::NodeVisitor* nv)
{
//验证得到的结点是不是
osg:ositionAttitudeTransform* pat = dynamic_cast<osg::PositionAttitudeTransform*> (node);
//如果是的
if (nv && nv->getFrameStamp())
{
//const osg::BoundingSphere& bs2 = m_group->getChild(2)->getBound();
osg::AnimationPath* animation20= CreateAnimationPath20(osg::Vec3(0.0,0.0,0.0),95,5.0);
osg::AnimationPathCallback* apc20 =
new osg::AnimationPathCallback(animation20,45,1.0);
osg::AnimationPath* animation21= CreateAnimationPath20(osg::Vec3(0.0,0.0,0.0),95,5.0);
osg::AnimationPathCallback* apc21 =
new osg::AnimationPathCallback(animation21,45,1.0);
//得到参考时间与当前时间差,
double time = nv->getFrameStamp()->getReferenceTime();
if(time>=0.0 && time <=50.0)
pat->setUpdateCallback(apc20);
else
pat->setUpdateCallback(apc21);
std::cout<<time<<std::endl;
}
traverse(node,nv);
}
protected:
};
osg::ref_ptr<osg::PositionAttitudeTransform> pata20 = new osg::PositionAttitudeTransform();
pata20 ->setUpdateCallback(new AnimateCallback);
pata20->addChild(model);
root->addChild(pata20); ... ...
谢谢! |
|