查看: 3033|回复: 3

关于OSGEarth绘制卫星轨道问题

[复制链接]

该用户从未签到

发表于 2019-6-27 11:10:40 | 显示全部楼层 |阅读模式
小新一枚,弱弱的问一句各位大佬,如何在三维球外部绘制线,我用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;

该用户从未签到

发表于 2019-7-3 17:01:12 | 显示全部楼层
默认打开了光照,在一些角度下显示黑色,设置geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);可以一直显示红色

该用户从未签到

 楼主| 发表于 2019-7-8 10:24:09 | 显示全部楼层
Tangent 发表于 2019-7-3 17:01
默认打开了光照,在一些角度下显示黑色,设置geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::St ...

谢谢,已经解决了,改用FeaturelNode来绘制的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表