|
- osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform;
- osg::Group* root = new osg::Group();
- //读取地形模型
- osg::Node* node = new osg::Node();
- node = osgDB::readNodeFile("port.ive");
- osg::Node* follownode=new osg::Node();
- follownode=osgDB::readNodeFile("ship.ive");
- trans->addChild(follownode);
- //添加到场景
- root->addChild(node);
- root->addChild(trans);
- //优化场景数据
- osgUtil::Optimizer optimizer ;
- optimizer.optimize(root) ;
- viewer->setSceneData(root);
- UseEventHandler *ev=new UseEventHandler(trans);
- TM->transMatrix=ev;//TM为视点矩阵,获取模型运动矩阵以便同步
- viewer->addEventHandler(ev);
- viewer->realize();
- viewer->run();
- return 0 ;
复制代码 这么直接组织场景结构键盘相应trans没问题,可是在另一个程序里:- osg::ref_ptr<osg::Group> root = new osg::Group;
- osg::ref_ptr<osg::Node> port=new osg::Node;
- if(arguments.read("-p"),port)
- port=osgDB::readNodeFiles(arguments);
- osg::ref_ptr<osg::Node> ship=NULL;
- if(arguments.read("-sp"),ship)
- ship=osgDB::readNodeFiles(arguments);
- //while(arguments.read("-ship"),ship);这么写很多编译器不能编译。改为上面写法
- osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform;
- trans->addChild(ship.get());//场景组织一下
- root->addChild(port.get());
- root->addChild(trans);
- viewer->setSceneData(root.get());
- viewer->realize();
- UseEventHandler* ev = new UseEventHandler(transMTF);
- TM->transMatrix = ev;//TM为视点矩阵,获取模型运动矩阵以便同步
- viewer->addEventHandler(ev);
- // read up the osgcluster specific arguments.
- ViewerMode viewerMode = STAND_ALONE;
- while (arguments.read("-m")) viewerMode = MASTER;
- while (arguments.read("-s")) viewerMode = SLAVE;
复制代码 这么组织场景的时候,ship模型就不响应了,只有视点能动,trans下挂着ship呀,可是就是不响应,我觉得是场景结构出问题了,请问什么原因? |
|