|
本帖最后由 heye 于 2011-3-28 23:13 编辑
void createKeyframes1(osgAnimation::Vec3KeyframeContainer* ks)
{
ks->push_back(osgAnimation::Vec3Keyframe(0,osg::Vec3(0.0,0.0,0.0)));
ks->push_back(osgAnimation::Vec3Keyframe(10,osg::Vec3(10.0,0.0,-10.0)));
ks->push_back(osgAnimation::Vec3Keyframe(20,osg::Vec3(0.0,0.0,0.0)));
}
void createKeyframes2(osgAnimation::Vec3KeyframeContainer* ks)
{
ks->push_back(osgAnimation::Vec3Keyframe(0,osg::Vec3(0.0,0.0,0.0)));
ks->push_back(osgAnimation::Vec3Keyframe(10,osg::Vec3(10.0,0.0,100.0)));
ks->push_back(osgAnimation::Vec3Keyframe(15,osg::Vec3(10.0,0.0,80.0)));
ks->push_back(osgAnimation::Vec3Keyframe(200,osg::Vec3(0.0,0.0,0.0)));
}
int main()
{
osg::Node* model;
model=osgDB::readNodeFile("glider.osg");
osg::ref_ptr<osgAnimation::Vec3LinearChannel>ch1=
new osgAnimation::Vec3LinearChannel();
ch1->setName("position");
ch1->setTargetName("PathCallback");
createKeyframes1(ch1->getOrCreateSampler()->getOrCreateKeyframeContainer());
osg::ref_ptr<osgAnimation::Animation>anim1=
new osgAnimation::Animation;
anim1->setPlaymode(osgAnimation::Animation::LOOP);
anim1->addChannel(ch1.get());
osg::ref_ptr<osgAnimation::Vec3LinearChannel>ch2=
new osgAnimation::Vec3LinearChannel;
ch2->setName("position");
ch2->setTargetName("PathCallback");
createKeyframes2(ch2->getOrCreateSampler()->getOrCreateKeyframeContainer());
osg::ref_ptr<osgAnimation::Animation>anim2=
new osgAnimation::Animation();
anim2->setPlaymode(osgAnimation::Animation::LOOP);
anim2->addChannel(ch2.get());
osg::ref_ptr<osg::MatrixTransform>animRoot=
new osg::MatrixTransform();
animRoot->addChild(model);
animRoot->setDataVariance(osg::Object::DYNAMIC);
animRoot->setUpdateCallback(new osgAnimation::UpdateMatrixTransform("PathCallback"));//这句中osgAnimation::UpdateMatrixTransform("PathCallback"),原//来为osgAnimation::UpdateTransform("PathCallback")
osg::ref_ptr<osgAnimation::BasicAnimationManager>mng=
new osgAnimation::BasicAnimationManager();
mng->registerAnimation(anim1.get());
mng->registerAnimation(anim2.get());
osg::ref_ptr<osg::Group> root=new osg::Group;
root->addChild(animRoot.get());
root->setUpdateCallback(mng.get());
mng->playAnimation(anim1.get(),0,0.3);
mng->playAnimation(anim2.get(),0,0.7);
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
viewer.run();
return 0;
}
以上是全部代码
运行可以通过,但glider没有运动。(osg 2.8.3版)请赐教,谢谢 |
|