在osgearth里头画线
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
线的画法和osg里头一样,可参看osggeometry.cpp,但是点的坐标需要经过转换,实践证明是可行的,应该也可以用到其它几何体上。新手上路,欢迎大牛们拍砖。
这部分放在main()或者InitSceneGraph( void )中
osg::ref_ptr
mRoot->addChild(geode);
//测试画线
osg::Vec3d startline(-155.150257, 63.390041, 220230);
osg::Vec3d endline(-165.150257, 63.390041, 0);
createLine(startline, endline);
void OSGEarthEngine::createLine(osg::Vec3d startline, osg::Vec3d endline)
{
const SpatialReference* mapSRS = mapNode->getMapSRS();
// create Geometry object to store all the vertices and lines primitive.
osg::ref_ptr
// this time we'll preallocate the vertex array to the size we
// need and then simple set them as array elements, 2 points
// makes 1 line segments.
osg::Vec3d startWorld;
osg::Vec3d endWorld;
osg::ref_ptr
mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS,startline), startWorld );
mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS,endline), endWorld );
(*vertices)[0] = startWorld;
(*vertices)[1] = endWorld;
// pass the created vertex array to the points geometry object.
linesGeom->setVertexArray(vertices);
// set the colors as before, plus using the above
osg::ref_ptr
colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
// set the normal in the same way color.
osg::ref_ptr
normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// This time we simply use primitive, and hardwire the number of coords to use
// since we know up front,
linesGeom->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet:INES,0,2));
// add the points geometry to the geode.
geode->addDrawable(linesGeom);
}