基础的物体的移动,调用translate进行平移操作,调用setUpdateCallback回调函数在每一帧调用的时候更新。
AnimationPathCallback为setUpdateCallbac中的一个绕轴旋转的函数
效果图如下:
#include <iostream>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/ViewerEventHandlers>
#include <osg/MatrixTransform>
osg::ref_ptr<osg::Node> MatrixOperation()
{
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::MatrixTransform> max = new osg::MatrixTransform;
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("glider.osg");
osg::ref_ptr<osg::MatrixTransform> max1 = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> max2 = new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> max3 = new osg::MatrixTransform;
max1->addChild(node.get());
max1->setMatrix(osg::Matrix::translate(5.0,0,0));
max->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(5.0,0,0),osg::Z_AXIS,2.0));
max->addChild(max1.get());
max3->addChild(node.get());
max2->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0,0,0),osg::Z_AXIS,5.0));
max2->addChild(max3.get());
// group->addChild(node.get());
group->addChild(max.get());
group->addChild(max2.get());
return group;
}
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setSceneData(MatrixOperation().get());
return viewer->run();
}