OSG程序设计之osg::NodeVisitor
本文所有内容来自《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的更多相关文章
- OSG程序设计之osg::Group
以下是一个简单的模型读取程序: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/N ...
- OSG程序设计之Hello World1.0
对于从未接触过OSG的我来说,首先需要一个入门教程.在OSG论坛逛了半天,再加上google,最终决定使用<OSG程序设计>这本书. 下面就贴出书中的第一个例子:Hello World. ...
- OSG程序设计之更新回调
更新回调(Update Callback)涉及到一个类:osg::NodeCallback.这个类重载了函数调用操作符.当回调动作发生时,将会执行这一操作符的内容. 如果节点绑定了更新回调函数,那么在 ...
- OSG程序设计之Hello World 4.0
代码如下: //需要添加两个库:osgUtild.lib.osgTextd.lib #include <osgDB/ReadFile> #include <osgUtil/Optim ...
- osg #ifdef _WIN32 osg
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osgViewer/Viewer> #include ...
- OSG程序设计之Hello World 3.0
直接上代码: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osgViewer/View ...
- OSG程序设计之Hello World 2.0
现在为Hello World添加一些键盘响应事件. //需要多添加两个库:osgGAd.lib.osgd.lib 代码如下: #include <osgDB/ReadFile> #incl ...
- OSG(OpenSceneGraphcow.osg)配置笔记
OpenSceneGraph是一款高性能的3D图形开发库.广泛应用在可视化仿真.游戏.虚拟现实.高端技术研发以及建模等领域.使用标准的C++和OpenGL编写而成,可以运行在Windows系列.OSX ...
- 【OSG】运行OSG示例出现的奶牛不完整问题
发现一个很奇怪的问题:我用笔记本运行OSG里面的示例,出现的图案总是不完整显示的,以经典的奶牛图案为例,如图. 图一是我电脑上的情况,正常情况应该是图二.不知道这是什么原因,难道是我电脑显卡的原因吗? ...
随机推荐
- String 对象-->substr() 方法
1.定义和用法 substr() 方法可在字符串中抽取从 开始 下标开始的指定数目的字符. 语法: string.substr(start,length) 参数: start:提取开始下标 lengt ...
- Wpf之HandyControls与MaterialDesign混用之DataGrid
首先在App.Xaml引入相关资源 <Application.Resources> <ResourceDictionary> <ResourceDictionary.Me ...
- Java创建线程的三种形式的区别以及优缺点
1.实现Runnable,Callable Callable接口里定义的方法有返回值,可以声明抛出异常. 继承Callable接口实现线程 class ThreadCall implements Ca ...
- Python 小技之实现的鲜花盛宴,你准备好了吗?
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:派森酱 PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...
- Some Modern Softwares' drawbacks: User experience 12/29/2015
In the nowadays, there are many APP in the PC or smart Phone. Some of them can't meet the customers' ...
- Equalizing by Division
The only difference between easy and hard versions is the number of elements in the array. You are g ...
- 莫名的证书错误...ERROR ITMS-90035:"Invalid Signature.
请删除 .DS_Store 这种类似的文件再尝试
- 接触 Jmeter
Apache JMeter是 Apache组织开发的基于 Java的开源压力测试工具.接口以及自动化测试. JMeter 可以进行参数化测试,实现自动化脚本与测试数据分离,能够对应用程序做功能/回归测 ...
- js中string转map的方法
例如: var r = "{'msg':'你好'}" ; var map = eval("("+r+")"); //r为String类型的数 ...
- orcale 树形结构查询
接到需求是要在一个表中(表结构为主键id和父id)循环显示数据,类似于省市县++这种情况 也可能不只有三级子菜单 id name parentid 1 a 0 2 ...