本文所有内容来自《OpenSceneGraph三维渲染引擎设计与实践》一书。

  本文主要讨论的是OSG中节点的访问。

  对于节点的访问是从节点接收一个访问器开始的,用户执行某个节点的accept()函数,将一个具体的访问器对象传递给节点。

  第二步,节点反过来执行访问器的apply()函数,并将自身传入访问器。

  这两步的实现过程可以用一行十分简单的函数代码来表达:

void Node::accept(NodeVisitor& nv)
{
nv.apply(*this);
}

  下面是一个具体的访问节点的例子:

#include <osg/Node>
#include <osgDB/ReadFile>
#include <iostream> class InfoVisitor: public osg::NodeVisitor
{
public:
InfoVisitor():osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(){} virtual void apply(osg::Node &node)
{
for (int i = ; i < _indent; ++i)
std::cout<<" ";
std::cout<<"["<<_indent + <<"]"<<node.libraryName()
<<"::"<<node.className()<<std::endl; _indent++;
traverse(node);
_indent--;
} virtual void apply(osg::Geode &node)
{
for (int i = ; i < _indent; ++i)
std::cout<<" ";
std::cout<<"["<<_indent + <<"]"<<node.libraryName()
<<"::"<<node.className()<<std::endl; for (unsigned int n = ; n < node.getNumDrawables(); ++n)
{
osg::Drawable *drawable = node.getDrawable(n);
if (!drawable)
continue;
for (int i = ; i < _indent; ++i)
std::cout<<" ";
std::cout<<drawable->libraryName()
<<"::"<<drawable->className()<<std::endl;
}
_indent++;
traverse(node);
_indent--;
}
protected:
int _indent;
}; int main()
{
osg::Node *root = osgDB::readNodeFile("osgcool.osgt");
InfoVisitor infoVisitor;
if(root)
root->accept(infoVisitor);
return ;
}

  继续学习OSG,吼吼

OSG程序设计之osg::NodeVisitor的更多相关文章

  1. OSG程序设计之osg::Group

    以下是一个简单的模型读取程序: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/N ...

  2. OSG程序设计之Hello World1.0

    对于从未接触过OSG的我来说,首先需要一个入门教程.在OSG论坛逛了半天,再加上google,最终决定使用<OSG程序设计>这本书. 下面就贴出书中的第一个例子:Hello World. ...

  3. OSG程序设计之更新回调

    更新回调(Update Callback)涉及到一个类:osg::NodeCallback.这个类重载了函数调用操作符.当回调动作发生时,将会执行这一操作符的内容. 如果节点绑定了更新回调函数,那么在 ...

  4. OSG程序设计之Hello World 4.0

    代码如下: //需要添加两个库:osgUtild.lib.osgTextd.lib #include <osgDB/ReadFile> #include <osgUtil/Optim ...

  5. osg #ifdef _WIN32 osg

    #ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osgViewer/Viewer> #include ...

  6. OSG程序设计之Hello World 3.0

    直接上代码: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osgViewer/View ...

  7. OSG程序设计之Hello World 2.0

    现在为Hello World添加一些键盘响应事件. //需要多添加两个库:osgGAd.lib.osgd.lib 代码如下: #include <osgDB/ReadFile> #incl ...

  8. OSG(OpenSceneGraphcow.osg)配置笔记

    OpenSceneGraph是一款高性能的3D图形开发库.广泛应用在可视化仿真.游戏.虚拟现实.高端技术研发以及建模等领域.使用标准的C++和OpenGL编写而成,可以运行在Windows系列.OSX ...

  9. 【OSG】运行OSG示例出现的奶牛不完整问题

    发现一个很奇怪的问题:我用笔记本运行OSG里面的示例,出现的图案总是不完整显示的,以经典的奶牛图案为例,如图. 图一是我电脑上的情况,正常情况应该是图二.不知道这是什么原因,难道是我电脑显卡的原因吗? ...

随机推荐

  1. Powershell检查邮件队列设置阈值,通过html形式进行邮件告警

    为了完善公司的整体邮件质量,博主通过zabbix监控了exchange的所有微软推荐项目,并写了很多powershell来辅佐, 旨在更大程度上提高整体的邮件性能 这篇文章主要是讲通过powershe ...

  2. Git应用详解第七讲:Git refspec与远程分支的重要操作

    前言 前情提要:Git应用详解第六讲:Git协作与Git pull常见问题 这一节来介绍本地仓库与远程仓库的分支映射关系:git refspec.彻底弄清楚本地仓库到底是如何与远程仓库进行联系的. 一 ...

  3. posix系统线程调度-设置线程优先级

    #include <thread> #include <mutex> #include <iostream> #include <chrono> #in ...

  4. Python趣味入门3:变量、字串输入与输出

    安装配置python环境完毕,非常有必要花十分钟对一些基本概念:变量.数学字符.输入.输出等4个概念进行理解,下面通过简单示例,深入了解python的基本语法. 本文的示例均在IDLE的命令行模式中完 ...

  5. python初学(二)

    1.输入一个整数列表L,判断L中是否存在相同的数字: (1)若存在,输出YES,否则输出NO: (2)若存在,输出YES,同时输出相同的数字:否则输出NO. l=list(input()) print ...

  6. L16 LeNet

    **本小节用到的数据下载 1.涉及语句 import d2lzh1981 as d2l 数据1 : d2lzh1981 链接:https://pan.baidu.com/s/1LyaZ84Q4M75G ...

  7. Sprint 2 : ios图形界面设计与代码整合

    这周我们主要focus在personal photo experience 项目的ios图形界面设计与代码整合工作上. 工作进度: 1. 图形界面设计方面:兆阳和敏龙基本已经将ios手机客户端的雏形界 ...

  8. Problem E. Bet

    转载:https://blog.csdn.net/qq_40861916/article/details/84403731 #include<iostream> #include<c ...

  9. 最短路径变形 POJ 2253

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  10. Python函数的返回值和作用域

    函数的返回值和作用域 1.返回值 def guess(x):    if x > 3:        return "> 3"    else:        retu ...