编译环境
osg: 3.6.5
osgEarth: 3.2.0
MSVC2019
osg 和 osgearth 的库文件配置参考这篇文章
编译生成osgQOpenGLWidget
修改CMakeLists 文件
- 添加qt版本和编译器目录
SET(DESIRED_QT_VERSION "5.15.2" CACHE STRING "")
SET(CMAKE_PREFIX_PATH "D:/Solfware/Qt/5.15.2/msvc2019_64" CACHE PATH "")
2.修改osg版本
与安装的osg版本一致
其余内容按照这个文章内容进行即可
将osgEarth嵌入Qt
头文件
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osgEarth/EarthManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osgGA/StateSetManipulator>
#include <osgGA/TrackballManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/NodeTrackerManipulator>
#include <osgGA/FirstPersonManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osg/GraphicsContext>
#include <osg/Math>
#include <osg/BlendFunc>
#include <osg/BlendColor>
#include <osgEarth/ElevationQuery>
#include <osgEarth/Config>
#include <osgEarth/GeoTransform>
#include <osgEarth/MapNode>
#include <osgEarth/Terrain>
#include <osgDB/ReadFile>
#include <osgUtil/LineSegmentIntersector>
#include <osgUtil/Optimizer>
#include <osgUtil/IntersectVisitor>
using namespace osgEarth::Util;
using namespace osgEarth;
using namespace osgGA;
DigtalEarth.h文章来源:https://www.toymoban.com/news/detail-520316.html
class DigtalEarth : public QMainWindow
{
Q_OBJECT
public:
DigtalEarth(QWidget *parent = nullptr);
~DigtalEarth();
private slots:
void initOsg();
private:
Ui::DigtalEarth *ui;
osgQOpenGLWidget *pOsgW;
osgViewer::Viewer *mViewer; //场景
osg::ref_ptr<osg::Group> mRoot; // 根节点
osg::ref_ptr<osg::Node> mEarth; //地球节点
osg::ref_ptr<osgEarth::Util::EarthManipulator> mCamera; //相机操作器
};
DigtalEarth::DigtalEarth(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::DigtalEarth)
{
ui->setupUi(this);
resize(400, 300);
pOsgW = new osgQOpenGLWidget(this);
ui->gridLayout_2->addWidget(pOsgW);
mRoot = new osg::Group;
mCamera = new osgEarth::Util::EarthManipulator;
mEarth = osgDB::readNodeFile("simple.earth");
mRoot->addChild(mEarth.get());
connect(pOsgW, SIGNAL(initialized()), this, SLOT(initOsg()));
}
DigtalEarth::~DigtalEarth()
{
delete ui;
}
void DigtalEarth::initOsg()
{
osgEarth::initialize();
mViewer = pOsgW->getOsgViewer();
mViewer->setCameraManipulator(new osgGA::TrackballManipulator());
mViewer->setCameraManipulator(mCamera);
mViewer->setSceneData(mRoot.get());
}
文章来源地址https://www.toymoban.com/news/detail-520316.html
到了这里,关于【QT + OsgEarth】(二)-- OsgEarth + osgQOpenGLWidget 加载地球的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!