Class FlatRenderer

java.lang.Object
  |
  +--Renderer
        |
        +--FlatRenderer
Direct Known Subclasses:
GouraudRenderer

public class FlatRenderer
extends Renderer

Renders mesh objects using visible-surface determination and constant shading. Uses the scan-line with a single-line z-buffer algorithm. When at least one Light object exist in the metafile, it renders using the constant-shading method, otherwise it renders with an ambient light of RGB = (1F,1F,1F).

Author:
Sasmito Adibowo - 1299000029

Inner Class Summary
protected static class FlatRenderer.ActiveEdgeTable
          The current edge table for the scan line.
protected static class FlatRenderer.EdgeBucket
          The Edge table bucket for the EdgeTable.
protected static class FlatRenderer.EdgeEntry
          The entry for an edge in an EdgeBucket.
protected static class FlatRenderer.EdgeTable
          The global Edge Table for each polygon.
protected static class FlatRenderer.PolygonInfo
          Information about a polygon in process.
 
Field Summary
protected  Color[] colorBuffer
          The colors of the current scan line.
protected  double[] depthBuffer
          The depths(Z) of the current scan line.
protected  List lights
          The list of Light objects, transformed onto viewplane coordinates, but not projected.
protected  List polygonTable
          The polygon table, containing PolygonInfo instances
protected  List projectedMeshes
          The list of meshes which are already projected onto the viewplane, ready for scan-conversion.
protected  int xmin
          The minimum x scan line value.
 
Fields inherited from class Renderer
AMBIENT_BLUE, AMBIENT_GREEN, AMBIENT_RED, backingStore, CS_REALWORLD, FATT_C1, FATT_C2, FATT_C3, metafile, owner, viewPlane
 
Constructor Summary
FlatRenderer(Component owner)
           
 
Method Summary
protected  void fillPixels(FlatRenderer.PolygonInfo info, FlatRenderer.ActiveEdgeTable AET, int xmin, int y)
          Fills a line of pixels from the AET.
protected  Jama.Matrix getProjectionMatrix()
          Returns the current projection matrix -- parallel or perspective.
protected  void initLineBuffers(int width)
          Initializes the line buffers: depthBuffer and colorBuffer.
protected  void initPolygonTable()
          Initializes the polygon table with PolygonInfo instances using the current meshes in projectedMeshes.
protected  Jama.Matrix makeCoorSysMatrices(CoorSys cs)
          Retrieves coorsys transformation matrices up to the root, and returns the composite transformation matrix.
protected  Mesh normalizeMesh(Mesh mesh)
          Normalizes the mesh into viewplane coordinates.
protected  void normalizeMeshes()
          Normalizes all the mesh objects and put into projectedMeshes.
protected  void notifyDataChanged()
          Called when there are changes to the Renderer data.
 void paint(Graphics2D graphic)
          Renders the 3-D scene.
protected  void processPolygon(FlatRenderer.PolygonInfo info, int y)
          Draws a polygon at the current scan line.
protected  void processScanLine(Graphics2D g)
          Scan-line converts the projected meshes.
protected  Jama.Matrix projectMatrix(Jama.Matrix normalized)
          Project matrix to viewplane matrix and projection matrix.
protected  void projectMesh(Mesh m)
          Projects all the meshes in projectedMeshes
protected  void projectMeshes()
          Projects the mesh objects in projectedMeshes
 void render()
          Called to re-render the image internally.
protected static int roundCoord(double coord)
          Rounds a coordinate value from world units to device units.
protected  void transformLights()
          Transforms all the Light objects onto the viewplane and store them into the lights List.
 
Methods inherited from class Renderer
drawGrid, getMetafile, getSize, initBackingStore, makeParallelProjection, makePerspectiveProjection, moveCamera, overlaps, parallelProjection, rotateCameraX, rotateCameraY, rotateCameraZ, rotateCoorSysX, rotateCoorSysY, rotateCoorSysZ, setMetafile, setupCartesian, translateCoorSys
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

lights

protected List lights
The list of Light objects, transformed onto viewplane coordinates, but not projected.

depthBuffer

protected double[] depthBuffer
The depths(Z) of the current scan line.

colorBuffer

protected Color[] colorBuffer
The colors of the current scan line.

xmin

protected int xmin
The minimum x scan line value.

projectedMeshes

protected List projectedMeshes
The list of meshes which are already projected onto the viewplane, ready for scan-conversion.

polygonTable

protected List polygonTable
The polygon table, containing PolygonInfo instances
Constructor Detail

FlatRenderer

public FlatRenderer(Component owner)
Method Detail

render

public void render()
Description copied from class: Renderer
Called to re-render the image internally. The default implementation does nothing. Since rendering 3D images is typically slow, it is desirable to call this in a separate thread.
Overrides:
render in class Renderer

paint

public void paint(Graphics2D graphic)
Description copied from class: Renderer
Renders the 3-D scene. The default implementation does nothing.
Overrides:
paint in class Renderer
Tags copied from class: Renderer
Parameters:
g - the graphics context.

notifyDataChanged

protected void notifyDataChanged()
Description copied from class: Renderer
Called when there are changes to the Renderer data. Derived classes should override this to receive the notification. The default implementation does nothing.
Overrides:
notifyDataChanged in class Renderer

initLineBuffers

protected void initLineBuffers(int width)
Initializes the line buffers: depthBuffer and colorBuffer.
Parameters:
width - the width (length) of the line buffers
See Also:
depthBuffer, colorBuffer

transformLights

protected void transformLights()
Transforms all the Light objects onto the viewplane and store them into the lights List.

initPolygonTable

protected void initPolygonTable()
Initializes the polygon table with PolygonInfo instances using the current meshes in projectedMeshes.
See Also:
projectedMeshes, polygonTable, FlatRenderer.PolygonInfo

processScanLine

protected void processScanLine(Graphics2D g)
Scan-line converts the projected meshes.
Parameters:
g - the graphic context to draw the image; must already be set to the cartesian coordinate system.

processPolygon

protected void processPolygon(FlatRenderer.PolygonInfo info,
                              int y)
Draws a polygon at the current scan line.
Parameters:
info - the polygon to draw.
y - the y-coordinate of the current scan line.

fillPixels

protected void fillPixels(FlatRenderer.PolygonInfo info,
                          FlatRenderer.ActiveEdgeTable AET,
                          int xmin,
                          int y)
Fills a line of pixels from the AET. Updates depthBuffer and colorBuffer.
Parameters:
AET - the current active-edge table.
g - the drawing surface.
xmin - the minimum x-coordinate.
y - the current y-coordinate of the line.
See Also:
depthBuffer, colorBuffer

normalizeMeshes

protected void normalizeMeshes()
Normalizes all the mesh objects and put into projectedMeshes.
See Also:
projectedMeshes

projectMeshes

protected void projectMeshes()
Projects the mesh objects in projectedMeshes

projectMesh

protected void projectMesh(Mesh m)
Projects all the meshes in projectedMeshes
See Also:
projectedMeshes

makeCoorSysMatrices

protected Jama.Matrix makeCoorSysMatrices(CoorSys cs)
Retrieves coorsys transformation matrices up to the root, and returns the composite transformation matrix.
Parameters:
cs - the coordinate system.
Returns:
the composite transformation matrix of cs and its parents.

projectMatrix

protected Jama.Matrix projectMatrix(Jama.Matrix normalized)
Project matrix to viewplane matrix and projection matrix.
Parameters:
normalized - the normalized matrix in world coordinates
Returns:
the projection matrix from world coordinates to viewplane coordinates.

getProjectionMatrix

protected Jama.Matrix getProjectionMatrix()
Returns the current projection matrix -- parallel or perspective.

normalizeMesh

protected Mesh normalizeMesh(Mesh mesh)
Normalizes the mesh into viewplane coordinates.
Parameters:
mesh - the source mesh to project.
Returns:
the new projected mesh.

roundCoord

protected static final int roundCoord(double coord)
Rounds a coordinate value from world units to device units.
Parameters:
coord - a coordinate value in world units.
Returns:
the coordinate value in device units.