b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

opengl超级宝典_opengl超级宝典 kindle_opengl红宝书(2)

电脑杂谈  发布时间:2017-01-10 17:59:52  来源:网络整理

上面所存储的数据还不能直接用于OpenGL的顶点数组。因为OpenGL要求顶点数组,法线数组和纹理坐标数组必须是同样的大小,这样数组的遍历方式才能保持一致。顶点数组的第0个元素和法线数组的第0个元素是对应的。对于索引数组也有同样的要求。

在下面的例子中,我们使用一个类来处理现有的数组,并为其建立索引。下面是处理机身和玻璃座舱盖并建立索引的代码:

CTriangleMesh thunderBirdBody;

CTriangleMesh thunderBirdGalss;

//临时空间

M3DVector3f vVerts[3];

M3DVector3f vNorms[3];

M3DVector2f vTex[3];

//开始收集机身的网格,设置最大值

thunderBirdBody.BeginMesh(3074*3);

//循环所有面

for(int iFace = 0; iFace < 3074; iFace++)

{

for(int iPoint = 0; iPoint < 3; iPoint++)
{
    memcpy(&vVerts[iPoint][0], &vertices[face_indices[iFace][iPoint][0]], sizeof(M3DVector3f));

    memcpy(&vNorms[iPoint][0], &normals[face_indices[iFace][iPoint+3][0]], sizeof(M3DVector3f));

    memcpy(&vTex[iPoint][0], &textures[face_indices[iFace][iPoint+6][0]], sizeof(M2DVector2f));
}
thunderBirdBody.AddTriangle(vVerts, vNorms, vTex);

}

//结束,并缩放顶点的值,以便屏幕的显示。

thunderBirdBody.EndMesh();

thunderBirdBody.Scale(fScale);

thunderBirdGlass.BeginMesh(352*3);

for(int iFace = 0; iFace < 352; iFace++)

{

for(int iPoint = 0; iPoint < 3; iPoint++)
{
        memcpy(&vVerts[iPoint][0], &verticesGlass[face_indiciesGlass[iFace][iPoint]][0], sizeof(M3DVector3f));
        memcpy(&vNorms[iPoint][0], &normalsGlass[face_indiciesGlass[iFace][iPoint+3]][0], sizeof(M3DVector3f)); 
        memcpy(&vTex[iPoint][0], &texturesGlass[face_indiciesGlass[iFace][iPoint+6]][0], sizeof(M3DVector2f));
}

thunderBirdGlass.AddTriangle(vVerts, vNorms, vTex);

}

thunderBirdGlass.EndMesh();


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25412-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...