//QT += core gui opengl
//LIBS += -losgViewer -losgDB -losgUtil -losg -lOpenThreads -losgGA -losgQt
#include <QtGui/QApplication>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
#include <QtCore/QString>
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtGui/QMainWindow>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QMdiArea>
#include <iostream> using Qt::WindowFlags; class AdapterWidget:public QGLWidget
{
public:
AdapterWidget(QWidget *parent=,const char* name=,const QGLWidget * shareWidget=,WindowFlags f=); virtual ~AdapterWidget()
{ } osgViewer::GraphicsWindow* getGraphicsWindow()
{
return _gw.get();
} const osgViewer::GraphicsWindow* getGraphicsWidow()const
{
return _gw.get();
}
protected:
void init();
virtual void resizeGL(int width,int height);
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);//
virtual void mouseMoveEvent(QMouseEvent* event); osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw; }; AdapterWidget::AdapterWidget(QWidget *parent,const char* name,const QGLWidget * shareWidget,WindowFlags f):QGLWidget(parent,shareWidget,f)
{
_gw=new osgViewer::GraphicsWindowEmbedded(,,width(),height());
setFocusPolicy(Qt::ClickFocus); } void AdapterWidget::resizeGL(int width, int height)
{
_gw->getEventQueue()->windowResize(,,width,height);
_gw->resized(,,width,height); }
void AdapterWidget::keyPressEvent(QKeyEvent* event)
{
_gw->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) *(event->text().toAscii().data() ) ); } void AdapterWidget::keyReleaseEvent(QKeyEvent* event)
{
_gw->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol)*(event->text().toAscii().data())); } void AdapterWidget::mousePressEvent(QMouseEvent* event)
{
int button=;
switch (event->button())
{
case(Qt::LeftButton):
button=;
break;
case (Qt::MidButton):
button=;
break;
case (Qt::RightButton):
button=;
break;
case (Qt::NoButton):
button=;
break;
default:
button=;
break; } _gw->getEventQueue()->mouseButtonPress(event->x(),event->y(),button); } void AdapterWidget::mouseReleaseEvent( QMouseEvent* event )
{
int button = ;
switch(event->button())
{
case(Qt::LeftButton):
button = ;
break;
case(Qt::MidButton):
button = ;
break;
case(Qt::RightButton):
button = ;
break;
case(Qt::NoButton):
button = ;
break;
default:
button = ;
break;
}
_gw->getEventQueue()->mouseButtonRelease(event->x(), event->y(), button);
} void AdapterWidget::mouseMoveEvent(QMouseEvent* event)
{
_gw->getEventQueue()->mouseMotion(event->x(),event->y()); } class ViewerQT : public osgViewer::Viewer, public AdapterWidget
{
public:
ViewerQT(QWidget * parent=,const char * name=,const QGLWidget * shareWidget=,WindowFlags f=):AdapterWidget(parent ,name,shareWidget ,f)
{
getCamera()->setViewport(new osg::Viewport(,,width(),height()));
getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
getCamera()->setGraphicsContext(getGraphicsWindow()); setThreadingModel(osgViewer::Viewer::SingleThreaded);
connect(&_timer,SIGNAL(timeout()),this,SLOT(updateGL()));//并且把它的timeout()连接到适当的槽。当这段时间过去了,它将会发射timeout()信号。 _timer.start();//使用start()来开始 } virtual void paintGL()
{
frame();
}
protected:
QTimer _timer;
}; int main(int argc,char** argv)
{
QApplication a(argc,argv);
osg::ref_ptr<osg::Node> loadedModel=osgDB::readNodeFile("cow.osg");
ViewerQT * ViewerWindow=new ViewerQT;
ViewerWindow->setCameraManipulator(new osgGA::TrackballManipulator);
ViewerWindow->setSceneData(loadedModel.get()); QMainWindow* mw=new QMainWindow();
mw->showMaximized();
mw->setCentralWidget(ViewerWindow);
mw->show();
a.connect(&a,SIGNAL(lastWindowClosed()),&a,SLOT(quit()));
return a.exec();
}

Qt加载OSg视图例子的更多相关文章

  1. MVC学习系列6--使用Ajax加载分部视图和Json格式的数据

    Ajax的应用在平时的工作中,很是常见,这篇文章,完全是为了,巩固复习. 我们先看看不使用json格式返回分部视图: 先说需求吧: 我有两个实体,一个是出版商[Publisher],一个是书[Book ...

  2. MVC5中,加载分部视图,常见的方式

    首先,新建一个MVC类型的Web项目: 然后在Model文件夹下定义一个Student实体: public class Student { public int ID { get; set; } pu ...

  3. MVC Ajax Helper或jQuery异步方式加载部分视图

    Model: namespace MvcApplication1.Models { public class Team { public string Preletter { get; set; } ...

  4. Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子

    Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...

  5. jQuery加载部分视图(Partial Views)

    本篇是演示使用jQuery加载部分视图(Partial View).如果你不想使用Razor的语法呈现部分视图,那此篇的方法是最理想的了.它可以Render至指定的tag上. 创建两个部分视图,一个为 ...

  6. MVC加载部分视图Partial

    加载部分视图的方法:Partial() .RenderPartial() . Action() .RenderAction() . RenderPage() partial 与 RenderParti ...

  7. VB6 加载水晶报表例子

    VB6 加载水晶报表例子 先按照水晶报表组件 Crystal Reports,Business Objects,现已被SAP收购. 再添加引用 'Library: CRAXDRT 'C:\Progra ...

  8. 使用jquery加载部分视图02-使用$.ajax()

    本篇体验使用$.ajax()加载部分视图.与加载部分视图相关的包括: RenderPartial和RenderAction区别   使用jquery加载部分视图01-使用$.get()       □ ...

  9. 使用jquery加载部分视图01-使用$.get()

    使用Html.RenderParital或Html.RenderAction可以在主视图中加载部分视图. 两种方法是有区别的,在"RenderPartial和RenderAction区别&q ...

随机推荐

  1. 机器学习理论基础学习9--- EM 算法

    EM算法的适用场景: EM算法用于估计含有隐变量的概率模型参数的极大似然估计,或者极大后验概率估计. 当概率模型既含有观测值,又含有隐变量或潜在变量时,就可以使用EM算法来求解概率模型的参数. 当概率 ...

  2. .NET 互联网技术简介

    概述 技术更新太快,尤其是在互联网公司里,很多新的主流技术,我们还是必须要知道和熟练使用的.下面就给大家简单介绍,入门还是需要大家更努力的去深入学习. 目录 Git 入门 常用软件安装及VS插件工具 ...

  3. Linux系统——PXE高效能批量网络装机

    PXE:Pre-boot Excution Environment,预启动执行环境,石油Intel公司开发的网络引导技术,工作在Client.Server模式,允许客户机通过网络从远程服务器下载阴道镜 ...

  4. cda转MP3

    首先启动Windows Media Player播放器(依次单击“开始”——“所有程序”——“附件”——“娱乐”——“Windows Media Player”     在工具栏切换到“翻录”选项,这 ...

  5. python练习题-写一个函数,打印所有包含copy方法的内置对象

    代码: #encoding=utf-8for i in dir(__builtins__):    #print "i:",i    try: #这里的i是个字符串,并不能直接用d ...

  6. MySQL Crash Course #11# Chapter 20. Updating and Deleting Data

    INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...

  7. Redis 如何正确实现分布式锁

    前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上已经有各种介 ...

  8. MySQL中INSERT的一般用法

    原文链接:http://www.blogjava.net/midnightPigMan/archive/2014/12/15/421406.html MySQL中INSERT的一般用法 INSERT语 ...

  9. Python3基础 函数 无参数无返回值 调用会输出hello world的函数

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. TeeChart的网络资料

    TeeChart坐标轴常见问题 http://www.shaoqun.com/a/54063.aspx TeeChart常用编程语句汇总(C#) http://www.ev get.com/artic ...