代码如下:  //需要添加两个库:osgUtild.lib、osgTextd.lib

#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osgText/Text>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers> #include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <iostream>
int main(int argc, char **argv)
{
osg::ArgumentParser arguments(&argc, argv);
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() +
" is the standard OpenSceneGraph example which loads and visualises 3d models.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName() +
" [options] filename...");
arguments.getApplicationUsage()->addCommandLineOption("--image <filename>", "Load an image and render it on quad");
arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>", "Load an image/DEM and render it on a HeightField");
arguments.getApplicationUsage()->addCommandLineOption("-h or -help", "Display command line parameters");
arguments.getApplicationUsage()->addCommandLineOption("--help-env", "Display environmental variables available");
arguments.getApplicationUsage()->addCommandLineOption("--help-keys", "Display keyboard & mouse bindings available");
arguments.getApplicationUsage()->addCommandLineOption("--help-all", "Display command line, env vars and keyboard & mouse bindings.");
arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded", "Select SingleThreaded threading model for viewer.");
arguments.getApplicationUsage()->addCommandLineOption("-CullDrawThreadPerContext",
"Select CullDrawThreadPerContext threading model for viewer.");
arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext",
"Select DrawThreadPerContext threading model for viewer.");
arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext",
"Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.");
bool helpAll = arguments.read("--help-all");
unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help")) ?
osg::ApplicationUsage::COMMAND_LINE_OPTION : ) |
((helpAll || arguments.read("--help-env")) ?
osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : ) |
((helpAll || arguments.read("--help-keys")) ?
osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : );
if (helpType)
{
arguments.getApplicationUsage()->write(std::cout, helpType);
return ;
} osgViewer::Viewer viewer(arguments);
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return ;
}
if (arguments.argc() <= )
{
arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION);
return ;
} //添加一些操作器
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
keyswitchManipulator->addMatrixManipulator('', "Trackball", new osgGA::TrackballManipulator());
keyswitchManipulator->addMatrixManipulator('', "Flight", new osgGA::FlightManipulator());
keyswitchManipulator->addMatrixManipulator('', "Drive", new osgGA::DriveManipulator());
keyswitchManipulator->addMatrixManipulator('', "Terrain", new osgGA::TerrainManipulator()); std::string pathfile;
char keyForAnimationPath = '';
while (arguments.read("-p", pathfile))
{
osgGA::AnimationPathManipulator *apm = new osgGA::AnimationPathManipulator(pathfile);
if (apm || !apm->valid())
{
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
keyswitchManipulator->addMatrixManipulator(keyForAnimationPath, "Path", apm);
keyswitchManipulator->selectMatrixManipulator(num);
++keyForAnimationPath;
}
}
viewer.setCameraManipulator(keyswitchManipulator.get()); //添加状态事件
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
viewer.addEventHandler(new osgViewer::ThreadingHandler);
//窗口大小变化事件
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
//添加一些常用状态设置
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
if (!loadedModel)
{
std::cout<<arguments.getApplicationName()<<": No data loaded"<<std::endl;
return ;
}
arguments.reportRemainingOptionsAsUnrecognized();
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return ;
}
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel.get());
viewer.setSceneData(loadedModel.get()); viewer.realize();
viewer.run();
}

  吐槽一下作者,作为新手教程,搞这些乱七八糟的东西有什么用呢?

  这个例子相比3.0版本,唯一的新东西就是有个模型优化。

OSG程序设计之Hello World 4.0的更多相关文章

  1. OSG程序设计之Hello World 3.0

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

  2. OSG程序设计之Hello World 2.0

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

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

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

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

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

  5. OSG程序设计之osg::NodeVisitor

    本文所有内容来自<OpenSceneGraph三维渲染引擎设计与实践>一书. 本文主要讨论的是OSG中节点的访问. 对于节点的访问是从节点接收一个访问器开始的,用户执行某个节点的accep ...

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

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

  7. C语言程序设计(基础)- 第0次作业

    亲爱的同学们,恭喜你成为一名大学生,我也很荣幸能够带大家一起学习大学的第一门专业基础课.还在军训的你,肯定对大学生活和计算机专业有着美好的憧憬,那么大学生活是什么样子的那?计算机专业应该怎么学习那?请 ...

  8. 2018下C程序设计(上)第0次作业

    1.翻阅邹欣老师博客关于师生关系博客,并回答下列问题: (1)大学和高中最大的不同是什么?请看大学理想的师生关系是?有何感想? 我认为大学和高中最大的不同在于我们(包括老师)对学习的态度.在高中,学生 ...

  9. 【OSG】osgText::Text 研究

    由于需要在3D坐标轴上显示刻度值,所以要用到osgText::Text,这里简单记录一下其常见用法. 一.基本知识 常见设置 设置字体:setFont 设置内容:setText,这里输入参数需要是os ...

随机推荐

  1. Mysql中的分库分表

    mysql中的分库分表分库:减少并发问题分表:降低了分布式事务分表 1.垂直分表 把其中的不常用的基础信息提取出来,放到一个表中通过id进行关联.降低表的大小来控制性能,但是这种方式没有解决高数据量带 ...

  2. thinkphp5.0远程执行漏洞

    0x01 漏洞简介 由于ThinkPHP5 框架控制器名 没有进行足够的安全监测,导致在没有开启强制路由的情况下,可以伪装特定的请求可以直接Getshell(可以控制服务器) 0x02 环境搭建 Ph ...

  3. Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(七)之Access Control

    Access control ( or implementation hiding) is about "not getting it right the first time." ...

  4. Daily Scrum 12/21/2015

    Process: Zhaoyang: Integrate the oxford Speech API Code to the IOS client and do some UI optimizatio ...

  5. 谁说 Vim 不好用?送你一个五彩斑斓的编辑器!

    相信大家在使用各种各样强大的 IDE 写代码时都会注意到,代码中各种类型的关键字会用独特的颜色标记出来,然后形成一套语法高亮规则.这样不仅美观,而且方便代码的阅读. 而在上古神器 Vim 中,我们通常 ...

  6. vue2.x学习笔记(十)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12584237.html. 事件处理 使用javascript当然少不了事件处理,即使是vue也不会例外. 监听事件 ...

  7. .NET Core3.1总体预览和第一个Core程序的创建

    小伙伴们大家好!欢迎阅读本贴,这里是常哥说编程的专栏,.NetCore已经出来一段时间了,很多小伙伴可能也开始了学习,但是.NetCore毕竟在学习上和我们常用的.NET Framework还是有很大 ...

  8. testNG 问题总结

    1. Eclipse中TestNG报告乱码问题 在eclipse 安装根目录下的eclipse.ini 文件,在最后增加 -Dfile.encoding=UTF-8

  9. UML 建模工具的安装与使用

    一. 实验目的1) 学习使用 EA(Enterprise Architect) 开发环境创建模型的一般方法: 2) 理解 EA 界面布局和元素操作的一般技巧: 3) 熟悉 UML 中的各种图的建立和表 ...

  10. cgi、fastCGI、php-fpm、 php-CGI的区别

    cgi.fastCGI.php-fpm. php-CGI的区别 作为面试的高频热点问题,必须来一波记录: 我们发送一个请求到收到响应之间的一个过程是什么? 如果客户端请求的是 index.html,那 ...