查看: 1151|回复: 1

《三维渲染引擎设计和实践》中9.2.4例子

[复制链接]

该用户从未签到

发表于 2011-3-28 23:11:23 | 显示全部楼层 |阅读模式
本帖最后由 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版)请赐教,谢谢

该用户从未签到

发表于 2011-3-29 08:41:50 | 显示全部楼层
这个例子已经过时了,您的更改本身不会起到作用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表