thunderBirdGlass.Scale(fScale);
首先,我们声明了两个三角形网格类
CTriangleMesh thunderBirdBody;
CTriangleMesh thunderBirdGalss;
然后我们要告诉包含所有顶点所需要的大小的最大值,在最坏的情况下我们可能有3074个唯一的顶点,但一般情况下,许多顶点是共享的,值是一样的。
thunderBirdBody.BeginMesh(3074*3);
然后遍历集体所有的面,并收集每一个独立的三角形,并作为AddTriangle的参数,AddTriagnle会组织索引数组。opengl超级宝典在AddTriangle函数中把传进来的参数与之前的顶点数据进行比较看是否有重复的。如果是重复的在索引数组中就用同一个索引值。opengl超级宝典其内部处理代码:
for(GLuint iVertex = 0; iVertex < 3; iVertex++)
{
GLuint iMatch = 0;
for(iMatch = 0; iMatch < nNumVerts; iMatch++)
{
// If the vertex positions are the same
if(m3dCloseEnough(pVerts[iMatch][0], verts[iVertex][0], e) &&
m3dCloseEnough(pVerts[iMatch][1], verts[iVertex][1], e) &&
m3dCloseEnough(pVerts[iMatch][2], verts[iVertex][2], e) &&
// AND the Normal is the same...
m3dCloseEnough(pNorms[iMatch][0], vNorms[iVertex][0], e) &&
m3dCloseEnough(pNorms[iMatch][1], vNorms[iVertex][1], e) &&
m3dCloseEnough(pNorms[iMatch][2], vNorms[iVertex][2], e) &&
// And Texture is the same...
m3dCloseEnough(pTexCoords[iMatch][0], vTexCoords[iVertex][0], e) &&
m3dCloseEnough(pTexCoords[iMatch][1], vTexCoords[iVertex][1], e))
{
// Then add the index only
pIndexes[nNumIndexes] = iMatch;
nNumIndexes++;
break;
}
}
// No match for this vertex, add to end of list
if(iMatch == nNumVerts)
{
memcpy(pVerts[nNumVerts], verts[iVertex], sizeof(M3DVector3f));
memcpy(pNorms[nNumVerts], vNorms[iVertex], sizeof(M3DVector3f));
memcpy(pTexCoords[nNumVerts], &vTexCoords[iVertex], sizeof(M3DVector2f));
pIndexes[nNumIndexes] = nNumVerts;
nNumIndexes++;
nNumVerts++;
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25412-3.html
相信通过杨洋不懈的努力和追求
呵呵在南海说自由我们有权利自由
有些人不打他是认为你好欺负的