m3g08
Class EmulatingLightSample

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by javax.microedition.lcdui.game.GameCanvas
              extended by m3g08.EmulatingLightSample
All Implemented Interfaces:
Sample

public class EmulatingLightSample
extends javax.microedition.lcdui.game.GameCanvas
implements Sample

Shows alternatives to real lighting.

Author:
Claus Hoefele

Field Summary
private  int currentLighting
          Current lighting mode.
private  javax.microedition.lcdui.Graphics graphics
          2D graphics singleton used for rendering.
private  javax.microedition.m3g.Graphics3D graphics3d
          3D graphics singleton used for rendering.
private static int LIGHTING_BAKED_TEXTURE
          Texture baking.
private static int LIGHTING_DYNAMIC
          Real lighting.
private static int LIGHTING_LIGHT_MAP
          Light map
private static int LIGHTING_VERTEX_COLORS
          Vertex colors.
private  javax.microedition.m3g.Mesh mesh
          Mesh for display.
private  javax.microedition.m3g.Transform meshTransform
          The mesh's transformation.
private static int NUMBER_OF_LIGHTING_MODES
          Number of light modes.
private  float rotY
          Current rotation value.
private static byte[] VERTEX_COLORS
          Vertex colors with lighting information.
 
Fields inherited from class javax.microedition.lcdui.game.GameCanvas
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
EmulatingLightSample()
          Constructor.
 
Method Summary
private  javax.microedition.m3g.Mesh bakedTexture()
          Creates a new mesh with lighting baked into the texture.
private  javax.microedition.m3g.Mesh createMesh(int mode)
          Creates a new mesh according to the given lighting mode.
 void destroy()
          Destroys the sample.
private  void drawMenu(javax.microedition.lcdui.Graphics graphics)
          Draws a menu for the current key assignments.
private  javax.microedition.m3g.Mesh dynamicLight()
          Creates a new mesh for real lighting.
 void init()
          Initializes the sample.
protected  void keyPressed(int keyCode)
          Handles key presses.
private  javax.microedition.m3g.Mesh lightMap()
          Creates a new mesh with a light map applied.
private  void render(javax.microedition.lcdui.Graphics graphics)
          Renders the sample.
private  javax.microedition.m3g.Mesh vertexColors()
          Creates a new mesh with lighting information in the vertex colors.
 
Methods inherited from class javax.microedition.lcdui.game.GameCanvas
flushGraphics, flushGraphics, getGraphics, getKeyStates, paint
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mesh

private javax.microedition.m3g.Mesh mesh
Mesh for display.


meshTransform

private javax.microedition.m3g.Transform meshTransform
The mesh's transformation.


rotY

private float rotY
Current rotation value.


LIGHTING_BAKED_TEXTURE

private static final int LIGHTING_BAKED_TEXTURE
Texture baking.

See Also:
Constant Field Values

LIGHTING_VERTEX_COLORS

private static final int LIGHTING_VERTEX_COLORS
Vertex colors.

See Also:
Constant Field Values

LIGHTING_LIGHT_MAP

private static final int LIGHTING_LIGHT_MAP
Light map

See Also:
Constant Field Values

LIGHTING_DYNAMIC

private static final int LIGHTING_DYNAMIC
Real lighting.

See Also:
Constant Field Values

NUMBER_OF_LIGHTING_MODES

private static final int NUMBER_OF_LIGHTING_MODES
Number of light modes.

See Also:
Constant Field Values

currentLighting

private int currentLighting
Current lighting mode.


graphics3d

private javax.microedition.m3g.Graphics3D graphics3d
3D graphics singleton used for rendering.


graphics

private javax.microedition.lcdui.Graphics graphics
2D graphics singleton used for rendering.


VERTEX_COLORS

private static final byte[] VERTEX_COLORS
Vertex colors with lighting information.

Constructor Detail

EmulatingLightSample

public EmulatingLightSample()
Constructor.

Method Detail

init

public void init()
Initializes the sample.

Specified by:
init in interface Sample

destroy

public void destroy()
Destroys the sample.

Specified by:
destroy in interface Sample

createMesh

private javax.microedition.m3g.Mesh createMesh(int mode)
Creates a new mesh according to the given lighting mode.

Parameters:
mode - lighting mode.
Returns:
mesh.

lightMap

private javax.microedition.m3g.Mesh lightMap()
Creates a new mesh with a light map applied.

Returns:
mesh mesh with light map.

bakedTexture

private javax.microedition.m3g.Mesh bakedTexture()
Creates a new mesh with lighting baked into the texture.

Returns:
mesh mesh.

vertexColors

private javax.microedition.m3g.Mesh vertexColors()
Creates a new mesh with lighting information in the vertex colors.

Returns:
mesh mesh with vertex colors.

dynamicLight

private javax.microedition.m3g.Mesh dynamicLight()
Creates a new mesh for real lighting.

Returns:
mesh mesh for real lighting.

render

private void render(javax.microedition.lcdui.Graphics graphics)
Renders the sample.

Parameters:
graphics - graphics context for drawing.

keyPressed

protected void keyPressed(int keyCode)
Handles key presses.

Overrides:
keyPressed in class javax.microedition.lcdui.Canvas
Parameters:
keyCode - key code.

drawMenu

private void drawMenu(javax.microedition.lcdui.Graphics graphics)
Draws a menu for the current key assignments.

Parameters:
graphics - graphics context for drawing.