|
本帖最后由 ccy_ccy2001 于 2011-1-7 21:06 编辑
如图
a,b,c三点为鼠标点击获得的点,a1,a2,b1,b2,c1,c2为通过a,b,c计算出来的,现在想通过OSG中Delaunay生成三角网格,代码如下:- osg::Geode* OsgWidget::creatDelaunay(std::vector<osg::Vec3f>vertex)
- {
- //创建顶点数组
- osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array();
- //计算顶点数组的大小
- unsigned int n = vertex.size();
- //添加顶点数据
- for( unsigned int i = 0; i < n; i++ )
- {
- coords->push_back( vertex );
- }
- //创建Delaunay三角网对象
- osg::ref_ptr<osgUtil:elaunayTriangulator> dt = new osgUtil:elaunayTriangulator(coords.get());
- //生成三角网
- dt->triangulate();
- //创建几何体
- osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
- //设置顶点数组
- geometry->setVertexArray(coords.get());
- //加入到绘图基元
- geometry->addPrimitiveSet(dt->getTriangles());
- //添加纹理
- std::string roadTexture(std::string("../data/texture/2-road.jpg"));
- osg::Image* image = osgDB::readImageFile( roadTexture );
- if (image)
- {
- const unsigned int decalTex = 0;
- osg::StateSet* stateset = new osg::StateSet;
- osg::Texture2D* texture = new osg::Texture2D;
- texture->setImage(image);
- texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
- texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
- stateset->setTextureAttributeAndModes(decalTex, texture, osg::StateAttribute::ON);
- osg::TexEnv* texenv = new osg::TexEnv;
- texenv->setMode(osg::TexEnv::BLEND);
- texenv->setColor(osg::Vec4(0.8f,0.8f,0.8f,0.8f));
- stateset->setTextureAttribute(decalTex, texenv);
- geometry->setStateSet(stateset);
- }
- //添加到叶节点
- osg::Geode* geode = new osg::Geode();
- geode->addDrawable( geometry.get());
- return geode;
- }
复制代码 将a1,a2,b1,b2,c1,c2存入coords中,但是现在生成的下图
所示,请问如何才能生成第一个图那种 网格呢 ? |
|