Android OpenGL ES 3D空间与glDrawArrays
1.四棱锥: 由4个三角形构成。
四方体: 由6个三角形构成。
难点:在构建3D空间的顶点坐标时,要让对象绕自身的轴旋转,必须让对象的中心坐标总是(0.0f,0.0f,0.0f),
并且三角形都是按逆时针次序绘制的。
2.3D空间的绘制:
GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count);
参数说明:
mode,绘制方式,OpenGL2.0以后提供以下参数:GL_POINTS、GL_LINES、GL_LINE_LOOP、GL_LINE_STRIP、GL_TRIANGLES、GL_TRIANGLE_STRIP、GL_TRIANGLE_FAN。
first,从数组缓存中的哪一位开始绘制,一般为0。
count,数组中顶点的数量。
3.绘制顶点数组:
//绘制三角锥
for(int i=0; i<4; i++)
{
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*3, 3);
}
//绘制四方体
for(int i=0; i<6; i++)
{
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*4, 4);
}
[附]构建顶点数组:
[java]
int one = 0x10000;
// 四棱锥顶点数组:
private IntBuffer triggerBuffer = IntBuffer.wrap(new int[]{
0,one,0,
-one,-one,0,
one,-one,one,
0,one,0,
one,-one,one,
one,-one,-one,
0,one,0,
one,-one,-one,
-one,-one,-one,
0,one,0,
-one,-one,-one,
-one,-one,one
});
// 四方体顶点数组:
private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{
one,one,-one,
-one,one,-one,
one,one,one,
-one,one,one,
one,-one,one,
-one,-one,one,
one,-one,-one,
-one,-one,-one,
one,one,one,
-one,one,one,
one,-one,one,
-one,-one,one,
one,-one,-one,
-one,-one,-one,
one,one,-one,
-one,one,-one,
-one,one,one,
-one,one,-one,
-one,-one,one,
-one,-one,-one,
one, one, -one,
one, one, one,
one, -one, -one,
one, -one, one,
});
补充:移动开发 , Android ,