OSG节点访问和遍历

遍历节点树:
osg::Node类中有两个辅助函数:

1void ascend(NodeVisitor& nv) //虚函数,向上一级节点推进访问器 2void traverse(NodeVisitor& nv) //虚函数,向下一级节点推进访问器 3NodeVisitor的traverse()函数实现如下: 4inline void traverse(Node& node) 5{ 6 if (_traversalMode == TRAVERSE_PARENTS) 7 { 8 node.ascend(*this); 9 } 10 else if (_traversalMode != TRAVERSE_NONE) 11 { 12 node.traverse(*this); 13 } 14} 15 16#include <osg/Node> 17#include <osgDB/ReadFile> 18#include <iostream> 19 20using namespace std; 21 22class InfoVisitor: public osg::NodeVisitor 23{ 24public: 25 InfoVisitor() 26 :osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0) 27 {} 28 29 virtual void apply(osg::Node& node) 30 { 31 for(int i = 0; i < _indent; i++) cout << " "; 32 cout << "[" << _indent << "]"<< node.libraryName() 33 << "::" << node.className() << endl; 34 35 _indent++; 36 traverse(node); 37 _indent--; 38 39 for(int i = 0; i < _indent; i++) cout << " "; 40 cout << "[" << _indent << "] "<< node.libraryName() 41 << "::" << node.className() << endl; 42 } 43 44 virtual void apply(osg::Geode& node) 45 { 46 for(int i = 0; i < _indent; i++) cout << " "; 47 cout << "[" << _indent << "] "<< node.libraryName() 48 << "::" << node.className() << endl; 49 50 _indent++; 51 52 for(unsigned int n = 0; n < node.getNumDrawables(); n++) 53 { 54 osg::Drawable* draw = node.getDrawable(n); 55 if(!draw) 56 continue; 57 for(int i = 0; i < _indent; i++) cout << " "; 58 cout << "[" << _indent << "]" << draw->libraryName() << "::" 59 << draw->className() << endl; 60 } 61 62 traverse(node); 63 _indent--; 64 65 for(int i = 0; i < _indent; i++) cout << " "; 66 cout << "[" << _indent << "]"<< node.libraryName() 67 << "::" << node.className() << endl; 68 } 69private: 70 int _indent; 71}; 72 73int main(int argc, char** argv) 74{ 75 osg::ArgumentParser parser(&argc, argv); 76 osg::Node* root = osgDB::readNodeFiles(parser); 77 78 if(!root) 79 { 80 root = osgDB::readNodeFile("avatar.osg"); 81 } 82 83 InfoVisitor infoVisitor; 84 if(root) 85 { 86 root->accept(infoVisitor); 87 } 88 89 system("pause"); 90 return 0; 91}

转自:https://www.cnblogs.com/hzhg/archive/2010/12/17/1908764.html

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

DOM 文档对象模型使用教程来喽!

原文链接:HTML模板html我是网站标题访问节点通过id访问指定节点getElementByIdjavascriptvarnodedocument.getElementById('box')通过name访问指定节点getElementsByNamejav

C++primer学习笔记(六)

1.virtual函数是基类希望派生类重新定义的函数,希望派生类继承的函数不能为虚函数。根类一般要定义虚析构函数。2.派生类只能通过派生类对象访问protected成员,不能用基类对象访问。基类定义为virtual就一直为虚函数,派生类写不写virtual都是虚函数。用做基类的类必须是已定义的。3.存在虚函数指针或引用