GIS开发笔记(6)结合osg及osgEarth实现半球形区域绘制
一、实现效果
输入中心点坐标及半径,绘制半球形区域,地下部分不显示。
二、实现原理
根据中心点及半径绘制半球形区域,将其挂接到地球节点。
三、参考代码
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);
}