|
void MyHandle::createField(double h)
{
unsigned int a=(unsigned int )(_point._v[0]+INTERVAL/2)/INTERVAL;//四舍五入
unsigned int b=(unsigned int )(_point._v[1]+INTERVAL/2)/INTERVAL;//a,b用作圆心
unsigned int radio=(unsigned int)RADIO/INTERVAL;//用作半径
osg::ref_ptr<osg::Vec3Array> v=dynamic_cast<osg::Vec3Array *>(_geometry->getVertexArray());
osg::Vec2Array* gridPoint=new osg::Vec2Array(360*radio);
for (int i=0;i!=radio;i++)//圆面上的点 由最外层向圆心 依次加入到array中
{
for (unsigned int degree=0;degree<360;degree++)
{
double x=a+(radio-i)*cosf(degree*osg:I/180);//圆的x坐标,x范围[0,100)
double y=b+(radio-i)*sinf(degree*osg::PI/180);
unsigned int temp_COLUMN=COLUMN-1;
if (x<0) x=0;
if (x>temp_COLUMN) x=temp_COLUMN;
if (y<0) y=0;
if (y>temp_COLUMN) y=temp_COLUMN;
(*gridPoint)[360*i+degree].set((unsigned int)x,(unsigned int)y);
}
}
for (int i=0;i!=radio;i++)
{
for (int n=0;n<360;n++)
{
unsigned int x=(*gridPoint)[360*i+n].x();
unsigned int y=(*gridPoint)[360*i+n].y();
int temp=x*COLUMN+y;
double temp_z=(*v)[temp].z();
float hudu;
hudu=float(i)/(float)radio;
(*v)[temp].set(x*INTERVAL,y*INTERVAL,h);//平台
}
}
//v->dirty();
_geometry->setVertexArray(v);
}
调用上面的函数,内存会不断上升,不理解……
恳请赐教,不胜感激 |
|