|
#include <osg/ShapeDrawable>
#include <osgAnimation/Bone>
#include <osgAnimation/Skeleton>
#include <osgAnimation/BasicAnimationManager>
#include <osgViewer/Viewer>
#include<osg/Node>
#include<osgDB/ReadFile>
osgAnimation::Bone* createBone( const char* name, const osg::Vec3& trans )
{
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone;
bone->setBindMatrixInBoneSpace( osg::Matrix::translate(trans) );
bone->setName( name );
bone->setDefaultUpdateCallback();
osg::ref_ptr<osg::Node> node0=osgDB::readNodeFile("che1.ive");
bone->addChild( node0.get() );
return bone.release();
}
osgAnimation::Bone* createBone1( const char* name, const osg::Vec3& trans )
{
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone;
bone->setBindMatrixInBoneSpace( osg::Matrix::translate(trans) );
bone->setName( name );
bone->setDefaultUpdateCallback();
osg::ref_ptr<osg::Node> node0=osgDB::readNodeFile("danjia1.ive");
bone->addChild( node0.get() );
return bone.release();
}
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* keyframes = channel->getOrCreateSampler()->getOrCreateKeyframeContainer();
keyframes->push_back( osgAnimation::QuatKeyframe(0.0, osg::Quat(0.0,osg::X_AXIS)) );
keyframes->push_back( osgAnimation::QuatKeyframe(8.0, osg::Quat(rad, osg::X_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 = createBone1( "bone1", osg::Vec3(0.0,12.0,4.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();
}
现在我想做一个启动吊车的骨骼动画,启动时支撑杆慢慢的伸长,撑起吊车的吊臂(程序中是读入一个吊车臂模型),吊臂慢慢的竖起(程序中想使吊臂围绕车的尾部旋转),但是现在
把吊臂放到osg::Vec3(0.0,12.0,4.0)处,发现无法围绕制定点旋转,请问怎样设置围绕制定的一个点旋转啊?谢谢 |
|