写在前面:翻了一遍国内的博客,我竟然没有找到关于 osg 绘制线段的相关代码,反而看到都是一些相同内容的网站,就这风气。
osg::ref_ptr<osg::MatrixTransform> xfrom = getTransMatrix();
osg::ref_ptr<osg::Vec3Array> v1 = new osg::Vec3Array();
// 增加点
v1->push_back(calReferencePosition(_stackPoint));
v1->push_back(calReferencePosition(currentPosition));
// 创建实体
osg::ref_ptr<osg::Geometry> pa = new osg::Geometry();
pa->setVertexArray(v1);
pa->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, v1->size()));
// 线宽
pa->getOrCreateStateSet()->setAttribute(
new osg::LineWidth(_style.lineWidth() * ZHD3DConfig::getDpiScale()));
// 着色器
osg::ref_ptr<osg::Program> lineProgram = new osg::Program;
lineProgram->addShader(new osg::Shader(osg::Shader::VERTEX, stackPointLinkLineVertShader));
lineProgram->addShader(new osg::Shader(osg::Shader::FRAGMENT, stackPointLinkLineFragShader));
pa->getOrCreateStateSet()->setAttributeAndModes(
lineProgram,
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED );
// 线条颜色
pa->getOrCreateStateSet()->addUniform(new osg::Uniform("a_Color",
osgEarth::Color(_style.lineColor())));
xfrom->addChild(pa);
this->addChild(xfrom);
好了,内容比较短,看看继续做下去还有什么更新的内容吧。
网友评论