Java Reference
In-Depth Information
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
mCanvas.stop();
}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exitCommand) {
try {
destroyApp(false);
notifyDestroyed();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
}
Lights, Camera, Action!
Creating a 3D scene is like shooting a film on a movie set. You need to create the objects to
render, orchestrate their movement, set up light(s), and set up camera(s). The M3G API comes
with a full set of classes to support this staging.
You can manually create the objects that will be rendered. In Listing 15-1, this involves the
definition of the triangle and the rotation. The M3G engine needs to be informed of where the
triangle is and what sort of appearance it should take on.
Defining Triangle Vertices
In Listing 15-1, the position of the initial triangle is specified in a VertexArray by the
following code:
short[] vertices = { 0, 0, 0, 3, 0, 0, 0, 3, 0 };
VertexArray vertexArray = new VertexArray(vertices.length / 3, 3, 2);
vertexArray.set(0, vertices.length/3, vertices);
A VertexArray is an M3G class that holds an array of triplets— (x,y,z) . The elements of the
array may represent vertex position, normals, texture, or color coordinates. Many methods in
M3G take VertexArray as an input argument. In Listing 15-1, it holds the three vertices of
the triangle.
There are two set() methods for VertexArray :
void set(int firstVertex, int numVertices, byte[] values);
void set(int firstVertex, int numVertices, short[] values);
Search WWH ::




Custom Search