net.sf.j3d.threeD.raytracer.engine
Class AbstractSurface

java.lang.Object
  extended by net.sf.j3d.threeD.raytracer.engine.AbstractSurface
All Implemented Interfaces:
Surface
Direct Known Subclasses:
Cone, CSG, Cylinder, Plane, PointLightGrid, Polynomial, Sphere, SurfaceGroup, Triangle

public abstract class AbstractSurface
extends Object
implements Surface

AbstractSurface is an abstract implementation of Surface that takes care of all of the standard methods of Surface that are shared by all Surface implementations in the same way. By default the location is at the origin, the size is 1.0, and the color is black. Also, an AbstractSurface uses a DiffuseShader by default.

Author:
Mike Murray

Constructor Summary
AbstractSurface()
          Sets all values of this AbstractSurface to the defaults specified above.
AbstractSurface(Vector location, double size)
          Sets the location and size of this AbstractSurface to those specifed, and uses the defaults for the other values.
AbstractSurface(Vector location, double size, RGB color)
          Sets the location, size, and color of this AbstractSurface to those specified.
AbstractSurface(Vector location, double size, RGB color, boolean addDefaultDiffuseShader)
          Sets the location, size, and color of this AbstractSurface to those specified.
 
Method Summary
 boolean addShader(Shader shader)
          Appends the specified Shader object to the list of Shader objects used to shade this AbstractSurface.
 void addTexture(Texture texture)
          Appends the specified Texture object to the list of Texture objects used to color this AbstractSurface.
 void addTransform(TransformMatrix transform)
          Applies the transformation represented by the specified TransformMatrix to this AbstractSurface when it is rendered.
 void calculateTransform()
          Calculates the complete transformation that will be applied to this AbstractSurface when it is rendered and stores it for later use.
 RGB getColor()
          Returns the color of this AbstractSurface as an RGB object.
 RGB getColorAt(Vector p)
          Returns the color of this Surface object at the specified point as an RGB object.
 RGB getColorAt(Vector point, boolean transform)
           
 double getIndexOfRefraction()
           
 double getIndexOfRefraction(Vector p)
           
 Vector getLocation()
          Returns the location of this AbstractSurface as a Vector object.
 SurfaceGroup getParent()
          Returns the parent of this AbstractSurface as a SurfaceGroup object.
 double getReflectedPercentage()
           
 double getReflectedPercentage(Vector p)
           
 double getRefractedPercentage()
           
 double getRefractedPercentage(Vector p)
           
 double[] getRotationCoefficients()
          Returns an array of double values containing the angle measurements (in radians) used to rotate this AbstractSurface about the x, y, and z axes when it is rendered as an array of double values.
 double[] getScaleCoefficients()
          Returns an array of double values containing the values used to scale this AbstractSurface on the x, y, and z axes when it is rendered.
 boolean getShadeBack()
          Returns true if the back side of this AbstractSurface should be shaded.
 boolean getShadeFront()
          Returns true if the front side of this AbstractSurface should be shaded.
 ShaderSet getShaderSet()
          Returns a Set object that maintains the Shader objects stored by this AbstractSurface.
 double getSize()
          Returns the size of this AbstractSurface as a double value.
 Texture getTexture(int index)
          Returns the Texture object at the specified index in the list of Texture objects used to color this AbstractSurface.
 Texture[] getTextures()
          Returns the list of Texture objects used to color this AbstractSurface as an array of Texture objects.
 Set getTextureSet()
          Returns a Set object that maintains the Texture objects stored by this AbstractSurface.
 TransformMatrix getTransform()
          Returns the TransformMatrix object used to transform this AbstractSurface when it is rendered.
 TransformMatrix getTransform(boolean include)
          Returns the TransformMatrix object used to transform this AbstractSurface when it is rendered.
 TransformMatrix[] getTransforms()
          Returns the TransformMatrix objects used to transform this Surface object when it is rendered as an array of TransformMatrix objects.
 void removeTexture(int index)
          Removes the Texture object at the specified index from the list of Texture objects used to color this AbstractSurface.
 void removeTransform(int index)
          Removes the TransformMatrix object at the specified index from this Surface object.
 void setColor(RGB color)
          Sets the color of this AbstractSurface to the color represented by the specified RGB object.
 void setIndexOfRefraction(double n)
           
 void setLocation(Vector location)
          Sets the location of this AbstractSurface to the specified Vector object.
 void setParent(SurfaceGroup parent)
          Sets the parent surface group of this AbstractSurface to the specified SurfaceGroup object.
 void setReflectedPercentage(double p)
           
 void setRefractedPercentage(double p)
           
 void setRotationCoefficients(double x, double y, double z)
          Sets the angle measurements (in radians) used to rotate this AbstractSurface about the x, y, and z axes when it is rendered to the specified double values.
 void setScaleCoefficients(double x, double y, double z)
          Sets the values used to scale this AbstractSurface on the x, y, and z axes when it is rendered to the specified double values.
 void setShadeBack(boolean shade)
          Sets the flag indicating that the back side of this AbstractSurface should be shaded to the specified boolean value.
 void setShadeFront(boolean shade)
          Sets the flag indicating that the front side of this AbstractSurface should be shaded to the specified boolean value.
 void setShaders(Shader[] shaders)
          Sets the Shader objects (used to shade this AbstractSurface) to those specified.
 void setShaders(ShaderSet set)
           
 void setSize(double size)
          Sets the size of this AbstractSurface to the specified double value.
 void setTexture(int index, Texture texture)
          Sets the Texture object (used to color this AbstractSurface) at the specified index to the specified Texture object.
 void setTextures(Texture[] textures)
          Sets the Texture objects (used to color this AbstractSurface) to those specified.
 void setTransform(int index, TransformMatrix transform)
          Sets the TransformMatrix object at the specified index used to transform this Surface object when it is rendered to the TransformMatrix object specified.
 void setTransforms(TransformMatrix[] transforms)
          Sets the TransformMatrix objects used to transform this AbstractSurface when it is rendered to those stored in the specified TransformMatrix object array.
 RGB shade(ShaderParameters p)
          Calculates a color value for this AbstractSurface using the sum of the values calculated by the Shader objects stored by this AbstractSurface and the parent of this AbstractSurface and returns this value as an RGB object.
 Mesh triangulate()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.j3d.threeD.raytracer.engine.Surface
getNormalAt, intersect, intersectAt
 

Constructor Detail

AbstractSurface

public AbstractSurface()
Sets all values of this AbstractSurface to the defaults specified above.


AbstractSurface

public AbstractSurface(Vector location,
                       double size)
Sets the location and size of this AbstractSurface to those specifed, and uses the defaults for the other values.


AbstractSurface

public AbstractSurface(Vector location,
                       double size,
                       RGB color)
Sets the location, size, and color of this AbstractSurface to those specified.


AbstractSurface

public AbstractSurface(Vector location,
                       double size,
                       RGB color,
                       boolean addDefaultDiffuseShader)
Sets the location, size, and color of this AbstractSurface to those specified.

Method Detail

setParent

public void setParent(SurfaceGroup parent)
Sets the parent surface group of this AbstractSurface to the specified SurfaceGroup object.


getParent

public SurfaceGroup getParent()
Returns the parent of this AbstractSurface as a SurfaceGroup object.


setShadeFront

public void setShadeFront(boolean shade)
Sets the flag indicating that the front side of this AbstractSurface should be shaded to the specified boolean value.


setShadeBack

public void setShadeBack(boolean shade)
Sets the flag indicating that the back side of this AbstractSurface should be shaded to the specified boolean value.


getShadeFront

public boolean getShadeFront()
Returns true if the front side of this AbstractSurface should be shaded. The "front side" is the side that the Vector object returned by the getNormalAt() method for this AbstractSurface points outward from.

Specified by:
getShadeFront in interface Surface

getShadeBack

public boolean getShadeBack()
Returns true if the back side of this AbstractSurface should be shaded. The "back side" is the side that the vector opposite the Vector object returned by the getNormalAt() method for this AbstractSurface points outward from.

Specified by:
getShadeBack in interface Surface

triangulate

public Mesh triangulate()
Returns:
A Mesh object with location, size, color, scale coefficients, rotation coefficients, and transformations as this AbstractSurface.

setIndexOfRefraction

public void setIndexOfRefraction(double n)

getIndexOfRefraction

public double getIndexOfRefraction()

getIndexOfRefraction

public double getIndexOfRefraction(Vector p)

setReflectedPercentage

public void setReflectedPercentage(double p)

setRefractedPercentage

public void setRefractedPercentage(double p)

getReflectedPercentage

public double getReflectedPercentage()

getReflectedPercentage

public double getReflectedPercentage(Vector p)

getRefractedPercentage

public double getRefractedPercentage()

getRefractedPercentage

public double getRefractedPercentage(Vector p)

setLocation

public void setLocation(Vector location)
Sets the location of this AbstractSurface to the specified Vector object. This method calls calulateTransform() after it is completed.


setSize

public void setSize(double size)
Sets the size of this AbstractSurface to the specified double value.


setScaleCoefficients

public void setScaleCoefficients(double x,
                                 double y,
                                 double z)
Sets the values used to scale this AbstractSurface on the x, y, and z axes when it is rendered to the specified double values. This method calls calculateTransform() after it is completed.


setRotationCoefficients

public void setRotationCoefficients(double x,
                                    double y,
                                    double z)
Sets the angle measurements (in radians) used to rotate this AbstractSurface about the x, y, and z axes when it is rendered to the specified double values. This method calls calculateTransform() after it is completed.


setTransform

public void setTransform(int index,
                         TransformMatrix transform)
Sets the TransformMatrix object at the specified index used to transform this Surface object when it is rendered to the TransformMatrix object specified. This method calls calculateTransform() after it is completed.


setTransforms

public void setTransforms(TransformMatrix[] transforms)
                   throws IllegalArgumentException
Sets the TransformMatrix objects used to transform this AbstractSurface when it is rendered to those stored in the specified TransformMatrix object array. If the specified array is null, an IllegalArgumentException will be thrown. This method calls calculateTransform() after it is completed.

Throws:
IllegalArgumentException

addTransform

public void addTransform(TransformMatrix transform)
Applies the transformation represented by the specified TransformMatrix to this AbstractSurface when it is rendered. This method calls calculateTransform() after it is completed.


removeTransform

public void removeTransform(int index)
Removes the TransformMatrix object at the specified index from this Surface object. This method calls calculateTransform() after it is completed.


calculateTransform

public void calculateTransform()
Calculates the complete transformation that will be applied to this AbstractSurface when it is rendered and stores it for later use. The transformations are applied in the following order: translate (location), scale (size), rotate x, rotate y, rotate z. Other transforms are applied last and in the order they were added.


setTexture

public void setTexture(int index,
                       Texture texture)
Sets the Texture object (used to color this AbstractSurface) at the specified index to the specified Texture object.


setTextures

public void setTextures(Texture[] textures)
Sets the Texture objects (used to color this AbstractSurface) to those specified.


addTexture

public void addTexture(Texture texture)
Appends the specified Texture object to the list of Texture objects used to color this AbstractSurface.


removeTexture

public void removeTexture(int index)
Removes the Texture object at the specified index from the list of Texture objects used to color this AbstractSurface.


getTextureSet

public Set getTextureSet()
Returns a Set object that maintains the Texture objects stored by this AbstractSurface.


setShaders

public void setShaders(Shader[] shaders)
Sets the Shader objects (used to shade this AbstractSurface) to those specified.


setShaders

public void setShaders(ShaderSet set)
Parameters:
set - New ShaderSet object to use for shading.

addShader

public boolean addShader(Shader shader)
Appends the specified Shader object to the list of Shader objects used to shade this AbstractSurface.


getShaderSet

public ShaderSet getShaderSet()
Returns a Set object that maintains the Shader objects stored by this AbstractSurface.


shade

public RGB shade(ShaderParameters p)
Calculates a color value for this AbstractSurface using the sum of the values calculated by the Shader objects stored by this AbstractSurface and the parent of this AbstractSurface and returns this value as an RGB object.

Specified by:
shade in interface Surface
See Also:
Shader

setColor

public void setColor(RGB color)
Sets the color of this AbstractSurface to the color represented by the specified RGB object.


getLocation

public Vector getLocation()
Returns the location of this AbstractSurface as a Vector object.


getSize

public double getSize()
Returns the size of this AbstractSurface as a double value.


getScaleCoefficients

public double[] getScaleCoefficients()
Returns an array of double values containing the values used to scale this AbstractSurface on the x, y, and z axes when it is rendered.


getRotationCoefficients

public double[] getRotationCoefficients()
Returns an array of double values containing the angle measurements (in radians) used to rotate this AbstractSurface about the x, y, and z axes when it is rendered as an array of double values.


getTransform

public TransformMatrix getTransform()
Returns the TransformMatrix object used to transform this AbstractSurface when it is rendered. This TransformMatrix does not represents the transformations due to fixed scaling and rotation.


getTransform

public TransformMatrix getTransform(boolean include)
Returns the TransformMatrix object used to transform this AbstractSurface when it is rendered. If the specified boolean value is true, this TransformMatrix includes the transformations due to fixed scaling and rotation.


getTransforms

public TransformMatrix[] getTransforms()
Returns the TransformMatrix objects used to transform this Surface object when it is rendered as an array of TransformMatrix objects. This array does not include the TransformMatrix objects that account for fixed scaling and rotation.


getTexture

public Texture getTexture(int index)
Returns the Texture object at the specified index in the list of Texture objects used to color this AbstractSurface.


getTextures

public Texture[] getTextures()
Returns the list of Texture objects used to color this AbstractSurface as an array of Texture objects.


getColor

public RGB getColor()
Returns the color of this AbstractSurface as an RGB object.


getColorAt

public RGB getColorAt(Vector p)
Description copied from interface: Surface
Returns the color of this Surface object at the specified point as an RGB object.

Specified by:
getColorAt in interface Surface
Returns:
The color of this AbstractSurface at the specified point as an RGB object.

getColorAt

public RGB getColorAt(Vector point,
                      boolean transform)
Returns:
The color of this AbstractSurface at the specified point as an RGB object.