|
楼主 |
发表于 2012-11-6 09:03:47
|
显示全部楼层
array 发表于 2012-11-5 09:41
您什么信息也没有给出来。。。
这是生成云图主干代码,全部代码放在附件里面了,麻烦您知道知道,,呵呵
osg::ref_ptr<osg::Geometry> create()
{
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array();
osg::ref_ptr<osg::Vec4Array> vc = new osg::Vec4Array();
//计算顶点数组的大小
unsigned int n = sizeof(vertex)/sizeof(float[4]);
//求数组差值最大最小值
float max;
float min;
float number = 12;
max = maxed(vertex,n);
min = mined(vertex,n);
float mm = (max-min)/number;
//添加顶点数据
for( unsigned int i = 0; i < n; i++ )
{
coords->push_back( osg::Vec3(vertex[0], vertex[1], vertex[2] ));
if (vertex[3]<=(min+number*mm/4))
{
vc->push_back(osg::Vec4(0.0f,1.0f*255*(vertex[3]-min)/(number*mm/4),1.0f,1.0f));
}
if (vertex[3]>min+number*mm/4 && vertex[3]<=min+number*mm/2)
{
vc->push_back(osg::Vec4(1.0f,1.0f,1.0f*(255-255*(vertex[3]-(min+number*mm/4))/(number*mm/4)),1.0f));
}
if (vertex[3]>min+number*mm/2 && vertex[3]<=min+number*mm*3/4)
{
vc->push_back(osg::Vec4(1.0f*255*(vertex[3]-(min+number*mm/2))/(number*mm/4),1.0f,1.0f,1.0f));
}
if (vertex[3] > min+number*mm*3/4 && vertex[3]<=max)
{
vc->push_back(osg::Vec4(1.0f,1.0f*(255-255*(vertex[3]-(min+number*mm*3/4))/(number*mm/4)),0.0f,1.0f));
}
}
osg::TemplateIndexArray<unsigned int ,osg::Array::UIntArrayType,4,4>* colorIndex = new osg::TemplateIndexArray<unsigned int ,osg::Array::UIntArrayType,4,4>();
for (unsigned int i=0;i<n;i++)
{
colorIndex->push_back(i);
}
//创建几何体
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
//设置顶点数组
geometry->setVertexArray(coords.get());
geometry->setColorArray(vc.get());
geometry->setColorIndices(colorIndex);
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
//设置法线
/*osg::ref_ptr<osg::Vec3Array> nc = new osg::Vec3Array();
nc->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
geometry->setNormalArray(nc.get());
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);*/
//创建Delaunay三角网对象
osg::ref_ptr<osgUtil:elaunayTriangulator> dt = new osgUtil::DelaunayTriangulator(coords.get());
//生成三角网
dt->triangulate();
//加入到绘图基元
geometry->addPrimitiveSet(dt->getTriangles());
/*geometry->addPrimitiveSet(new osg::DrawArrays(osg:rimitiveSet:UADS,0,n));*/
//添加到叶节点
/*osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable( geometry.get());
return geode.get();*/
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
geometry->setStateSet(stateset.get());
return geometry.get();
} |
|