Osgearth2.10之集成到Qt5.13

7 篇文章 1 订阅
7 篇文章 1 订阅

基于ViewerWidget类,通过加载earth文件方式创建三维地球,实现Osgearth在Qt5.13中QWidget显示

(1)初始化节点

m_Root = new osg::Group();

std::string url = m_EarthFile;

m_EarthNode = osgDB::readNodeFile(url);

m_Root->addChild(m_EarthNode);

m_MapNode = osgEarth::MapNode::findMapNode(m_EarthNode);

m_ViewerWidget = new ViewerWidget(this, m_Root);

m_MainViewer = dynamic_cast<osgViewer::Viewer*>(m_ViewerWidget->getViewer());

(2)设置漫游器

m_EarthManipulator = new osgEarth::Util::EarthManipulator();

m_EarthManipulator->getSettings()->setMinMaxPitch(-90, 0);//设置最大最小倾斜角度

m_EarthManipulator->getSettings()->setMinMaxDistance(100.0, 4e7);//设置最近最远距离

m_MainViewer->setCameraManipulator(m_EarthManipulator);

(3)设置Camera

osg::Camera* camera = m_MainViewer->getCamera();

osg::GraphicsContext* pGC = camera->getGraphicsContext();

if (!camera->getViewport())

{

             camera->setViewport(new osg::Viewport(0, 0, pGC->getTraits()->width, pGC->getTraits()->height));

}

camera->setProjectionMatrixAsPerspective(30.0f, camera->getViewport()->width() / camera->getViewport()->height(), 1.0f, 10000.0f);

camera->setNearFarRatio(0.00001);

camera->setSmallFeatureCullingPixelSize(-1.0f);

osgEarth::GLUtils::setGlobalDefaults(camera->getOrCreateStateSet());//osgearth2.10.1 添加后才可显示feature

(4)添加到布局

QGridLayout* pLayout = new QGridLayout(this);

pLayout->addWidget(m_ViewerWidget,0,0,1,1);

setLayout(pLayout);

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值