|
现在我做魔方,已经把所有模型按照相应的位置摆放整齐,我想按照整个立方体,分成九个切面,每次事件相应可以转动整个切面,现在问题是,我不太知道怎样可以控制每个模型的转动,因为我使用,下载一共再场景里面摆放了26个方块,用MatrixTransform方法设置了位置。之后再事件里面,比如说我想让最下面一面向左顺时针旋转90度,需要用什么函数进行操作,并且需要操作哪个对象。- #pragma region 初始化魔方
- osg::ref_ptr<osg::Node> InitCube()
- {
- osg::ref_ptr<osg::Group> group =new osg::Group;
- osg::ref_ptr<osg::Node> node;
- osg::ref_ptr<osg::Node> node111=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf111.IVE");
- osg::ref_ptr<osg::Node> node112=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf112.IVE");
- osg::ref_ptr<osg::Node> node113=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf113.IVE");
- osg::ref_ptr<osg::Node> node121=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf121.IVE");
- osg::ref_ptr<osg::Node> node122=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf122.IVE");
- osg::ref_ptr<osg::Node> node123=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf123.IVE");
- osg::ref_ptr<osg::Node> node131=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf131.IVE");
- osg::ref_ptr<osg::Node> node132=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf132.IVE");
- osg::ref_ptr<osg::Node> node133=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf133.IVE");
- osg::ref_ptr<osg::Node> node211=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf211.IVE");
- osg::ref_ptr<osg::Node> node212=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf212.IVE");
- osg::ref_ptr<osg::Node> node213=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf213.IVE");
- osg::ref_ptr<osg::Node> node221=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf221.IVE");
- osg::ref_ptr<osg::Node> node223=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf223.IVE");
- osg::ref_ptr<osg::Node> node231=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf231.IVE");
- osg::ref_ptr<osg::Node> node232=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf232.IVE");
- osg::ref_ptr<osg::Node> node233=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf233.IVE");
- osg::ref_ptr<osg::Node> node311=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf311.IVE");
- osg::ref_ptr<osg::Node> node312=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf312.IVE");
- osg::ref_ptr<osg::Node> node313=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf313.IVE");
- osg::ref_ptr<osg::Node> node321=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf321.IVE");
- osg::ref_ptr<osg::Node> node322=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf322.IVE");
- osg::ref_ptr<osg::Node> node323=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf323.IVE");
- osg::ref_ptr<osg::Node> node331=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf331.IVE");
- osg::ref_ptr<osg::Node> node332=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf332.IVE");
- osg::ref_ptr<osg::Node> node333=osgDB::readNodeFile("E:/OSGMofan/OSGMofan/model/mf333.IVE");
- osg::ref_ptr<osg::MatrixTransform> matrix111=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix112=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix113=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix121=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix122=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix123=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix131=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix132=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix133=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix211=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix212=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix213=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix221=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix223=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix231=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix232=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix233=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix311=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix312=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix313=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix321=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix322=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix323=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix331=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix332=new osg::MatrixTransform;
- osg::ref_ptr<osg::MatrixTransform> matrix333=new osg::MatrixTransform;
- matrix111->addChild(node111);
- matrix111->setMatrix(osg::Matrix::translate(0.0,0.0,0.0));
- matrix112->addChild(node112);
- matrix112->setMatrix(osg::Matrix::translate(0.0,0.0,20.0));
- matrix113->addChild(node113);
- matrix113->setMatrix(osg::Matrix::translate(0.0,0.0,40.0));
- matrix121->addChild(node121);
- matrix121->setMatrix(osg::Matrix::translate(0.0,20.0,0.0));
- matrix122->addChild(node122);
- matrix122->setMatrix(osg::Matrix::translate(0.0,20.0,20.0));
- matrix123->addChild(node123);
- matrix123->setMatrix(osg::Matrix::translate(0.0,20.0,40.0));
- matrix131->addChild(node131);
- matrix131->setMatrix(osg::Matrix::translate(0.0,40.0,0.0));
- matrix132->addChild(node132);
- matrix132->setMatrix(osg::Matrix::translate(0.0,40.0,20.0));
- matrix133->addChild(node133);
- matrix133->setMatrix(osg::Matrix::translate(0.0,40.0,40.0));
- matrix211->addChild(node211);
- matrix211->setMatrix(osg::Matrix::translate(20.0,0.0,0.0));
- matrix212->addChild(node212);
- matrix212->setMatrix(osg::Matrix::translate(20.0,0.0,20.0));
- matrix213->addChild(node213);
- matrix213->setMatrix(osg::Matrix::translate(20.0,0.0,40.0));
- matrix221->addChild(node221);
- matrix221->setMatrix(osg::Matrix::translate(20.0,20.0,0.0));
- matrix223->addChild(node223);
- matrix223->setMatrix(osg::Matrix::translate(20.0,20.0,40.0));
- matrix231->addChild(node231);
- matrix231->setMatrix(osg::Matrix::translate(20.0,40.0,0.0));
- matrix232->addChild(node232);
- matrix232->setMatrix(osg::Matrix::translate(20.0,40.0,20.0));
- matrix233->addChild(node233);
- matrix233->setMatrix(osg::Matrix::translate(20.0,40.0,40.0));
- matrix311->addChild(node311);
- matrix311->setMatrix(osg::Matrix::translate(40.0,0.0,0.0));
- matrix312->addChild(node312);
- matrix312->setMatrix(osg::Matrix::translate(40.0,0.0,20.0));
- matrix313->addChild(node313);
- matrix313->setMatrix(osg::Matrix::translate(40.0,0.0,40.0));
- matrix321->addChild(node321);
- matrix321->setMatrix(osg::Matrix::translate(40.0,20.0,0.0));
- matrix322->addChild(node322);
- matrix322->setMatrix(osg::Matrix::translate(40.0,20.0,20.0));
- matrix323->addChild(node323);
- matrix323->setMatrix(osg::Matrix::translate(40.0,20.0,40.0));
- matrix331->addChild(node331);
- matrix331->setMatrix(osg::Matrix::translate(40.0,40.0,0.0));
- matrix332->addChild(node332);
- matrix332->setMatrix(osg::Matrix::translate(40.0,40.0,20.0));
- matrix333->addChild(node333);
- matrix333->setMatrix(osg::Matrix::translate(40.0,40.0,40.0));
- group->addChild(matrix111);
- group->addChild(matrix112);
- group->addChild(matrix113);
- group->addChild(matrix121);
- group->addChild(matrix122);
- group->addChild(matrix123);
- group->addChild(matrix131);
- group->addChild(matrix132);
- group->addChild(matrix133);
- group->addChild(matrix211);
- group->addChild(matrix212);
- group->addChild(matrix213);
- group->addChild(matrix221);
- group->addChild(matrix223);
- group->addChild(matrix231);
- group->addChild(matrix232);
- group->addChild(matrix233);
- group->addChild(matrix311);
- group->addChild(matrix312);
- group->addChild(matrix313);
- group->addChild(matrix321);
- group->addChild(matrix322);
- group->addChild(matrix323);
- group->addChild(matrix331);
- group->addChild(matrix332);
- group->addChild(matrix333);
- return group;
- }
- #pragma endregion 初始化
- void main()
- {
- osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer;
-
- viewer->setSceneData(InitCube());
- //viewer->addEventHandler(new osgViewer::HelpHandler());
- viewer->realize();
- viewer->run();
- }
复制代码 |
|