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,
});
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,
});