当前位置: 首页> 汽车> 新车 > 杭州网站推广与优化_黄冈资讯_seo从零开始到精通200讲解_百度极简网址

杭州网站推广与优化_黄冈资讯_seo从零开始到精通200讲解_百度极简网址

时间:2025/7/10 15:10:06来源:https://blog.csdn.net/oTianLe1234/article/details/147364769 浏览次数: 0次
杭州网站推广与优化_黄冈资讯_seo从零开始到精通200讲解_百度极简网址

一、实现效果
在这里插入图片描述

二、实现原理
按照5°的间隔分别创建经纬线的节点,挂在到组合节点,组合节点挂接到根节点。可以根据需要设置间隔度数和线宽、线的颜色。

三、参考代码

//创建经纬线的节点
osg::Node *GlobeWidget::createGraticuleGeometry(float interval, const osg::Vec4 &color)
{osg::ref_ptr<osg::Geode> geode = new osg::Geode;osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;// 设置颜色colors->push_back(color);geom->setColorArray(colors, osg::Array::BIND_OVERALL);// 生成经线(间隔为interval度)for (float lon = -180.0f; lon <= 180.0f; lon += interval){for (float lat = -89.9f; lat <= 89.9f; lat += 1.0f){osgEarth::GeoPoint pt(osgEarth::SpatialReference::get("wgs84"), lon, lat, 0);osg::Vec3d world;pt.toWorld(world);vertices->push_back(world);}geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,vertices->size() - 180, 180));}// 生成纬线(间隔为interval度)for (float lat = -90.0f; lat <= 90.0f; lat += interval){for (float lon = -180.0f; lon <= 180.0f; lon += 1.0f){osgEarth::GeoPoint pt(osgEarth::SpatialReference::get("wgs84"), lon, lat, 0);osg::Vec3d world;pt.toWorld(world);vertices->push_back(world);}geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,vertices->size() - 361, 361));}geom->setVertexArray(vertices);// 设置线宽osg::ref_ptr<osg::LineWidth> lw = new osg::LineWidth(1.5f);geom->getOrCreateStateSet()->setAttribute(lw);// 配置渲染状态(防止被地形遮挡)osg::StateSet* ss = geom->getOrCreateStateSet();ss->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);// 修复:使用全限定类名 osg::Depthss->setAttribute(new osg::Depth(osg::Depth::LEQUAL, 0, 1, false));ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);geode->addDrawable(geom);return geode.release();
}
//控制经纬线显示隐藏
void GlobeWidget::gridVisible(bool visible)
{if (m_graticuleGroup) {m_graticuleGroup->setNodeMask(visible ? 0xFFFFFFFF : 0x0);}
}
关键字:杭州网站推广与优化_黄冈资讯_seo从零开始到精通200讲解_百度极简网址

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: