m3g12
Class SkinnedMeshSample

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by javax.microedition.lcdui.game.GameCanvas
              extended by m3g12.SkinnedMeshSample
All Implemented Interfaces:
java.lang.Runnable, Sample

public class SkinnedMeshSample
extends javax.microedition.lcdui.game.GameCanvas
implements Sample, java.lang.Runnable

SkinnedMesh animation that bends a skeleton with an adjustable number of bones.

Author:
Claus Hoefele

Field Summary
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  boolean isRunning
          Flag whether thread is running.
private  int lastKey
          Stores the last game action key.
private  int numBones
          Number of bones for skeleton.
private  javax.microedition.m3g.Mesh skin
          Representation of the skin.
private  javax.microedition.m3g.SkinnedMesh skinnedMesh
          Mesh with skin and skeleton.
private  javax.microedition.m3g.AnimationTrack track
          Bone animation.
private  boolean twoBonesPerVertex
          Enables vertices to share two bones.
 
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
SkinnedMeshSample()
          Constructor.
 
Method Summary
private  void attachAnimation(javax.microedition.m3g.SkinnedMesh skinnedMesh, javax.microedition.m3g.AnimationTrack track)
          Attaches the animation to the bones of the SkinnedMesh's skeleton.
private  javax.microedition.m3g.SkinnedMesh attachSkin(javax.microedition.m3g.Mesh skin, javax.microedition.m3g.Group skeleton, int numBones, boolean twoBonesPerVertex)
          Attaches skin to skeleton to create a SkinnedMesh.
private  void checkKeys(int worldTime)
          Processes key presses.
private  javax.microedition.m3g.AnimationTrack createAnimation()
          Creates a new animation that interpolates between two orientations.
private  javax.microedition.m3g.Group createSkeleton(int numBones)
          Creates a hierarchy of Groups that serves as skeleton.
private  javax.microedition.m3g.Mesh createSkin(int subdivisions)
          Creates a new rectangular mesh that serves as skin.
 void destroy()
          Destroys the sample.
private  void drawMenu(javax.microedition.lcdui.Graphics graphics)
          Draws a menu for the current key assignments.
 void init()
          Initializes the sample.
protected  void keyPressed(int keyCode)
          Receives key presses.
private  void render(javax.microedition.lcdui.Graphics graphics)
          Renders the sample.
private  void reset()
          Initializes the sample.
 void run()
          Animation loop.
 
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, setCommandListener, setFullScreenMode, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

skin

private javax.microedition.m3g.Mesh skin
Representation of the skin.


skinnedMesh

private javax.microedition.m3g.SkinnedMesh skinnedMesh
Mesh with skin and skeleton.


track

private javax.microedition.m3g.AnimationTrack track
Bone animation.


numBones

private int numBones
Number of bones for skeleton.


twoBonesPerVertex

private boolean twoBonesPerVertex
Enables vertices to share two bones.


isRunning

private boolean isRunning
Flag whether thread is running.


lastKey

private int lastKey
Stores the last game action key.


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.

Constructor Detail

SkinnedMeshSample

public SkinnedMeshSample()
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

run

public void run()
Animation loop.

Specified by:
run in interface java.lang.Runnable

reset

private void reset()
Initializes the sample.


createSkin

private javax.microedition.m3g.Mesh createSkin(int subdivisions)
Creates a new rectangular mesh that serves as skin.

Parameters:
subdivisions - number of vertical subdivisions.
Returns:
mesh.

createSkeleton

private javax.microedition.m3g.Group createSkeleton(int numBones)
Creates a hierarchy of Groups that serves as skeleton.

Parameters:
numBones - number of bones.
Returns:
skeleton.

attachSkin

private javax.microedition.m3g.SkinnedMesh attachSkin(javax.microedition.m3g.Mesh skin,
                                                      javax.microedition.m3g.Group skeleton,
                                                      int numBones,
                                                      boolean twoBonesPerVertex)
Attaches skin to skeleton to create a SkinnedMesh.

Parameters:
skin - mesh used as skin.
skeleton - hierarchy used as skeleton.
numBones - number of bones.
twoBonesPerVertex - enables vertices to share bones.
Returns:
SkinnedMesh.

createAnimation

private javax.microedition.m3g.AnimationTrack createAnimation()
Creates a new animation that interpolates between two orientations.

Returns:
animation track.

attachAnimation

private void attachAnimation(javax.microedition.m3g.SkinnedMesh skinnedMesh,
                             javax.microedition.m3g.AnimationTrack track)
Attaches the animation to the bones of the SkinnedMesh's skeleton.

Parameters:
skinnedMesh - mesh with skeleton.
track - animation track.

keyPressed

protected void keyPressed(int keyCode)
Receives key presses.

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

checkKeys

private void checkKeys(int worldTime)
Processes key presses.

Parameters:
worldTime - current world time.

render

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

Parameters:
graphics - graphics context for drawing.

drawMenu

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

Parameters:
graphics - graphics context for drawing.