Java Reference
In-Depth Information
The length of the TriangleStripArray instance also needs to be changed:
int[] stripLength = { 4};
mIndexBuffer = new TriangleStripArray( 0, stripLength );
Make the preceding modifications to the TriangleCanvas code, and rebuild and run it. You
will see a red square rotating instead of a triangle. Using the same technique, you can create
and rotate any abitrary polygon.
Rotating a 3D Corner Piece
The second example is actually an evolution of the TriangleMIDlet . It rotates a section of a
cube in 3D. Try this out by running the CornerMIDlet example. When you copy over the source
files, make sure you have included the texture.png file and placed it into the res directory of
the WTK application. Figure 15-8 shows the CornerMIDlet running.
Figure 15-8. CornerMIDlet rotating the corner of a cube
In Figure 15-8, you see the corner of a cube that has a brick exterior being rotated in 3D.
The code to perform this rotation is in the CornerCanvas class, which has the exact same general
structure as TriangleMIDlet . The source code of CornerCanvas is shown in Listing 15-3.
Listing 15-3. CornerCanvas—Rotating a Texture-Mapped Cube
import javax.microedition.lcdui.*;
import javax.microedition.m3g.*;
import javax.microedition.lcdui.game.*;
public class CornerCanvas extends GameCanvas implements Runnable {
private boolean mRunning = false;
private Thread mPaintThrd = null;
 
Search WWH ::




Custom Search