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 ...
随机推荐
- 页面存在多个url,使用jmeter进行遍历操作
有一次遇见一个问题:进入网站后,有多个相同的url,但是仅url后面的路径中id有区别,如下图:这时我想要遍历点击查看url详情内容:那么就可以使用一个“逻辑控制器---foreach控制器” 如下: ...
- c++容器的底层数据结构
序列式容器 vector ->底层数据结构为数组,支持快速随机访问 list ->底层数据结构为双向链表,支持快速增加和删除 deque ->底层数据结构为一个中央控制器和多个缓冲区 ...
- 条件变量 condition_variable wait
wait(阻塞当前线程,直到条件变量被唤醒) #include <iostream> #include <string> #include <thread> #in ...
- Linux的文本编辑和文本内容查看命令
Linux的文本编辑和文本内容查看命令 1.文本编辑命令 vi:用于编辑文本文件,基本上可以分为三种模式,分别是一般模式.编辑模式.命令行模式. 一般模式:当编辑一个文件时,刚进入文件就是一般模 ...
- hibernate.current_session_context_class 比较权威的解释
hibernate.current_session_context_class 博客分类: hibernate HibernateSpring多线程配置管理thread 遇到过的问题: 情景1: 在 ...
- JSR303完成validate校验并编写BeanValidator工具类
一.引入pom依赖 <!-- validator --> <dependency> <groupId>javax.validation</groupId> ...
- 第一天 简单的python认证登陆代码
#!/usr/bin/env python3# -*- coding:utf-8 -*-# name:zzyu welcome = '''-----------welcome to home----- ...
- lambda表达式,及lambda简化过程
lambda表达式(jdk8特性) 1.为什么要用lambda表达式 原因:因为我们有时候需要用到很多类,但是,这些类我们只用一次或者两次,所以我们用匿名内部类,但是匿名内部类多了还是很麻烦,所以用l ...
- ES6构造函数class 和 ES5构造函数语法
构造函数就是JavaScript程序定义好的函数,我们直接使用就可以,实际也是一种函数,构造函数专门用于生成定义对象,通过构造函数生成的对象,称为实例化对象 构造函数分为两种,一种是JavaScrip ...
- sqli-labs通关----11~20关
第十一关 从第十一关开始,就开始用post来提交数据了,我们每关的目的都是获取users表下password字段的内容. post是一种数据提交方式,它主要是指数据从客户端提交到服务器端,例如,我们常 ...