|
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
/************************************************************************/
/* 当mt1设置为45度,沿X轴正向移动100个距离
/* 当mt2设置为90度时,沿X轴负向移动100个距离
/* 两头牛重合????
/************************************************************************/
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cowNode = osgDB::readNodeFile("cow.osg");
//矩阵变换节点1
osg::ref_ptr<osg::MatrixTransform> mt1 = new osg::MatrixTransform;
//创建一个矩阵
osg::Matrix m;
//沿X轴正向移动10个距离
m.makeTranslate(osg::Vec3(100.0f,0.0f,0.0f));
//绕X轴旋转45度
m.makeRotate(45.0f,1.0f,0.0f,0.0f);
//设置矩阵
mt1->setMatrix(m);
mt1->addChild(cowNode.get());
//矩阵变换节点1
osg::ref_ptr<osg::MatrixTransform> mt2 = new osg::MatrixTransform;
//创建一个矩阵
osg::Matrix t;
//沿X轴负向移动10个距离
t.makeTranslate(osg::Vec3(-100.0f,0.0f,0.0f));
//绕X轴旋转45度
t.makeRotate(90.0f,1.0f,0.0f,0.0f);
//设置矩阵
mt2->setMatrix(t);
mt2->addChild(cowNode.get());
root->addChild(mt1.get());
root->addChild(mt2.get());
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0;
} |
|