|
楼主 |
发表于 2010-8-30 08:44:14
|
显示全部楼层
下面是我的main()
int main()
{
osg::ref_ptr<osgViewer::CompositeViewer> viewer=new osgViewer::CompositeViewer;
osg::ref_ptr<osgViewer::View> view1=new osgViewer::View;
osg::ref_ptr<osg::Group> group=new osg::Group();
osg::ref_ptr<osg::Node> node=osgDB::readNodeFile("cow.osg");
group->addChild(node.get());
transformAccumulator* tankWorldCoords = new transformAccumulator();
tankWorldCoords->attachToGroup(group.get());
followNodeMatrixManipulator* followTank =
new followNodeMatrixManipulator(tankWorldCoords);
osgGA::KeySwitchMatrixManipulator *ksmm = new osgGA::KeySwitchMatrixManipulator();
if (!ksmm)
return -1;
// 添加跟随坦克的矩阵控制器的。按下“m”键即可实现视口切换到该控制器。
ksmm->addMatrixManipulator('m',"tankFollower",followTank);
view1->setSceneData(group.get());
view1->setCameraManipulator(ksmm);
viewer->addView(view1);
viewer->realize();
viewer->run();
return 0;
}
其它部分都的教程上的。我把
class updateAccumulatedMatrix : public osg::NodeCallback
{
public:
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
//这两行注释掉还是一样的效果
//matrix=osg::computeLocalToWorld(nv->getNodePath());
//traverse(node,nv);
}
osg::Matrix matrix;
};
还想请教一下:
bool transformAccumulator::attachToGroup(osg::Group* g)
这个Group 里面node 一直是空的 |
|