|
大家帮忙看看下面这段代码,是哪里出了问题,里面的模型不能实现动画。
-
-
- [code]int _tmain(int argc, _TCHAR* argv[])
- {
- osg::ref_ptr<osg::Group> root;
- root= new osg::Group;
- osg::ref_ptr<osgAnimation::Bone> bone =new osgAnimation::Bone;
- bone->setMatrixInSkeletonSpace(osg::Matrix::translate(1.0,0.0,0.0));
- bone->setName("bone");
- bone->setDefaultUpdateCallback("bone");
- osg::ref_ptr<osg::Box>box=new osg::Box((osg::Vec3(1.0,0.0,0.0))*0.5,1,0.2,0.2);
- osg::ref_ptr<osg::Geode> geode=new osg::Geode;
- geode->addDrawable(new osg::ShapeDrawable(box.get()));
- bone->addChild(geode.get());
- osg::ref_ptr<osgAnimation::Skeleton> skelroot= new osgAnimation::Skeleton();
- root->addChild(skelroot.get());
- skelroot->addChild(bone);
- osgAnimation::Animation* anim = new osgAnimation::Animation;
- anim->setPlayMode(osgAnimation::Animation::LOOP);
- {
- osgAnimation::QuatKeyframeContainer* keys0 = new osgAnimation::QuatKeyframeContainer;
- osg::Quat rotate;
- rotate.makeRotate(osg::PI_2, osg::Vec3(0,0,1));
- keys0->push_back(osgAnimation::QuatKeyframe(0,osg::Quat(0,0,0,1)));
- keys0->push_back(osgAnimation::QuatKeyframe(3,rotate));
- keys0->push_back(osgAnimation::QuatKeyframe(6,rotate));
- osgAnimation::QuatSphericalLinearSampler* sampler = new osgAnimation::QuatSphericalLinearSampler;
- sampler->setKeyframeContainer(keys0);
- osgAnimation::QuatSphericalLinearChannel* channel = new osgAnimation::QuatSphericalLinearChannel(sampler);
- channel->setName("quaternion");
- channel->setTargetName("bone");
- anim->addChannel(channel);
- };
- osg::ref_ptr<osgAnimation::BasicAnimationManager>manager=new osgAnimation::BasicAnimationManager;
- manager->registerAnimation(anim);
- manager->buildTargetReference();
- manager->playAnimation(anim);
- root->setUpdateCallback(manager.get());
- osgViewer::Viewer viewer;
- viewer.setSceneData(root.get());
- return viewer.run();
- }
复制代码
[/code] |
|