一、实现效果
输入中心点坐标及半径,绘制半球形区域,地下部分不显示。
二、实现原理
根据中心点及半径绘制半球形区域,将其挂接到地球节点。
三、参考代码
void GlobeWidget::drawSphericalRegion(osg::Vec3d point,double radius)
{
// 使用 osgEarth 转换经纬度到地球坐标
osgEarth::GeoPoint geoPoint(osgEarth::SpatialReference::get("wgs84"),
point.x(), point.y(), 0.0, osgEarth::ALTMODE_ABSOLUTE);
osg::Vec3d worldPoint;
geoPoint.toWorld(worldPoint); // 转换为地球坐标系
// 创建一个球体
osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(worldPoint, radius);
osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(sphere);
// 设置材质颜色
shape->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 0.5f)); // 红色,半透明
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable(shape);
// 启用透明混合
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
// 添加到根节点
m_userDrawGroup->addChild(geode);
}