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
 boolean anisotropic
          Indicates whether the material is anisotropic (light reflection varies with respect to direction).
protected  double[] color
          Holds the color information ( Diffuse color R,G,B, Specular Color R,G,B, Specular exponent).
protected  double[] glow
          Ambient lighting color values in RGB (glow) (range [0,1]).
 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  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.
 double[] getAmbient()
          Gets the glow light components (r, g, b).
 double[] getDiffuse()
          Gets the diffuse color components in RGB (range 0 to 1).
 double[] getDS()
          Returns the diffuse and specular light components.
 double[] getDSA()
          Gets the diffuse, specular, and ambient light components.
 double[] getSpecular()
          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[] c)
          Deprecated. Use specific color-setting functions, see setDS(double, double, double, double, double, double, double).
 Material setColor(double dr, double dg, double db)
          Deprecated. Use specific color-setting functions, see setDiffuse(double, double, double).
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp)
          Deprecated. Use specific color-setting functions, see setDS(double, double, double, double, double, double, double).
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp, double ar, double ag, double ab)
          Deprecated. Use specific color-setting functions, see setDSA(double, double, double, double, double, double, double, double, double, double).
 Material setDiffuse(double r, double g, double b)
          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 setDS(double dr, double dg, double db, double sr, double sg, double sb, double p)
          Sets the diffuse and specular values of color.
 Material setDSA(double dr, double dg, double db, double sr, double sg, double sb, double p, double ar, double ag, double ab)
          Sets the diffuse, specular, and ambient values of color.
 Material setGlow(double[] g)
          Deprecated. Use specific color setting function, setAmbient(double, double, double)
 Material setGlow(double r, double g, double b)
          Deprecated. Use specific color setting function, setAmbient(double, double, double)
 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.


color

protected double[] color
Holds the color information ( Diffuse color R,G,B, Specular Color R,G,B, Specular exponent).


transparency

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


glow

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


texture

protected Texture texture

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

setColor

public Material setColor(double[] c)
Deprecated. Use specific color-setting functions, see setDS(double, double, double, double, double, double, double).

Sets diffuse and specular color values.

Parameters:
c - color values corresponding to [dred, dgreen, dblue, sred, sgreen, sblue, s exponent].
Returns:
the material

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

getDiffuse

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

Returns:
an array of doubles corresponding to r g b color components

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 double[] getSpecular()
Gets the specular components of color (r, g, b, exponent).

Returns:
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 double[] getAmbient()
Gets the glow light components (r, g, b).

Returns:
the array of the ambient lighting components (r, g, b)

setDS

public Material setDS(double dr,
                      double dg,
                      double db,
                      double sr,
                      double sg,
                      double sb,
                      double p)
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
Returns:
the material

getDS

public double[] getDS()
Returns the diffuse and specular light components.

Returns:
array of values corresponding to diffuse r, g, b, and specular r, g, b, exponent. In that order.

setDSA

public Material setDSA(double dr,
                       double dg,
                       double db,
                       double sr,
                       double sg,
                       double sb,
                       double p,
                       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

getDSA

public double[] getDSA()
Gets the diffuse, specular, and ambient light components.

Returns:
An array containing the diffuse r, g, b, specular r, g, b, exp, ambient r, g, b.

setColor

public Material setColor(double dr,
                         double dg,
                         double db)
Deprecated. Use specific color-setting functions, see setDiffuse(double, double, double).

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 sr,
                         double sg,
                         double sb,
                         double sp)
Deprecated. Use specific color-setting functions, see setDS(double, double, double, double, double, double, double).

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
See Also:
setDS(double, double, double, double, double, double, double)

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double sr,
                         double sg,
                         double sb,
                         double sp,
                         double ar,
                         double ag,
                         double ab)
Deprecated. Use specific color-setting functions, see setDSA(double, double, double, double, double, double, double, double, double, double).

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

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

setGlow

public Material setGlow(double[] g)
Deprecated. Use specific color setting function, setAmbient(double, double, double)

Sets the color value of the ambient lighting.

Parameters:
g - array of [red, green, blue] values in range 0..1
Returns:
the material.
See Also:
setAmbient(double, double, double)

setGlow

public Material setGlow(double r,
                        double g,
                        double b)
Deprecated. Use specific color setting function, setAmbient(double, double, double)

Sets the color value of the ambient lighting.

Parameters:
r - red
g - green
b - blue
Returns:
the material
See Also:
setAmbient(double, double, double)

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