net.sf.j3d.threeD.raytracer.primitives
Class Triangle

java.lang.Object
  extended by net.sf.j3d.threeD.raytracer.engine.AbstractSurface
      extended by net.sf.j3d.threeD.raytracer.primitives.Triangle
All Implemented Interfaces:
ParticleGroup, Surface

public class Triangle
extends AbstractSurface
implements ParticleGroup

A Triangle object represents a triangle in 3d space.


Constructor Summary
Triangle()
          Constructs a new Triangle object with all vertices at the origin that is black.
Triangle(int p1, int p2, int p3, RGB color, Mesh.VertexData data)
           
Triangle(Vector p1, Vector p2, Vector p3)
          Constructs a new Triangle object with the specified vertices that is black.
Triangle(Vector p1, Vector p2, Vector p3, RGB color)
          Constructs a new Triangle object with the specified vertices with the color represented by the specified RGB object.
 
Method Summary
 RGB getColorAt(Vector p)
          Returns the color of this Surface object at the specified point as an RGB object.
 boolean getInterpolateVertexColor()
           
 Vector getNormalAt(Vector point)
          Returns a Vector object that represents the vector normal to this sphere at the point represented by the specified Vector object.
 double[][] getParticleVertices()
           
 boolean getSmooth()
           
 boolean getUseTransform()
           
 Vector[] getVertices()
           
 boolean intersect(Ray ray)
          Returns true if the ray intersects the 3d surface in real space.
 Intersection intersectAt(Ray ray)
          Returns an Intersection object representing the points along the ray represented by the specified Ray object that intersection between the ray and the triangle represented by this Triangle object occurs.
 void setInterpolateVertexColor(boolean vcolor)
          Controls if vertex colors will be used and color will be interpolated across the triangle.
 void setSmooth(boolean s)
          Sets the smooth flag which indicates if normal vectors should be interpolated.
 void setUseTransform(boolean use)
           
 void setVertices(Vector p1, Vector p2, Vector p3)
          Sets the vertices of this Triangle object to those specified.
 String toString()
           
 
Methods inherited from class net.sf.j3d.threeD.raytracer.engine.AbstractSurface
addShader, addTexture, addTransform, calculateTransform, getColor, getColorAt, getIndexOfRefraction, getIndexOfRefraction, getLocation, getParent, getReflectedPercentage, getReflectedPercentage, getRefractedPercentage, getRefractedPercentage, getRotationCoefficients, getScaleCoefficients, getShadeBack, getShadeFront, getShaderSet, getSize, getTexture, getTextures, getTextureSet, getTransform, getTransform, getTransforms, removeTexture, removeTransform, setColor, setIndexOfRefraction, setLocation, setParent, setReflectedPercentage, setRefractedPercentage, setRotationCoefficients, setScaleCoefficients, setShadeBack, setShadeFront, setShaders, setShaders, setSize, setTexture, setTextures, setTransform, setTransforms, shade, triangulate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Triangle

public Triangle()
Constructs a new Triangle object with all vertices at the origin that is black.


Triangle

public Triangle(Vector p1,
                Vector p2,
                Vector p3)
Constructs a new Triangle object with the specified vertices that is black.


Triangle

public Triangle(Vector p1,
                Vector p2,
                Vector p3,
                RGB color)
Constructs a new Triangle object with the specified vertices with the color represented by the specified RGB object.


Triangle

public Triangle(int p1,
                int p2,
                int p3,
                RGB color,
                Mesh.VertexData data)
Method Detail

setVertices

public void setVertices(Vector p1,
                        Vector p2,
                        Vector p3)
Sets the vertices of this Triangle object to those specified. The Vector objects passed to this method WILL be stored by the Triangle object, but changes made to the Vector objects WILL NOT be reflected in the calculation of smooth surface normals and of intersections. To change the Vector coordinates you must call the setVertices method again.


getVertices

public Vector[] getVertices()
Returns:
An array of Vector objects representing the vertices of this Triangle object.

setUseTransform

public void setUseTransform(boolean use)
Parameters:
use - If set to true, the intersection methods will apply the transformations stored by this Triangle object. Otherwise, transformation will not be used. Setting to false is useful if the Triangle vertices are absolute coordinates and/or if the Triangle is part of a Mesh and the Mesh will apply all needed transformation.

getUseTransform

public boolean getUseTransform()
Returns:
True if the intersection methods will apply the transformations stored by this Triangle object, false otherwise.

setInterpolateVertexColor

public void setInterpolateVertexColor(boolean vcolor)
Controls if vertex colors will be used and color will be interpolated across the triangle.

Parameters:
vcolor - If true, color will be interpolated across the triangle based on vertex colors and then mixed with the color of the triangle. If false, the color of the triangle will be used all across the surface.

getInterpolateVertexColor

public boolean getInterpolateVertexColor()
Returns:
True if color will be interpolated across the triangle based on vertex colors and then mixed with the color of the triangle. False if the color of the triangle will be used all across the surface.

setSmooth

public void setSmooth(boolean s)
Sets the smooth flag which indicates if normal vectors should be interpolated.

Parameters:
s - Value to use.

getSmooth

public boolean getSmooth()
Returns:
The smooth flag which indicates if normal vectors should be interpolated.

getParticleVertices

public double[][] getParticleVertices()
Specified by:
getParticleVertices in interface ParticleGroup
See Also:
ParticleGroup.getParticleVertices()

getNormalAt

public Vector getNormalAt(Vector point)
Returns a Vector object that represents the vector normal to this sphere at the point represented by the specified Vector object.

Specified by:
getNormalAt in interface Surface

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
Overrides:
getColorAt in class AbstractSurface
Returns:
The color of this AbstractSurface at the specified point as an RGB object.

intersect

public boolean intersect(Ray ray)
Description copied from interface: Surface
Returns true if the ray intersects the 3d surface in real space.

Specified by:
intersect in interface Surface
Returns:
True if the ray represented by the specified Ray object intersects the triangle represented by this Triangle object.

intersectAt

public Intersection intersectAt(Ray ray)
Returns an Intersection object representing the points along the ray represented by the specified Ray object that intersection between the ray and the triangle represented by this Triangle object occurs.

Specified by:
intersectAt in interface Surface

toString

public String toString()
Overrides:
toString in class Object