|
|
关于md2文件的渲染,我看到有一个引擎是这样画读入的md2三角形顶点数据的。
while(val != 0)
{
int count;
if(val > 0)
{
glBegin(GL_TRIANGLE_STRIP);
count = val;
}
else
{
glBegin(GL_TRIANGLE_FAN);
count = -val;
}
while(count--)
{
***********************************************************
float s = *(float*)&glCommands[i++];
float t = *(float*)&glCommands[i++];
int index = glCommands[i++];
glTexCoord2f(s , t);
***********************************************************
x1 = m_pFrames[currFrame].m_pVertices[index].m_fVert[0];
y1 = m_pFrames[currFrame].m_pVertices[index].m_fVert[1];
z1 = m_pFrames[currFrame].m_pVertices[index].m_fVert[2];
x2 = m_pFrames[nextFrame].m_pVertices[index].m_fVert[0];
y2 = m_pFrames[nextFrame].m_pVertices[index].m_fVert[1];
z2 = m_pFrames[nextFrame].m_pVertices[index].m_fVert[2];
glVertex3f((x1 + fInterpolation * (x2 - x1)) , (y1 + fInterpolation * (y2 - y1)) , (z1 + fInterpolation * (z2 - z1)));
}
glEnd();
val = glCommands[i++];
}
我前几天买了你出的《学OpenGL编3D游戏》,可是我看了半天,怎么这个读取md2显示的代码和您的相差这么多啊?而且结果两个都对,我已经验证了。尤其是两行星号之间的代码我更不明白,为什么这个glCommand这么厉害?好像它还包含了纹理坐标,既然这里面包含着纹理坐标,那md2头文件里自带的纹理坐标又还有什么用。我说的这个例子真的是根本就没用纹理坐标这个变量,而是直接从md2文件的头文件里接收的glCommand参数中包含的纹理坐标。
那么这个glCommand参数在 md2文件中到底是干什么的?怎么这么神通广大?
我在别的论坛问了,但可能都没有知道的,所以来请教你。 |
|