render
Class Material

java.lang.Object
  |
  +--render.Material
All Implemented Interfaces:
java.lang.Runnable

public class Material
extends java.lang.Object
implements java.lang.Runnable

Deals with aspects of color and material properties of objects.

Stores color properties of material: diffuse light, specular light, and ambient light.
Holds information about transparency and whether the material is double sided.


Field Summary
protected  double[] ambient
          Ambient lighting color values in RGB (range [0,1]).
 boolean anisotropic
          Indicates whether the material is anisotropic (light reflection varies with respect to direction).
protected  double[] diffuse
          Holds diffuse color information ( R, G, B, exponent )
protected  double FL
          Focal Length
 boolean isDoubleSided
          Indicates whether the material is double sided.
 double noiseA
          Noise amplitude.
 double noiseF
          Noise frequency.
 int res
          Resolution of the material.
 int resP
          Bit depth of the resolution.
protected  double[] specular
          Holds specular color information (R, G, B, exponent )
protected  int[] table
          Stores the precomputed normal map for quick lookup later.
 boolean tableMode
          Flag determining wheter to precompute and store color tables for direct look up intead of on the fly computation.
protected  Texture texture
           
protected  double transparency
          Transparency of the object (0-invisible, 1-opaque).
protected  double[] v
           
 
Constructor Summary
Material()
           
 
Method Summary
 int computePixel(int[] data, int dx, int dy, int NB)
          Returns the packed integer of a particular pixel To do extra pixel computation, overload this method
 int countTable()
          Counts the non-zero entries in the lookup table.
 void getAmbient(double[] amb)
          Gets the ambient light components (r, g, b).
 void getDiffuse(double[] diff)
          Gets the diffuse color components in RGB (range 0 to 1).
 void getSpecular(double[] spec)
          Gets the specular components of color (r, g, b, exponent).
 int getTable(int ix, int iy, int iz)
          Looks up the appropriate color value from the table at x, y, z.
 double getTransparency()
          Returns the transparency of the material (0 transparent to 1 opaque).
 boolean hasTexture()
           
 void initTable(int p)
          Creates and initializes the lookup table to all black.
 void recache()
           
 void run()
          Thread that runs in the background ( provided the resources are available - no mouse dragging for example) and computes the normal map table of values for quick look up later.
 Material setAmbient(double r, double g, double b)
          Sets the ambient lighting color values (range 0..1).
 Material setColor(double dr, double dg, double db)
          Sets the diffuse color of an object.
 Material setColor(double dr, double dg, double db, double dp)
          Sets the diffuse color of an object.
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp)
          Sets the diffuse and specular values of color.
 Material setColor(double dr, double dg, double db, double dp, double sr, double sg, double sb, double sp)
          Sets the diffuse and specular values of color.
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp, double ar, double ag, double ab)
          Sets the diffuse, specular and ambient values of color.
 Material setColor(double dr, double dg, double db, double dp, double sr, double sg, double sb, double sp, double ar, double ag, double ab)
          Sets the diffuse, specular and ambient values of color.
 Material setDiffuse(double r, double g, double b)
          Sets the diffuse components of light (range 0..1).
 Material setDiffuse(double r, double g, double b, double p)
          Sets the diffuse components of light (range 0..1).
 Material setDoubleSided(boolean t)
          Sets the double sided flag true to indicate whether the object is double sided.
 Material setSpecular(double r, double g, double b, double p)
          Sets the specular color components (r, g, b, exp).
 void setTable(int ix, int iy, int iz, int p)
          Sets the x, y, z, value in the lookup table to p.
 Material setTexture(Texture texel)
           
 Material setTransparency(double t)
          Sets the transparency of the material (0 transparent to 1 opaque).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableMode

public boolean tableMode
Flag determining wheter to precompute and store color tables for direct look up intead of on the fly computation.


resP

public int resP
Bit depth of the resolution.


res

public int res
Resolution of the material.


table

protected int[] table
Stores the precomputed normal map for quick lookup later.


isDoubleSided

public boolean isDoubleSided
Indicates whether the material is double sided.


anisotropic

public boolean anisotropic
Indicates whether the material is anisotropic (light reflection varies with respect to direction).


noiseF

public double noiseF
Noise frequency.


noiseA

public double noiseA
Noise amplitude.


diffuse

protected double[] diffuse
Holds diffuse color information ( R, G, B, exponent )


specular

protected double[] specular
Holds specular color information (R, G, B, exponent )


transparency

protected double transparency
Transparency of the object (0-invisible, 1-opaque).


ambient

protected double[] ambient
Ambient lighting color values in RGB (range [0,1]).


texture

protected Texture texture

FL

protected double FL
Focal Length


v

protected double[] v
Constructor Detail

Material

public Material()
Method Detail

getTable

public int getTable(int ix,
                    int iy,
                    int iz)
Looks up the appropriate color value from the table at x, y, z.

Parameters:
ix - x
iy - y
iz - z
Returns:
the packed color value

setTable

public void setTable(int ix,
                     int iy,
                     int iz,
                     int p)
Sets the x, y, z, value in the lookup table to p.

Parameters:
ix - x
iy - y
iz - z
p - the packed color value

initTable

public void initTable(int p)
Creates and initializes the lookup table to all black.

Parameters:
p - bit depth resolution

countTable

public int countTable()
Counts the non-zero entries in the lookup table.

Returns:
the number of non-zero entries.

hasTexture

public boolean hasTexture()

setTexture

public Material setTexture(Texture texel)

computePixel

public int computePixel(int[] data,
                        int dx,
                        int dy,
                        int NB)
Returns the packed integer of a particular pixel To do extra pixel computation, overload this method

Parameters:
data - array representing the pixel indices of data are: 0,1,2 are the x,y,z of the pixel 3,4,5 are the r,g,b values 6,7 are the u,v coordinates
dx - size of the pixel in x
dy - size of the pixel in y
NB - precision value

setDiffuse

public Material setDiffuse(double r,
                           double g,
                           double b)
Sets the diffuse components of light (range 0..1).

Parameters:
r - red
g - green
b - blue

setDiffuse

public Material setDiffuse(double r,
                           double g,
                           double b,
                           double p)
Sets the diffuse components of light (range 0..1).

Parameters:
r - red
g - green
b - blue
p - exponent

getDiffuse

public void getDiffuse(double[] diff)
Gets the diffuse color components in RGB (range 0 to 1).


setSpecular

public Material setSpecular(double r,
                            double g,
                            double b,
                            double p)
Sets the specular color components (r, g, b, exp).

Parameters:
r - red
g - green
b - blue
Returns:
the material

getSpecular

public void getSpecular(double[] spec)
Gets the specular components of color (r, g, b, exponent).

Parameters:
spec - array of doubles containing 4 specular light components

setAmbient

public Material setAmbient(double r,
                           double g,
                           double b)
Sets the ambient lighting color values (range 0..1).

Parameters:
r - red
g - green
b - blue
Returns:
the material

getAmbient

public void getAmbient(double[] amb)
Gets the ambient light components (r, g, b).


setColor

public Material setColor(double dr,
                         double dg,
                         double db)
Sets the diffuse color of an object.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp)
Sets the diffuse color of an object.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double sr,
                         double sg,
                         double sb,
                         double sp)
Sets the diffuse and specular values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
sr - specular red
sg - specular green
sb - specular blue
sp - specular exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp,
                         double sr,
                         double sg,
                         double sb,
                         double sp)
Sets the diffuse and specular values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
sr - specular red
sg - specular green
sb - specular blue
sp - specular exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double sr,
                         double sg,
                         double sb,
                         double sp,
                         double ar,
                         double ag,
                         double ab)
Sets the diffuse, specular and ambient values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
sr - specular red
sg - specular green
sb - specular blue
ar - ambient red
ag - ambient green
ab - ambient blue
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp,
                         double sr,
                         double sg,
                         double sb,
                         double sp,
                         double ar,
                         double ag,
                         double ab)
Sets the diffuse, specular and ambient values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
sr - specular red
sg - specular green
sb - specular blue
ar - ambient red
ag - ambient green
ab - ambient blue
Returns:
the material

setDoubleSided

public Material setDoubleSided(boolean t)
Sets the double sided flag true to indicate whether the object is double sided.

Parameters:
t - new value of isDoubleSided
Returns:
the material

setTransparency

public Material setTransparency(double t)
Sets the transparency of the material (0 transparent to 1 opaque).

Parameters:
t - new transparency value
Returns:
the material

getTransparency

public double getTransparency()
Returns the transparency of the material (0 transparent to 1 opaque).

Returns:
the actual transparency of the material

recache

public void recache()

run

public void run()
Thread that runs in the background ( provided the resources are available - no mouse dragging for example) and computes the normal map table of values for quick look up later.

Specified by:
run in interface java.lang.Runnable