效果图
实现过程
- 下载影像地图和高程图
- 编写earth文件加载资源
- 在QT窗口设置参数和星空背景
影像地图和高程图
下载.tif 格式的地图文件
编写earth文件加载资源
<map name="Global" type="geocentric" version = "2">
<!--影像地图文件-->
<image name="GlobalImage" driver="gdal">
<url>../data/world.tif</url>
</image>
<!--高程地图文件-->
<heightfield name="GlobalHeightfield" driver="gdal">
<url>../data/srtm30plus_stripped.tif</url>
</heightfield>
<!--文件缓存-->
<options>
<cache type="filesystem">
<path>./FileCache</path>
</cache>
</options>
</map>
在QT窗口设置参数和星空背景
使用SkyNode添加星空背景
#include <osgEarth/Sky>
//初始化天空
osgEarth::Util::SkyOptions skyOptions;
skyOptions.ambient() = 0.1;
//控制黑夜部分明暗程度,数值越小,越黑暗
double hours = 12.0;
osgEarth::DateTime dateTime(2022, 10, 23, 3);
osgEarth::Util::SkyNode *sky_node;
sky_node = osgEarth::Util::SkyNode::create(skyOptions);
sky_node->setName("sky");
sky_node->setDateTime(dateTime);
sky_node->setLighting(true);
//mRoot->addChild(sky_node);
osgEarth::insertGroup(sky_node,mRoot);
OsgEarth3.2版本的SkyNode实例化与早期版本不同,使用osgEarth::Util::SkyNode::create(& SkyOptions)
进行实例化