第1课时《Qt osgEarth 编程入门》

8 篇文章 1 订阅
2 篇文章 1 订阅

1.首先编译osg /osgEarth 源码,配置环境变量,将osg及osgEarth 对应的bin目录加入系统环境中。

2.在QT中的pro文件中进行引用:

include(deployment.pri)
win32:INCLUDEPATH +=C:/OSGEARRH/include \
              C:/OpenSceneGraph/include \
win32:DEPENDPATH +=C:/OSGEARRH/include \
             C:/OpenSceneGraph/include

win32:CONFIG(release, debug|release): LIBS += \
                                            -LC:/OSGEARRH/lib/ -losgEarth \
                                            -LC:/OSGEARRH/lib/ -losgEarthAnnotation \
                                            -LC:/OSGEARRH/lib/ -losgEarthFeatures \
                                            -LC:/OSGEARRH/lib/ -losgEarthQt \
                                            -LC:/OSGEARRH/lib/ -losgEarthSymbology \
                                            -LC:/OSGEARRH/lib/ -losgEarthUtil \
3.在CPP文件编写

     一般我们加载和使用对应的地理信息资源需要以下几步:


源码如下:

#include <QApplication>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgQt/GraphicsWindowQt>
#include <osg/MatrixTransform>
#include <osgManipulator/TabBoxDragger>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/tms/TMSOptions>
int main( int argc, char** argv )
{
    QApplication app(argc, argv);
    osgQt::initQtWindowingSystem();
    //osg::Group* sceneroot = new osg::Group;
    osg::ref_ptr<osgEarth::Map> map=  new osgEarth::Map;
    osg::ref_ptr<osgEarth::MapNode> mapNode= new osgEarth::MapNode(map);
    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
    osgEarth::Drivers::TMSOptions tms;
    tms.url()="D:/data/world/tms.xml";
    map->addImageLayer(new osgEarth::ImageLayer("My",tms));
    viewer->addEventHandler(new osgViewer::StatsHandler);
    viewer->addEventHandler(new osgGA::StateSetManipulator());
    viewer->setCameraManipulator( new osgGA::TrackballManipulator );
    viewer->setSceneData(mapNode);
    osgQt::setViewer( viewer.get() );
 
    osgQt::GLWidget* glw = new osgQt::GLWidget;
    osgQt::GraphicsWindowQt* graphicswin = new osgQt::GraphicsWindowQt(glw);
 
    viewer->getCamera()->setViewport( new osg::Viewport(0, 0, glw->width(), glw->height() ) );
    viewer->getCamera()->setGraphicsContext( graphicswin );
 
    glw->show();
 
    return app.exec();
}
 运行结果如下: 


评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值