Learning OSG programing---osgwindows
/* OpenSceneGraph example, osgwindows.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/ #include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osgViewer/Viewer> #include <iostream> int main( int argc, char **argv )
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv); // read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead.
if (!loadedModel) loadedModel = osgDB::readRefNodeFile("/home/ding/Downloads/OpenSceneGraph-Data/cow.osgt");
//this path was modified because the OSG_FILE_PATH is not configed correctly in my computer!
//so it is an alternative method // if no model has been successfully loaded report failure.
if (!loadedModel)
{
std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
return ;
} // construct the viewer.
osgViewer::Viewer viewer; int xoffset = ;
int yoffset = ; // left window + left slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift left of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,-1.0,0.0), osg::Matrixd());
} // right window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,-1.0,0.0), osg::Matrixd());
} // left_down window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(1.0,1.0,0.0), osg::Matrixd());
} // right_down window + right slave camera
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = xoffset + ;
traits->y = yoffset + ;
traits->width = ;
traits->height = ;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = ;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen(); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(,, traits->width, traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer); // add this slave camera to the viewer, with a shift right of the projection matrix
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,1.0,0.0), osg::Matrixd());
}
// optimize the scene graph, remove redundant nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel); // set the scene to render
viewer.setSceneData(loadedModel); return viewer.run();
}
The routine of each slave camera is alike. While the key point is this sentence:
viewer.addSlave(camera.get(), osg::Matrixd::translate(-1.0,1.0,0.0), osg::Matrixd());
This sentence set the viewpoint of slave camera,which translate the position of view point. Four slave camera view the common model in different direction, combine together.
the command to complie this program is following:
g++ -o osgwindows_1 osgwindows_1.cpp -losg -losgDB -losgViewer -lOpenThreads -losgUtil
After compling, just run it with:
sudo ./osgwindows_1
The outcome of above program is shown:
Like moniter constructed with four screen. Drag mouse in one window, the model will rotate in other three screen meanwhile. Great!
Learning OSG programing---osgwindows的更多相关文章
- Learning OSG programing---osgScribe
Learning OSG programing---osgScribe Scribe可以翻译为素描,抄写等.本例通过在模型表面添加一层素描,来显示模型的骨架. 关键代码: osg::ref_ptr&l ...
- Learning OSG programing---Multi Camera in Multi window 在多窗口中创建多相机
这个例子演示了在多个窗口中创建多个相机,函数的代码如下: void multiWindowMultipleCameras(osgViewer::Viewer& viewer,bool mult ...
- Learning OSG programing---Multi Camera in one window 在单窗口中创建多相机
在学习OSG提供的例子osgCamera中,由于例子很长,涉及很多细节,考虑将其分解为几个小例子.本文介绍实现在一个窗口中添加多个相机的功能. 此函数接受一个Viewer引用类型参数,设置图形上下文的 ...
- Learning OSG programing---osgAnimation(3)
接下来是用createModel函数创建模型: osg::ref_ptr<osg::Group> createModel(bool overlay, osgSim::OverlayNode ...
- Learning OSG programing---osgAnimation(2)
osg::Node* createBase(const osg::Vec3& center,float radius) { ; ; *radius; *radius; osg::Vec3 v0 ...
- Learning OSG programing---osgAnimation(1)
osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) { ...
- Learning OSG programing---osgShape
本例示范了osg中Shape ---- 基本几何元素的绘制过程.参照osg官方文档,Shape 类包含以下子类: 在示例程序中,函数createShapes函数用于生成需要绘制的几何形状. osg:: ...
- Learning OSG programing---osgClip
OSG Clip例程剖析 首先是创建剪切节点的函数代码: osg::ref_ptr<osg::Node> decorate_with_clip_node(const osg::ref_pt ...
- Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week3, Hyperparameter tuning, Batch Normalization and Programming Frameworks
Tuning process 下图中的需要tune的parameter的先后顺序, 红色>黄色>紫色,其他基本不会tune. 先讲到怎么选hyperparameter, 需要随机选取(sa ...
随机推荐
- ORM多对多的实现
#coding=utf-8 from sqlalchemy import Table, Column, Integer,String,DATE, ForeignKey from sqlalchemy. ...
- C#split的使用方式
一,在msdn中我们能看到一下几种使用 二,我们先看看经常使用的, 我们先定义一个数组 string test = "1,2,,3,4,5,6,7"; 第一种,结果大家都熟悉,就不 ...
- 【学习总结】GirlsInAI ML-diary day-20-初识 Kaggle
[学习总结]GirlsInAI ML-diary 总 原博github链接-day20 初识kaggle 1-注册一个账号(由于被谷歌收购,因此可能需要梯子) 2-Competition - 学会看一 ...
- javaScript--基础 选择结构
2.短路现象--扩展 当 true 遇到 || , true || 表达式不执行, 右侧的表达式不执行 当false 遇到 && , false && 表达式不 ...
- git 报错
-bash: git: command not found export PATH=$PATH:/usr/local/git/bin 使用git clone出现 fatal: unable to ac ...
- C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable
C++中使用函数strcpy时出现问题: 解决方案: 在文件开头添加语句: #pragma warning(disable:4996) done! 剑指offer: 第一题:赋值运算符函数 #incl ...
- rabbitmq 结构体
amqp_basic_properties_t props; props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MOD ...
- python 时间和时间段显示
两个包,最开始发现的是time包 import time print(time.time()) #显示当前时间戳 print(time.localtime(time.time())) #显示本地时间 ...
- python在mapreduce运行Wordcount程序
首先脚本文件: mapper.py: #!/usr/bin/env python import sys for line in sys.stdin: line = line.strip() words ...
- poj 3258:River Hopscotch(二分)
题目链接 L为N+2块石子中最右边石子位置,0最左,M为可移除块数,求移除后相邻石子可达到的最大距离. #include<iostream> #include<cstdio> ...