|
class getWorldCoordOfNodeVisitor : public osg::NodeVisitor
{
public:
getWorldCoordOfNodeVisitor():
osg::NodeVisitor(NodeVisitor::TRAVERSE_PARENTS), done(false)
{
wcMatrix= new osg::Matrixd();
}
virtual void apply(osg::Node &node)
{
if (!done)
{
if ( 0 == node.getNumParents() ) //到达根节点,此时节点路径也已记录完整
{
wcMatrix->set( osg::computeLocalToWorld(this->getNodePath()) );
done = true;
}
traverse(node);
}
}
osg::Matrixd* giveUpDaMat()
{
return wcMatrix;
}
private:
bool done;
osg::Matrix* wcMatrix;
};
osg::Matrixd* getWorldCoords( osg::Node* node)
{
getWorldCoordOfNodeVisitor* ncv = new getWorldCoordOfNodeVisitor();
if (node && ncv)
{
node->accept(*ncv);
return ncv->giveUpDaMat();
}
else
{
return NULL;
}
}
在这个方法基础上应该怎么修改? |
|