|
楼主 |
发表于 2011-6-1 09:51:37
|
显示全部楼层
源程序获取坐标的程序我没有改动。
int i, j;
float lev[] = { -5, -1.0, 1.0, 15.0, 30.0, 60.0, 90.0 };
float x, y, z;
float alpha, theta;
float radius = 20.0f;
int nlev = sizeof( lev )/sizeof(float);
osg::ref_ptr<osg::Geometry> geom = new Geometry;
Vec3Array& coords = *(new Vec3Array(19*nlev)); //顶点数组
Vec2Array& tcoords = *(new Vec2Array(19*nlev)); //纹理坐标数组
int ci = 0;
for( i = 0; i < nlev; i++ )
{
for( j = 0; j <= 18; j++ )
{
//转换为角度
alpha = osg:egreesToRadians(lev[i]);
theta = osg::DegreesToRadians((float)(j*20));
//计算顶点的alpha,theta角
x = radius * cosf( alpha ) * cosf( theta );
y = radius * cosf( alpha ) * -sinf( theta );
z = radius * sinf( alpha );
coords[ci][0] = x;
coords[ci][1] = y;
coords[ci][2] = z;
//纹理坐标
tcoords[ci][0] = (float)j/18.0;
tcoords[ci][1] = (float)i/(float)(nlev-1);
ci++;
}
}
另外问一句,下面这段程序是做什么的,没看懂
for( i = 0; i < nlev-1; i++ )
{
DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
drawElements->reserve(38);
for( j = 0; j <= 18; j++ )
{
drawElements->push_back((i+1)*19+j);
drawElements->push_back((i+0)*19+j);
}
geom->addPrimitiveSet(drawElements);
} |
|