render
Class Renderer

java.lang.Object
  |
  +--render.Renderer

public class Renderer
extends java.lang.Object


Field Summary
 boolean bufferg
          Flag that determines whether to keep a z-buffer of geometries, to to know the frontmost object at any position (x, y) in the image.
 boolean isAnaglyph
           
 boolean isHeadsUp
          Determines whether the camera tries to maintain a "heads up" orientation.
 int lod
          Set the level of detail for meshes.
 boolean manualCameraControl
          flag that enables full manual camera control for setting camera location, aim target, and the up vector.
 boolean seeMesh
          When set true, only the wireframe structure of the objects is displayed using appropriate colors.
 boolean showMesh
          Shows/overlays the geometry mesh in black when true.
static boolean tableMode
          Flag controls table lookup mode for materials, true means on.
 boolean updateTransparency
          Allocate space for transparent objects when true.
 
Constructor Summary
Renderer()
           
 
Method Summary
 void addLight(double x, double y, double z, double r, double g, double b)
          Add a light source where x,y,z are light source direction; r,g,b are light source color.
 void colorLight(int i, double r, double g, double b)
          Assigns new color values to the light i.
 int getBgColor()
          Returns the background color.
 Matrix getCamera()
          Returns the matrix that defines the camera transformation.
 double[] getCameraAim()
          returns the current target look-at point of the camera
 double[] getCameraPos()
          returns the current position of the camera
 double[] getCameraUp()
          returns the current up vector of the camera
 double getClippingPlaneEpsilon()
          Returns the distance of the clipping plane from the camera lens.
 double getCx()
           
 double getCy()
           
 double getFL()
          Returns the camera's focal length
 double getFOV()
          Returns the camera field of view.
 Geometry getGeometry(int x, int y)
          Returns the Geometry of the frontmost object at the point (x, y) in the image (like a z-buffer value of geometries).
 int getNumberOfLights()
          Returns the number of lights in the scene.
 double getOutline()
          Returns the outline threshold parameter for sketch-like (artistic) rendition of the scene.
 boolean getPoint(int ix, int iy, double[] xyz)
           
 Geometry getWorld()
          Returns the root of the geometry tree.
 void headsUp(boolean tf)
          Sets whether the camera tries to maintain a "heads up" orientation.
 int[] init(int W, int H)
          Initializes the renderer.
 void init(int W, int H, int[] pix)
           
static boolean isDragging()
          Returns whether dragging is active or not.
 void lookAt(double[] eye, double[] center, double[] up)
          Sets the camera to move to the eye position, aim at the center, and maintain the up direction ( requires the manualCameraControl flag to be turned on).
 void outline(double t)
          Thresholds t to produce a sketch-like (artistic) rendition of the scene.
 void placeLight(int i, double x, double y, double z)
          Moves an already defined light i, to point in the new direction of normalized [x, y, z].
 void projectPoint(double[] v)
           
 void refresh()
          Force a refresh of the entire window.
 int[] reinit(int W, int H)
          Initializes the renderer.
 void render()
          Render the entire world for this frame.
 void renderVertex(double[] v, Material m)
          Renders vertex v with material m, if table mode is enabled the data is just looked up in the material's table, otherwise it is computed.
static void renderVertex(int i, Material m)
          Renders vertex i ( packed x,y,z) with material m.
 void rotateView(double t, double p)
          Rotate angle of view.
 void setBgColor(double r, double g, double b)
          Set the background fill color.
 void setBgColor(int color)
          Set the background fill color.
 void setCamera(double theta, double phi)
          Forces an absolute value for the camera matrix.
 void setCamera(Matrix m)
          Sets the camera matrix directly.
 void setCameraAim(double px, double py, double pz)
          Sets the aiming point at which the camera should point.
 void setCameraPos(double px, double py, double pz)
          Sets the position of the camera.
 void setCameraUp(double px, double py, double pz)
          Sets the cameraUp vector (must be a unit vector).
 void setClippingPlaneEpsilon(double e)
          Sets the distance of the clipping plane in front of the camera lens.
 void setCx(double x)
           
 void setCy(double y)
           
static void setDragging(boolean tf)
          If the user is interactively dragging the mouse, we want the renderer to know about it, so that any other background process (eg: a material which is building a lookup table) can ask the renderer, and thereby avoid consuming scarce CPU resources simultaneously.
 void setFL(double value)
          Sets the camera's focal length.
 void setFOV(double value)
          Sets the camera field of view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableMode

public static boolean tableMode
Flag controls table lookup mode for materials, true means on.


lod

public int lod
Set the level of detail for meshes.


showMesh

public boolean showMesh
Shows/overlays the geometry mesh in black when true.


updateTransparency

public boolean updateTransparency
Allocate space for transparent objects when true.


bufferg

public boolean bufferg
Flag that determines whether to keep a z-buffer of geometries, to to know the frontmost object at any position (x, y) in the image.

See Also:
getGeometry(int x, int y)

isHeadsUp

public boolean isHeadsUp
Determines whether the camera tries to maintain a "heads up" orientation.


manualCameraControl

public boolean manualCameraControl
flag that enables full manual camera control for setting camera location, aim target, and the up vector. (default = false). When true you can use : lookAt(double[], double[], double[]), setCameraPos(double, double, double), setCameraAim(double, double, double), setCameraUp(double, double, double). When false you can use : setCamera(double, double)


isAnaglyph

public boolean isAnaglyph

seeMesh

public boolean seeMesh
When set true, only the wireframe structure of the objects is displayed using appropriate colors.

Constructor Detail

Renderer

public Renderer()
Method Detail

init

public int[] init(int W,
                  int H)
Initializes the renderer.

Parameters:
W - framebuffer width
H - framebuffer height.
Returns:
framebuffer array.

init

public void init(int W,
                 int H,
                 int[] pix)

reinit

public int[] reinit(int W,
                    int H)
Initializes the renderer.

Parameters:
W - framebuffer width
H - framebuffer height.
Returns:
framebuffer array.

setDragging

public static void setDragging(boolean tf)
If the user is interactively dragging the mouse, we want the renderer to know about it, so that any other background process (eg: a material which is building a lookup table) can ask the renderer, and thereby avoid consuming scarce CPU resources simultaneously.

Parameters:
tf - dragging true or false

isDragging

public static boolean isDragging()
Returns whether dragging is active or not.

Returns:
true when dragging is active, false otherwise

setCamera

public void setCamera(double theta,
                      double phi)
Forces an absolute value for the camera matrix.

Parameters:
theta - horizontal angle (radians)
phi - vertical angle (radians)

headsUp

public void headsUp(boolean tf)
Sets whether the camera tries to maintain a "heads up" orientation.

Parameters:
tf - value true or false

setFL

public void setFL(double value)
Sets the camera's focal length.

Parameters:
value - focal lengh

getFL

public double getFL()
Returns the camera's focal length

Returns:
camera's focal length

setFOV

public void setFOV(double value)
Sets the camera field of view.

Parameters:
value - field of view

getFOV

public double getFOV()
Returns the camera field of view.

Returns:
value field of view

getWorld

public Geometry getWorld()
Returns the root of the geometry tree.

Returns:
the root of the geometry tree.

setBgColor

public void setBgColor(double r,
                       double g,
                       double b)
Set the background fill color.


setBgColor

public void setBgColor(int color)
Set the background fill color.


getBgColor

public int getBgColor()
Returns the background color.


addLight

public void addLight(double x,
                     double y,
                     double z,
                     double r,
                     double g,
                     double b)
Add a light source where x,y,z are light source direction; r,g,b are light source color.


getNumberOfLights

public int getNumberOfLights()
Returns the number of lights in the scene.

Returns:
the number of lights

placeLight

public void placeLight(int i,
                       double x,
                       double y,
                       double z)
Moves an already defined light i, to point in the new direction of normalized [x, y, z].

Parameters:
i - the index of the light to be changed
x - x direction of the light
y - y direction of the light
z - z direction of the light

colorLight

public void colorLight(int i,
                       double r,
                       double g,
                       double b)
Assigns new color values to the light i.

Parameters:
i - index of the light to change
r - the red color component value
g - the green color component
b - the blue color component

rotateView

public void rotateView(double t,
                       double p)
Rotate angle of view.


lookAt

public void lookAt(double[] eye,
                   double[] center,
                   double[] up)
Sets the camera to move to the eye position, aim at the center, and maintain the up direction ( requires the manualCameraControl flag to be turned on).

Parameters:
eye - new position of the camera ( double[x, y, z] )
center - aim point of the camera ( double[x, y, z] )
up - unit vector specifying the up direction in the world ( double[x, y, z] )

getCamera

public Matrix getCamera()
Returns the matrix that defines the camera transformation.

Returns:
the matrix that defines the camera transformation

setCamera

public void setCamera(Matrix m)
Sets the camera matrix directly. Matrix needs to be 4x4.


setCameraPos

public void setCameraPos(double px,
                         double py,
                         double pz)
Sets the position of the camera. ( requires the manualCameraControl flag to be turned on).


getCameraPos

public double[] getCameraPos()
returns the current position of the camera


setCameraAim

public void setCameraAim(double px,
                         double py,
                         double pz)
Sets the aiming point at which the camera should point. ( requires the manualCameraControl flag to be turned on).


getCameraAim

public double[] getCameraAim()
returns the current target look-at point of the camera


setCameraUp

public void setCameraUp(double px,
                        double py,
                        double pz)
Sets the cameraUp vector (must be a unit vector). ( requires the manualCameraControl flag to be turned on).

Parameters:
px -
py -
pz -

getCameraUp

public double[] getCameraUp()
returns the current up vector of the camera


setClippingPlaneEpsilon

public void setClippingPlaneEpsilon(double e)
Sets the distance of the clipping plane in front of the camera lens.

Parameters:
e - the actual disance

getClippingPlaneEpsilon

public double getClippingPlaneEpsilon()
Returns the distance of the clipping plane from the camera lens.


render

public void render()
Render the entire world for this frame.


getOutline

public double getOutline()
Returns the outline threshold parameter for sketch-like (artistic) rendition of the scene.


outline

public void outline(double t)
Thresholds t to produce a sketch-like (artistic) rendition of the scene.

Parameters:
t - outline threshold

refresh

public void refresh()
Force a refresh of the entire window.


setCx

public void setCx(double x)

setCy

public void setCy(double y)

getCx

public double getCx()

getCy

public double getCy()

projectPoint

public void projectPoint(double[] v)

renderVertex

public static void renderVertex(int i,
                                Material m)
Renders vertex i ( packed x,y,z) with material m.

Parameters:
i - vertex to be rendered
m - material properties to be applied to the vertex

renderVertex

public void renderVertex(double[] v,
                         Material m)
Renders vertex v with material m, if table mode is enabled the data is just looked up in the material's table, otherwise it is computed.

Parameters:
v - vertex x,y,z and the r,g,b values for it.
m - material with which to render the vertex.

getGeometry

public Geometry getGeometry(int x,
                            int y)
Returns the Geometry of the frontmost object at the point (x, y) in the image (like a z-buffer value of geometries).

Parameters:
x - x coordinate in the image
y - y coordinate in the image
Returns:
the geometry of the foremost object at that location

getPoint

public boolean getPoint(int ix,
                        int iy,
                        double[] xyz)