PositionAttitudeTransform MatrixTransform 使用:
效果图:#include "stdafx.h" #include "../include/LoadLib.h" #include <osg/vec3> #include <osg/PositionAttitudeTransform> #include <osg/MatrixTransform> #include <osg/Node> #include <osg/Geode> #include <osg/Group> #include <osgDB/ReadFile> #include <osgViewer/viewer> #include <osgUtil/optimizer> #include <osg/Matrix> int _tmain(int argc, _TCHAR* argv[]) { osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(); osg::ref_ptr<osg::Group> root = new osg::Group(); osg::ref_ptr<osg::PositionAttitudeTransform> pat1 = new osg::PositionAttitudeTransform(); osg::ref_ptr<osg::PositionAttitudeTransform> pat2 = new osg::PositionAttitudeTransform(); osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg"); pat1->setPosition(osg::Vec3(-10.0f,0.0f,0.0f)); pat1->setScale(osg::Vec3(5.0f,5.0f,5.0f)); pat1->addChild(cow.get()); pat2->setPosition(osg::Vec3(15.0f,0.0f,0.0f)); pat2->addChild(cow.get()); osg::ref_ptr<osg::MatrixTransform> Mt = new osg::MatrixTransform(); Mt->addChild(pat1); osg::Matrix m1; m1.makeRotate(90.0f*osg::PI/180.0f,osg::Vec3(1.0f,0.0f,0.0f)); osg::Matrix m2; m2.makeTranslate(-10.0f,10.0f,0.0f); m1.preMult(m2); Mt->setMatrix(m1); root->addChild(Mt.get()); //root->addChild(pat1.get()); root->addChild(pat2.get()); osgUtil::Optimizer optimizer; optimizer.optimize(root.get()); viewer->setSceneData(root.get()); //viewer->realize(); viewer->run(); return 0; }
问题:Matrix的使用还不是很熟,有时间在研究研究。