OSG程序设计之Hello World 4.0
代码如下: //需要添加两个库: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的更多相关文章
- 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程序设计之Hello World1.0
对于从未接触过OSG的我来说,首先需要一个入门教程.在OSG论坛逛了半天,再加上google,最终决定使用<OSG程序设计>这本书. 下面就贴出书中的第一个例子:Hello World. ...
- OSG程序设计之更新回调
更新回调(Update Callback)涉及到一个类:osg::NodeCallback.这个类重载了函数调用操作符.当回调动作发生时,将会执行这一操作符的内容. 如果节点绑定了更新回调函数,那么在 ...
- OSG程序设计之osg::NodeVisitor
本文所有内容来自<OpenSceneGraph三维渲染引擎设计与实践>一书. 本文主要讨论的是OSG中节点的访问. 对于节点的访问是从节点接收一个访问器开始的,用户执行某个节点的accep ...
- OSG程序设计之osg::Group
以下是一个简单的模型读取程序: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/N ...
- C语言程序设计(基础)- 第0次作业
亲爱的同学们,恭喜你成为一名大学生,我也很荣幸能够带大家一起学习大学的第一门专业基础课.还在军训的你,肯定对大学生活和计算机专业有着美好的憧憬,那么大学生活是什么样子的那?计算机专业应该怎么学习那?请 ...
- 2018下C程序设计(上)第0次作业
1.翻阅邹欣老师博客关于师生关系博客,并回答下列问题: (1)大学和高中最大的不同是什么?请看大学理想的师生关系是?有何感想? 我认为大学和高中最大的不同在于我们(包括老师)对学习的态度.在高中,学生 ...
- 【OSG】osgText::Text 研究
由于需要在3D坐标轴上显示刻度值,所以要用到osgText::Text,这里简单记录一下其常见用法. 一.基本知识 常见设置 设置字体:setFont 设置内容:setText,这里输入参数需要是os ...
随机推荐
- kubernates常用命令
Kubernetes常用操作命令 kubectl log //查看日志 $ kubectl log myapp-pod –c test kubectl get pods查看pod列表 [root@n ...
- Sentry实时应用错误跟踪系统在Kubernetes中私有化部署
应用错误跟踪系统:对软件系统运行过程中产生的错误日志进行收集从而实现监控告警. 虽然软件错误❌是不可避免的,但是可以降低错误数. 提高对错误的治理能力能让错误带来的损失降到最低
- python爬取《龙岭迷窟》的数据,看看质量剧情还原度到底怎么样
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:简单 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行 ...
- 用Python介绍了企业资产情况的数据爬取、分析与展示。
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:张耀杰 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...
- sorted排序的两个方法 - Python
在给列表排序时,sorted非常好用,语法如下: sorted(iterable[, cmp[,key[,reverse]]]) 简单列表排序,很容易完成,sorted(list)返回的对象就是列表结 ...
- linux CVE-2019-14287 Sudo提权漏洞
CVE-2019-14287 sudo介绍 sudo,也就是以超级管理员身份运行(superuser do)的意思.sudo 是 Linux 中最常使用的重要实用程序之一,它功能十分强大,几乎安装在每 ...
- SpringCloud(一)学习笔记之项目搭建
[springcloud项目名称不支持下划线] 一.创建父项目 File---new---project: 填写项目信息: 默认即可,点击finish创建完成: 由于父项目只用到pom文件 所以把sr ...
- SpringBoot+Netty+WebSocket实现实时通信
这篇随笔暂时不讲原理,首先搭建起一个简单的可以实现通信的Demo.之后的一系列随笔会进行一些原理上的分享. 不过在这之前大家最好了解一下Netty的线程模型和NIO编程模型,会对它的整体逻辑有所了解. ...
- ASP.NET母版页
ASP.NET母版页:主要是设置一致界面的页面,在固定的页中进行更新. 如图1-1所示 页头 页中(页内容) 页尾 图1-1 母版页 一般网页是固定页头和页尾,只更新页内容,来实现网页的跳转或内容的 ...
- Python软件定时器APScheduler使用【软件定时器,非操作系统定时器,软件可控的定时器】【用途:定时同步数据库和缓存等】【刘新宇】
APScheduler使用 APScheduler (advanceded python scheduler)是一款Python开发的定时任务工具. 文档地址 https://apscheduler. ...