|
学习《OpenSceneGraph三维渲染引擎设计与实践》中骨骼动画一节中的示例代码,能够生成模型,但是没有运动效果,不知道为什么,本人新手,请多指教,谢谢,相关代码如下。
osgAnimation::Bone* createBone(const char* name,const osg::Vec3&trans)
{
......
}
osgAnimation::Channel* createChannel(const char* name,float rad)
{
osg::ref_ptr<osgAnimation:uatSphericalLinearChannel> channel
=new osgAnimation::QuatSphericalLinearChannel;
channel->setName("quaternion");
channel->setTargetName(name);
osgAnimation::QuatKeyframeContainer* ks =
channel->getOrCreateSampler()->getOrCreateKeyframeContainer();
ks->push_back(
osgAnimation::QuatKeyframe(0.0,osg::Quat(0.0,osg::Y_AXIS)));
ks->push_back(
osgAnimation::QuatKeyframe(8.0,osg::Quat(rad,osg::Y_AXIS)));
return channel.release();
}
int main(int argc,char** argv)
{
osgAnimation::Bone* bone0 = createBone("bone0",osg::Vec3(0.0,0.0,0.0));
osgAnimation::Bone* bone1 = createBone("bone1",osg::Vec3(1.0,0.0,0.0));
osgAnimation::Bone* bone2 = createBone("bone2",osg::Vec3(1.0,1.0,0.0));
osg::ref_ptr<osgAnimation::Skeleton> skelroot =
new osgAnimation::Skeleton;
skelroot->setDefaultUpdateCallback();
skelroot->addChild(bone0);
bone0->addChild(bone1);
bone1->addChild(bone2);
osg::ref_ptr<osgAnimation::Animation> anim = //创建动画对象
new osgAnimation::Animation;
anim->setPlayMode(osgAnimation::Animation:PONG);
anim->addChannel(createChannel("bone1",osg::PI_2));
anim->addChannel(createChannel("bone2",osg::PI_2));
osg::ref_ptr<osgAnimation::BasicAnimationManager> manager=
new osgAnimation::BasicAnimationManager;
manager->registerAnimation(anim.get());
manager->playAnimation(anim.get());
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(skelroot.get());
root->setUpdateCallback(manager.get()); |
|