|
本帖最后由 abc-osg 于 2015-1-3 13:54 编辑
osg::ref_ptr<osg::MatrixTransform> draw1::createpline(osg::Vec3d start,osg::Vec3d end)
{
osg::ref_ptr<osg::MatrixTransform> mt=new osg::MatrixTransform();
osg::ref_ptr<osg::Geode> geode=new osg:: Geode();
osg::ref_ptr<osg::Geometry> linesGeom=new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> v=new osg:: Vec3Array();
mt->setMatrix(osg::Matrix::translate(osg::Vec3d((start.x()+end.x())/2,(start.y()+end.y())/2,(start.z()+end.z())/2)));
v->push_back((start-end)/2);
v->push_back((end-start)/2);
linesGeom->setVertexArray(v.get());
// set the colors as before, plus using the above
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(0.0f,0.0f,0.5f,1.0f));
linesGeom->setColorArray(colors);
linesGeom->setColorBinding(osg::Geometry:: BIND_OVERALL);
// set the normal in the same way color.
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
linesGeom->setNormalArray(normals);
linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
linesGeom->addPrimitiveSet(new osg:: DrawArrays(osg:: PrimitiveSet:: LINES,0,v->size()));
geode->addDrawable(linesGeom);
mt->addChild(geode);
return mt.get();
}
draw1 draw;
osg::ref_ptr<osg::MatrixTransform> mt=draw.createpline(osg::Vec3d(73100.046,65692.537,-0.1),osg::Vec3d(73099.179,65688.977,-0.1));
osgDB::writeNodeFile(*(mt.get()),"F:\\11.osg");
osg::ref_ptr<osg::MatrixTransform> mt1=draw.createpline(osg::Vec3d(73100.046,65692.537,-0.1),osg::Vec3d(73100.278,65692.397,-0.1));
osgDB::writeNodeFile(*(mt1.get()),"F:\\12.osg");
osg::ref_ptr<osg::MatrixTransform> mt2=draw.createpline(osg::Vec3d(73100.046,65692.537,-0.1),osg::Vec3d(73101.453,65698.274,-0.1));
osgDB::writeNodeFile(*(mt2.get()),"F:\\13.osg");
root->addChild(mt.get());
root->addChild(mt1.get());
root->addChild(mt2.get()); 3条线衔接的很好。见
保存前
但是在外面同时加载F:\\11.osg F:\\12.osg F:\\13.osg 衔接的不好有距离。
保存后
谁遇到过这种情况。哪儿设置不对?
如何解决? |
|