Game Development Reference
In-Depth Information
you will have to add three more vertex data entries for this new triangle. Because more complex
graphics are made up of many triangles, you will obviously have to add more triangles to the vertex
data for a complex object.
Listing 7-1. A Triangle Defined for a Mesh Class
// Left Side u v nx, ny, nz
-1.5f, -1.5f, -1.5f, 0, 1, -1, -1, -1, // v0 = left, bottom, back
-1.5f, -1.5f, 1.5f, 1, 1, -1, -1, 1, // v1 = left, bottom, front
0.0f, 3.2f, 0.0f, 0.5f, 0, 0, 1, 0, // v2 = top point
The DrawMesh() function draws the mesh and is similar to the corresponding function in the MeshEx
class. The key difference is that the OpenGL function glDrawArrays() is used to draw the mesh
instead of glDrawElements() . (See Listing 7-2.)
The glDrawArrays() function takes as parameters in sequence:
The graphics primitive to draw, in this case GL_TRIANGLES
1.
2.
The number of the starting vertex to draw
3.
The number of vertices to draw
Listing 7-2. The DrawMesh Function
void DrawMesh(int PosHandle, int TexHandle, int NormalHandle)
{
SetUpMeshArrays(PosHandle, TexHandle, NormalHandle);
// Draw the triangle
//glDrawArrays (int mode, int first, int count)
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, m_VertexCount);
// Disable vertex array
GLES20.glDisableVertexAttribArray(PosHandle);
if (m_MeshHasUV)
{
GLES20.glDisableVertexAttribArray(TexHandle);
}
if (m_MeshHasNormals)
{
GLES20.glDisableVertexAttribArray(NormalHandle);
}
}
Modifying the Object3d Class
Next, the Object3d class needs to be modified to use the Mesh class.
A new Mesh class variable, m_Mesh , is added.
private Mesh m_Mesh = null;
 
Search WWH ::




Custom Search