Game Development Reference
In-Depth Information
The constructor takes the input vertices in the form of a float array and creates a FloatBuffer. The
FloatBuffer is originally created as a ByteBuffer. A ShortBuffer is created from the input short array
vertex index list.
If the UV texture offset is negative, there are no texture coordinates. If it is 0 or greater, there are
texture coordinates. If the Normal offset is negative, there are no vertex normals. If it is greater or
equal to 0, there are vertex normals. Thus, you can have a vertex with or without texture or lighting
information.
Note FloatBuffer, ShortBuffer, and ByteBuffer are standard Android classes. You can find out more about
them on the official Android developer's web site.
Listing 4-32. The MeshEx Constructor
public MeshEx(int CoordsPerVertex,
int MeshVerticesDataPosOffset,
int MeshVerticesUVOffset,
int MeshVerticesNormalOffset,
float[] Vertices,
short[] DrawOrder)
{
m_CoordsPerVertex = CoordsPerVertex;
m_MeshVerticesDataStrideBytes = m_CoordsPerVertex * FLOAT_SIZE_BYTES;
m_MeshVerticesDataPosOffset = MeshVerticesDataPosOffset;
m_MeshVerticesDataUVOffset = MeshVerticesUVOffset ;
m_MeshVerticesDataNormalOffset = MeshVerticesNormalOffset;
if (m_MeshVerticesDataUVOffset >= 0)
{
m_MeshHasUV = true;
}
if (m_MeshVerticesDataNormalOffset >=0)
{
m_MeshHasNormals = true;
}
// Allocate Vertex Buffer
ByteBuffer bb = ByteBuffer.allocateDirect(
// (Number of coordinate values * 4 bytes per float)
Vertices.length * FLOAT_SIZE_BYTES);
bb.order(ByteOrder.nativeOrder());
m_VertexBuffer = bb.asFloatBuffer();
Search WWH ::




Custom Search