首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络游戏 >

顶点缓存与索引缓存构建球体的有关问题

2013-01-23 
顶点缓存与索引缓存构建球体的问题想请教一下各位高人,球的索引应该是怎样设置的?想了很久没有头绪,有人说

顶点缓存与索引缓存构建球体的问题
想请教一下各位高人,球的索引应该是怎样设置的?想了很久没有头绪,有人说展开成矩形就明白了,但是笔者愚钝,很难想象把球展开为矩形,如果各位有比较好的理解方法,在此受教了,先谢过。
[解决办法]
说的是在 theta-phi 平面按举行取样吧,然后通过球坐标变换,就能构造出球面的点坐标了,连接顺序也是取样平面中的自然连接顺序。
[解决办法]
你说的贴图应该是UV球体,Icon球体我不会,但是UV球体一些书上附带的源代码以函数的形式介绍了贴图的方法。

// For best results, put this in a display list
// Draw a sphere at the origin
void gltDrawSphere(GLfloat fRadius, GLint iSlices, GLint iStacks)
{
GLfloat drho = (GLfloat)(3.141592653589) / (GLfloat) iStacks;
GLfloat dtheta = 2.0f * (GLfloat)(3.141592653589) / (GLfloat) iSlices;
GLfloat ds = 1.0f / (GLfloat) iSlices;
GLfloat dt = 1.0f / (GLfloat) iStacks;
GLfloat t = 1.0f;
GLfloat s = 0.0f;
GLint i, j;     // Looping variables

for (i = 0; i < iStacks; i++)
{
GLfloat rho = (GLfloat)i * drho;
GLfloat srho = (GLfloat)(sin(rho));
GLfloat crho = (GLfloat)(cos(rho));
GLfloat srhodrho = (GLfloat)(sin(rho + drho));
GLfloat crhodrho = (GLfloat)(cos(rho + drho));

// Many sources of OpenGL sphere drawing code uses a triangle fan
// for the caps of the sphere. This however introduces texturing
// artifacts at the poles on some OpenGL implementations
glBegin(GL_TRIANGLE_STRIP);
s = 0.0f;
for ( j = 0; j <= iSlices; j++)
{
GLfloat theta = (j == iSlices) ? 0.0f : j * dtheta;
GLfloat stheta = (GLfloat)(-sin(theta));
GLfloat ctheta = (GLfloat)(cos(theta));

GLfloat x = stheta * srho;
GLfloat y = ctheta * srho;
GLfloat z = crho;

glTexCoord2f(s, t);
glNormal3f(x, y, z);
glVertex3f(x * fRadius, y * fRadius, z * fRadius);

x = stheta * srhodrho;
y = ctheta * srhodrho;
z = crhodrho;
glTexCoord2f(s, t - dt);
s += ds;
glNormal3f(x, y, z);
glVertex3f(x * fRadius, y * fRadius, z * fRadius);
}
glEnd();

t -= dt;
}
}

这里glTextureCoord2f()函数的参数和DirectX中灵活顶点格式中的UV是一样的。
[解决办法]
要看你画球用的什么算法,球无法想象成矩形,可能和你用的算法有关系。

热点排行