|
在编写动画模块的过程中..能编译通过..但是运行总会出现以下问题..
请问下高人..究竟是库丢失了..抑或是系统问题..或者有其他答案.?
编写环境.OSG2.9.9 OS:win7 MFC库已更新到最新版
//代码
#include <windows.h>
#include <osgGA/TrackballManipulator>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Group>
#include <osg/ShapeDrawable>
#include <osgAnimation/Bone>
#include <osgAnimation/Skeleton>
#include <osgAnimation/BasicAnimationManager>
#include <osgViewer/Viewer>
#include <osgUtil/Optimizer>
#include <iostream>
osgAnimation::Bone* createBone(const char* name,const osg::Vec3& trans)
{
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone;
bone->setInvBindMatrixInSkeletonSpace(osg::Matrix::translate(trans));
bone->setName(name);
bone->setDefaultUpdateCallback();
osg::ref_ptr<osg::Box> box = new osg::Box(trans*0.5,trans.length(),0.2,0.2);
osg:uat quat;
quat.makeRotate(osg::Vec3(1.0,0.0,0.0),trans);
box->setRotation(quat);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(box.get()));
bone->addChild(geode.get());
return bone.release();
}
osgAnimation::Channel* createChannel(const char* name,float rad)
{
osg::ref_ptr<osgAnimation::QuatSphericalLinearChannel> 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(0.0,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,0.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());
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
return viewer.run();
} |
|