查看: 1440|回复: 1

bone节点如何实现动画控制

[复制链接]

该用户从未签到

发表于 2011-10-13 09:46:36 | 显示全部楼层 |阅读模式
大家帮忙看看下面这段代码,是哪里出了问题,里面的模型不能实现动画。


  1. [code]int _tmain(int argc, _TCHAR* argv[])
  2. {
  3. osg::ref_ptr<osg::Group> root;
  4. root= new osg::Group;

  5. osg::ref_ptr<osgAnimation::Bone> bone =new osgAnimation::Bone;
  6. bone->setMatrixInSkeletonSpace(osg::Matrix::translate(1.0,0.0,0.0));
  7. bone->setName("bone");
  8. bone->setDefaultUpdateCallback("bone");

  9. osg::ref_ptr<osg::Box>box=new osg::Box((osg::Vec3(1.0,0.0,0.0))*0.5,1,0.2,0.2);
  10. osg::ref_ptr<osg::Geode> geode=new osg::Geode;
  11. geode->addDrawable(new osg::ShapeDrawable(box.get()));
  12. bone->addChild(geode.get());

  13. osg::ref_ptr<osgAnimation::Skeleton> skelroot= new osgAnimation::Skeleton();
  14. root->addChild(skelroot.get());
  15. skelroot->addChild(bone);

  16. osgAnimation::Animation* anim = new osgAnimation::Animation;
  17. anim->setPlayMode(osgAnimation::Animation::LOOP);
  18. {
  19. osgAnimation::QuatKeyframeContainer* keys0 = new osgAnimation::QuatKeyframeContainer;
  20. osg::Quat rotate;
  21. rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1));
  22. keys0->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1)));
  23. keys0->push_back(osgAnimation::QuatKeyframe(3,rotate));
  24. keys0->push_back(osgAnimation::QuatKeyframe(6,rotate));
  25. osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler;
  26. sampler->setKeyframeContainer(keys0);
  27. osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler);
  28. channel->setName("quaternion");
  29. channel->setTargetName("bone");
  30. anim->addChannel(channel);
  31. };
  32. osg::ref_ptr<osgAnimation::BasicAnimationManager>manager=new osgAnimation::BasicAnimationManager;
  33. manager->registerAnimation(anim);
  34. manager->buildTargetReference();
  35. manager->playAnimation(anim);
  36. root->setUpdateCallback(manager.get());
  37. osgViewer::Viewer viewer;
  38. viewer.setSceneData(root.get());
  39. return viewer.run();
  40. }
复制代码

[/code]

该用户从未签到

发表于 2011-10-18 09:56:04 | 显示全部楼层
我没有细看,不过粗看的话,没有发现您使用StackedTransform和UpdateBone。请参看osganimationskeleton
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

联系我们

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