m3g05
Class WireframeEngine

java.lang.Object
  extended by m3g05.WireframeEngine

public class WireframeEngine
extends java.lang.Object

Wireframe engine that displays 3D models as line drawings. It uses M3G's matrix operations to transform 3D vertex coordinates to a 2D screen representation and draws the model on a MIDP graphics context.

Author:
Claus Hoefele
See Also:
WireframeSample

Field Summary
private  javax.microedition.m3g.Camera camera
          Camera object that represents the viewer of the 3D scene.
private  int halfViewportHeight
          Half the viewport height.
private  int halfViewportWidth
          Half the viewport width.
private  javax.microedition.m3g.Transform invertedCameraTransform
          Transformation for camera.
private  int viewportX
          Viewport x.
private  int viewportY
          Viewport y.
 
Constructor Summary
WireframeEngine(int viewportX, int viewportY, int viewportWidth, int viewportHeight)
          Creates a new WireframeEngine with the given viewport attributes.
 
Method Summary
protected  void draw(javax.microedition.lcdui.Graphics graphics, float[] vertices, int[] triangleIndices, int[] triangleLengths)
          Draws a wireframe model on the given graphics context.
 void render(javax.microedition.lcdui.Graphics graphics, javax.microedition.m3g.Mesh mesh, javax.microedition.m3g.Transform meshTransform, int[] triangleIndices, int[] triangleLengths)
          Renders a 3D model as wireframe.
 void setCamera(javax.microedition.m3g.Camera camera, javax.microedition.m3g.Transform cameraTransform)
          Sets the camera that's used to represent the viewer of the scene.
protected  float[] transform(javax.microedition.m3g.Mesh mesh, javax.microedition.m3g.Transform meshTransform, javax.microedition.m3g.Camera camera, javax.microedition.m3g.Transform invertedCameraTransform)
          Transforms vertices from 3D to 2D.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewportX

private int viewportX
Viewport x.


viewportY

private int viewportY
Viewport y.


halfViewportWidth

private int halfViewportWidth
Half the viewport width.


halfViewportHeight

private int halfViewportHeight
Half the viewport height.


camera

private javax.microedition.m3g.Camera camera
Camera object that represents the viewer of the 3D scene.


invertedCameraTransform

private javax.microedition.m3g.Transform invertedCameraTransform
Transformation for camera.

Constructor Detail

WireframeEngine

public WireframeEngine(int viewportX,
                       int viewportY,
                       int viewportWidth,
                       int viewportHeight)
Creates a new WireframeEngine with the given viewport attributes. The viewport defines the size and position of the rendered image.

Parameters:
viewportX - viewport x position.
viewportY - viewport y position.
viewportWidth - viewport width.
viewportHeight - viewport height.
Method Detail

setCamera

public void setCamera(javax.microedition.m3g.Camera camera,
                      javax.microedition.m3g.Transform cameraTransform)
Sets the camera that's used to represent the viewer of the scene.

Parameters:
camera - camera.
cameraTransform - camera transformation.

render

public void render(javax.microedition.lcdui.Graphics graphics,
                   javax.microedition.m3g.Mesh mesh,
                   javax.microedition.m3g.Transform meshTransform,
                   int[] triangleIndices,
                   int[] triangleLengths)
Renders a 3D model as wireframe.

Parameters:
graphics - graphics context used for drawing.
mesh - mesh to be drawn.
meshTransform - the mesh's transformation.
triangleIndices - triangle indices that define how to draw the model.
triangleLengths - lengths of the triangle array.

transform

protected float[] transform(javax.microedition.m3g.Mesh mesh,
                            javax.microedition.m3g.Transform meshTransform,
                            javax.microedition.m3g.Camera camera,
                            javax.microedition.m3g.Transform invertedCameraTransform)
Transforms vertices from 3D to 2D.

Parameters:
mesh - mesh to be transformed.
invertedCameraTransform - inverted camera transformation.
meshTransform - the mesh's transformation.
camera - camera object that represents the viewer of the 3D scene.
Returns:
transformed vertices.

draw

protected void draw(javax.microedition.lcdui.Graphics graphics,
                    float[] vertices,
                    int[] triangleIndices,
                    int[] triangleLengths)
Draws a wireframe model on the given graphics context.

Parameters:
graphics - graphics context for drawing.
vertices - transformed vertices of the model.
triangleIndices - triangle indices that define how to draw the model.
triangleLengths - lengths of the triangle array.