最近研究了下,加载OsgEarth有两种方式:
1.使用osgQt提供的osgQOpenGLWidget方式加载。
2.从public QOpenGLWidget, public osgViewer::Viewer派生类实现。
相关代码已上传到码云:
osgEarthTest: osgEarth3.1与Qt5集成的代码
效果:
方式1:
参考文档:
Qt加载OsgEarth的新方式osgQOpenGL简介_sun_xf1的博客-CSDN博客_qt加载osgearth
该文档代码需要添加的部分代码:
需使用如下控制器才能显示地图:
//加载osgEarth需使用osgEarth::EarthManipulator控制器
osg::ref_ptr<osgEarth::EarthManipulator> earthManipulator = new osgEarth::EarthManipulator();
pViewer->setCameraManipulator(earthManipulator);
参考项目代码中的Widget类的实现
方式2:
public QOpenGLWidget, public osgViewer::Viewer派生类实现.参考项目中代码
QOSGViewerWidget类的实现。
其中需要注意的是:
1.如果加载earth,则需要使用osgEarth::EarthManipulator控制器,如果加载模型,使用默认的即可。