|
小新一枚,弱弱的问一句各位大佬,如何在三维球外部绘制线,我用OSG的方法,线的颜色一直是黑色,画了条线段,但是颜色改变不了
osg::Vec3 startline(155.150, 63.39, 1020230);
osg::Vec3 endline(103.50, 31.50, 1020230);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
const osgEarth::SpatialReference*mapsrs = _mapNode->getMapSRS();
osg::ref_ptr<osg::Geometry> linesgeom = new osg::Geometry();
osg::Vec3d startWorld;
osg::Vec3d endWorld;
osg::ref_ptr<osg::Vec3dArray> vertices = new osg::Vec3dArray(2);
// 将经纬度转换为坐标
osgEarth::GeoPoint map(mapsrs, startline[0], startline[1], startline[2],osgEarth::ALTMODE_ABSOLUTE);
map.toWorld(startWorld);
osgEarth::GeoPoint map1(mapsrs, endline[0], endline[1], endline[2], osgEarth::ALTMODE_ABSOLUTE);
map1.toWorld(endWorld);
(*vertices)[0] = startWorld;
(*vertices)[1] = endWorld;
//将创建的顶点数组传递给几何对象。
linesgeom->setVertexArray(vertices);
linesgeom->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet::Mode:INES, 0, 2));
//设置颜色
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
linesgeom->setColorArray(colors);
linesgeom->setColorBinding(osg::Geometry::BIND_OVERALL);
colors->push_back(osg::Vec4(1.0f,0.0f, 0.0f, 0.5f));
//设置法线。
osg::ref_ptr<osg::Vec3Array> norms = new osg::Vec3Array;
norms->push_back(osg::Vec3(0.0, -1.0, 0.0));
osgUtil::SmoothingVisitor::smooth(*(linesgeom.get()));//自动生成法线
// linesgeom->setNormalArray(norms);
// linesgeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
//限制线宽
osg::ref_ptr<osg::LineWidth> width = new osg::LineWidth;
//设置线宽
width->setWidth(3.0);
geode->getOrCreateStateSet()->setAttributeAndModes(width, osg::StateAttribute::ON);
//打开透明度
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//将点几何添加到大地测量。
geode->addDrawable(linesgeom);
return geode; |
|