Class Renderer

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

public class Renderer
extends Object

Base class for all renderer objects which renders 3-D polygon meshes.

Version:
2.0
Author:
Sasmito Adibowo - 1299000029

Field Summary
protected static float AMBIENT_BLUE
          Default blue ambient value
protected static float AMBIENT_GREEN
          Default Green ambient value
protected static float AMBIENT_RED
          Default red ambient value
protected  Image backingStore
          The backing store.
static String CS_REALWORLD
          The real world coordinate system name.
protected static float FATT_C1
          The first constant for the attenuation factor.
protected static float FATT_C2
          The second constant for the attenuation factor.
protected static float FATT_C3
          The third constant for the attenuation factor.
protected  Metafile metafile
          The metafile containing the specification of the polygon meshes.
protected  Component owner
          The owner component.
protected  ViewPlane viewPlane
          The view plane on which to project the polygon mesh.
 
Constructor Summary
Renderer(Component owner)
          Creates the renderer to draw in the owner component.
 
Method Summary
 void drawGrid(Graphics2D g, int xspace, int yspace)
          draws a grid.
 Metafile getMetafile()
          Returns the current metafile of the renderer,
 Dimension getSize()
          Returns how big the display size should be.
protected  void initBackingStore()
          Creates an image for the backing store.
protected  Jama.Matrix makeParallelProjection()
          Creates a parallel projection matrix.
protected  Jama.Matrix makePerspectiveProjection()
          Creates a perspective projection matrix.
 void moveCamera(double dx, double dy, double dz)
          Translates the camera.
protected  void notifyDataChanged()
          Called when there are changes to the Renderer data.
static boolean overlaps(double min1, double max1, double min2, double max2)
          Determines if two sets of range values overlaps
 void paint(Graphics2D g)
          Renders the 3-D scene.
protected static Jama.Matrix parallelProjection(double l, double psi)
          Returns a 4x4 homogeneous matrix for parallel projection
 void render()
          Called to re-render the image internally.
 void rotateCameraX(double degs)
          Rotates the camera by the X axis.
 void rotateCameraY(double degs)
          Rotates the camera by the Y axis.
 void rotateCameraZ(double degs)
          Rotates the camera by the Z axis.
 void rotateCoorSysX(String name, double degs)
          Rotates a coordinate system by the X axis.
 void rotateCoorSysY(String name, double degs)
          Rotates a coordinate system by the Y axis.
 void rotateCoorSysZ(String name, double degs)
          Rotates a coordinate system by the Z axis.
 void setMetafile(Metafile m)
          Sets a new metafile.
protected  void setupCartesian(Graphics2D g)
          Modifies the Graphic object coordinate system to cartesian.
 void translateCoorSys(String name, double dx, double dy, double dz)
          Translates a coordinate system.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

viewPlane

protected ViewPlane viewPlane
The view plane on which to project the polygon mesh.

metafile

protected Metafile metafile
The metafile containing the specification of the polygon meshes.

owner

protected Component owner
The owner component.

backingStore

protected Image backingStore
The backing store.

CS_REALWORLD

public static final String CS_REALWORLD
The real world coordinate system name.

AMBIENT_RED

protected static final float AMBIENT_RED
Default red ambient value

AMBIENT_GREEN

protected static final float AMBIENT_GREEN
Default Green ambient value

AMBIENT_BLUE

protected static final float AMBIENT_BLUE
Default blue ambient value

FATT_C1

protected static final float FATT_C1
The first constant for the attenuation factor.

FATT_C2

protected static final float FATT_C2
The second constant for the attenuation factor.

FATT_C3

protected static final float FATT_C3
The third constant for the attenuation factor.
Constructor Detail

Renderer

public Renderer(Component owner)
Creates the renderer to draw in the owner component.
Method Detail

render

public void render()
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.

paint

public void paint(Graphics2D g)
Renders the 3-D scene. The default implementation does nothing.
Parameters:
g - the graphics context.

setMetafile

public void setMetafile(Metafile m)
Sets a new metafile.
Parameters:
m - the metafile.

getMetafile

public Metafile getMetafile()
Returns the current metafile of the renderer,

moveCamera

public void moveCamera(double dx,
                       double dy,
                       double dz)
Translates the camera.
Parameters:
dx - x-delta.
dy - y-delta.
dz - z-delta.

rotateCameraX

public void rotateCameraX(double degs)
Rotates the camera by the X axis.
Parameters:
degs - the rotation angle, in degrees.

rotateCameraY

public void rotateCameraY(double degs)
Rotates the camera by the Y axis.
Parameters:
degs - the rotation angle, in degrees.

rotateCameraZ

public void rotateCameraZ(double degs)
Rotates the camera by the Z axis.
Parameters:
degs - the rotation angle, in degrees.

translateCoorSys

public void translateCoorSys(String name,
                             double dx,
                             double dy,
                             double dz)
Translates a coordinate system. Does nothing if the coordinate system specified cannot be found.
Parameters:
name - the coordinate system name.
dx - x-delta.
dy - y-delta.
dz - z-delta.

rotateCoorSysX

public void rotateCoorSysX(String name,
                           double degs)
Rotates a coordinate system by the X axis. Does nothing if the coordinate system specified cannot be found.
Parameters:
name - the coordinate system name.
degs - the rotation angle, in degrees.

rotateCoorSysY

public void rotateCoorSysY(String name,
                           double degs)
Rotates a coordinate system by the Y axis. Does nothing if the coordinate system specified cannot be found.
Parameters:
name - the coordinate system name.
degs - the rotation angle, in degrees.

rotateCoorSysZ

public void rotateCoorSysZ(String name,
                           double degs)
Rotates a coordinate system by the Z axis. Does nothing if the coordinate system specified cannot be found.
Parameters:
name - the coordinate system name.
degs - the rotation angle, in degrees.

getSize

public Dimension getSize()
Returns how big the display size should be.

drawGrid

public void drawGrid(Graphics2D g,
                     int xspace,
                     int yspace)
draws a grid. Expects that g is already set to standard cartesian coordinate system.
Parameters:
g - the graphics context.
xspace - the spacing of vertical lines.
yspace - the spacing or horizontal lines

notifyDataChanged

protected void notifyDataChanged()
Called when there are changes to the Renderer data. Derived classes should override this to receive the notification. The default implementation does nothing.

parallelProjection

protected static Jama.Matrix parallelProjection(double l,
                                                double psi)
Returns a 4x4 homogeneous matrix for parallel projection

makeParallelProjection

protected Jama.Matrix makeParallelProjection()
Creates a parallel projection matrix.
Returns:
a 4x4 homogeneous matrix for parallel projection.

makePerspectiveProjection

protected Jama.Matrix makePerspectiveProjection()
Creates a perspective projection matrix.
Returns:
a 4x4 homogeneous matrix for perspective projection.

overlaps

public static final boolean overlaps(double min1,
                                     double max1,
                                     double min2,
                                     double max2)
Determines if two sets of range values overlaps

initBackingStore

protected void initBackingStore()
Creates an image for the backing store.
See Also:
backingStore

setupCartesian

protected void setupCartesian(Graphics2D g)
Modifies the Graphic object coordinate system to cartesian.