|
写一个类,该类实现将模型顶点的高程放大为原来两倍的功能,代码如下:
class modelvertices: public osg::NodeCallback
{
modelvertices::modelvertices(void)
{
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
}
modelvertices::~modelvertices(void)
{
}
void modelvertices::apply( osg::Geode& geode )
{
for (unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Geometry* geom=dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
if(!geom)
continue;
osg::Vec3Array* verts=dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
if(!verts)
continue;
osg::Vec3Array* verts2=new osg::Vec3Array;
for (osg::Vec3Array::iterator iter=verts->begin();iter!=verts->end();iter++)
{
//std::cout<<iter->x()<<" "<<iter->y()<<" "<<iter->z()<<std::endl;
iter->z()=iter->z()*2;//高程放大为原来两倍
osg::Vec3 aa=*iter;
verts2->push_back(aa);
}
geom->setVertexArray(verts2);
geom->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet::POINTS,0,verts2->size()));//注意,该处不能使用setPrimitiveSet()函数
}
}
}; |
|