我最近一直在 android 平台上使用 open gl 做一些工作,我一直在关注这个教程 http://blog.jayway.com/2010/02/15/opengl-es-tutorial-for-android-%E2%80%93-part-v/ . 但是,本教程中没有真正解释一件事,那就是什么是索引。所以我的问题是指数是什么意思?他们做什么以及他们如何适应绘制 3D 形状。
最佳答案
通常,您会按照 x, y, z, x, y, z...
的顺序在 float[]
中放置顶点。想象一下,每组 x, y, z
都是数组中的单个元素。索引是新数组中顶点的位置。
假设您有一些简单的正方形的顶点:
float[] vertices = new float[]
{
-x, y, 0, //top left (index 0)
-x, -y, 0, //bottom left (index 1)
x, -y, 0, //bottom right (index 2)
x, y, 0 //top right (index 3)
};
使用索引将正方形绘制为 GL_TRIANGLES
的正确方法是使用索引 0, 1, 2, 0, 2, 3
,其中 0, 1, 2
创建第一个三角形,0, 2, 3
创建第二个三角形。
关于android - Android 上的 OpenGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8767310/