Java Reference
In-Depth Information
Defining Triangle Strips for the Corner Submesh
The corner of the cube is defined as three separate triangle strips. The vertices for these strips
are specified in the same vertex buffer and loaded into the M3G rendering engine via an index
buffer—the TriangleStripArray . The TriangleStripArray keeps track of where one strip ends
and another starts.
The vertices for each of the strips are as follows:
Strip 1 (square in the x-y plane): (0,0,0) , (3,0,0) , (0,3,0) , (3,3,0)
Strip 2 (square in the y-z plane): (3,0,0) , (3,3,0) , (3,0,-3) , (3,3,-3)
Strip 3 (square in the x-z plane): (0,0,0) , (3,0,0) , (0,0,-3) , (3,0,-3)
The code to create the vertexArray in Listing 15-3 is shown here:
short[] vertices = {
0, 0, 0, 3, 0, 0, 0, 3, 0, 3, 3, 0,
3, 0, 0, 3, 3, 0, 3, 0, -3, 3, 3, -3,
0, 0, 0, 3, 0, 0, 0, 0, -3, 3, 0, -3
};
VertexArray vertexArray = new VertexArray(vertices.length / 3, 3, 2);
vertexArray.set(0, vertices.length/3, vertices);
Corresponding to the vertices, the normals are defined as follows:
byte[] normals = {
0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
0, -127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0
};
VertexArray normalsArray = new VertexArray(normals.length / 3, 3, 1);
normalsArray.set(0, normals.length/3, normals);
Texture Mapping the Cube Exterior
To make the exterior of the cube take on a brick-like appearance, texture mapping will be used.
Texture mapping is the action of painting a texture (an image) over a 3D surface, like using
wrapping paper to wrap a gift.
Obviously, you will first need an image that represents a texture. M3G has the Image3D
class, which can be used in a texture. Here is one of the constructors for Image3D :
public Image2D(int format, Object image);
The format parameter to the constructor can be one of the following:
Image2D.RGB
Image2D.RGBA
Image2D.ALPHA
Image2D.LUMINANCE
Image2D.LUMINANCE_ALPHA
Search WWH ::




Custom Search