Game Development Reference
In-Depth Information
A new variable is also added of MeshType called m_MeshType .
private MeshType m_MeshType;
In the MeshEx() constructor, the type of mesh to draw is defaulted to triangles.
m_MeshType = MeshType.Triangles;
Functions to set and retrieve the type of mesh being drawn are also added.
void SetMeshType(MeshType Type){m_MeshType = Type;}
MeshType GetMeshType() {return m_MeshType;}
In the DrawMesh() function, we add and change the code to actually draw the mesh. We draw either
triangles or lines, based on the value of m_MeshType . (See Listing 5-23.)
Listing 5-23. Code to Draw Either Triangles or Lines
if (m_MeshType == MeshType.Triangles)
{
GLES20.glDrawElements( GLES20.GL_TRIANGLES ,
m_DrawListBuffer.capacity(),
GLES20.GL_UNSIGNED_SHORT,
m_DrawListBuffer);
}
else
if (m_MeshType == MeshType.Lines)
{
GLES20.glDrawElements( GLES20.GL_LINES ,
m_DrawListBuffer.capacity(),
GLES20.GL_UNSIGNED_SHORT,
m_DrawListBuffer);
}
The GravityGridEx Class
Next, we create a new class called GravityGridEx. This is the class that represents the gravity grid
that our objects will be placed on.
The actual grid object is of type MeshEx and is called m_LineMeshGrid .
private MeshEx m_LineMeshGrid;
The vertex data for the grid has to be defined. The number of coordinates per vertex is 3, which are
the x, y, and z values of the point location for the grid.
private int m_CoordsPerVertex = 3;
The offset into the vertex array to the vertex position data is 0.
private int m_MeshVerticesDataPosOffset = 0;
 
Search WWH ::




Custom Search