org.openmali.spatial.polygons
Class Triangle

java.lang.Object
  extended by org.openmali.spatial.polygons.Polygon
      extended by org.openmali.spatial.polygons.Triangle

public class Triangle
extends Polygon

A Triangle is composed of three vertices.


Constructor Summary
Triangle()
           
Triangle(int features, int texCoordsSize)
           
 
Method Summary
 void addFeature(int feature)
          
 float getAngleA()
          Calculates angle between the edges AC and AB.
 float getAngleB()
          Calculates angle between the edges BA and BC.
 float getAngleC()
          Calculates angle between the edges CB and CA.
 Vector3f getFaceNormal()
          Calculates and returns the face normal.
 void getFaceNormal(Vector3f faceNormal)
          Calculates the face normal and writes it to the parameter.
 Vector3f getFaceNormalACAB()
          Calculates the face normal from the cross product of edge AC and AB.
 void getFaceNormalACAB(Vector3f faceNormal)
          Calculates the face normal from the cross product of edge AC and AB.
 Vector3f getFaceNormalBABC()
          Calculates the face normal from the cross product of edge BA and BC.
 void getFaceNormalBABC(Vector3f faceNormal)
          Calculates the face normal from the cross product of edge BA and BC.
 Vector3f getFaceNormalCBCA()
          Calculates the face normal from the cross product of edge AB and AC.
 void getFaceNormalCBCA(Vector3f faceNormal)
          Calculates the face normal from the cross product of edge AB and AC.
 void getVertexA(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 void getVertexB(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 void getVertexC(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 Colorf getVertexColorA()
           
 void getVertexColorA(Colorf color)
           
 Colorf getVertexColorB()
           
 void getVertexColorB(Colorf color)
           
 Colorf getVertexColorC()
           
 void getVertexColorC(Colorf color)
           
 void getVertexColors(Colorf colorA, Colorf colorB, Colorf colorC)
           
 Point3f getVertexCoordA()
           
 void getVertexCoordA(Tuple3f coord)
           
 Point3f getVertexCoordB()
           
 void getVertexCoordB(Tuple3f coord)
           
 Point3f getVertexCoordC()
           
 void getVertexCoordC(Tuple3f coord)
           
 void getVertexCoords(Tuple3f coordA, Tuple3f coordB, Tuple3f coordC)
           
 int getVertexIndexA()
           
 int getVertexIndexB()
           
 int getVertexIndexC()
           
 Vector3f getVertexNormalA()
           
 void getVertexNormalA(Vector3f normal)
           
 Vector3f getVertexNormalB()
           
 void getVertexNormalB(Vector3f normal)
           
 Vector3f getVertexNormalC()
           
 void getVertexNormalC(Vector3f normal)
           
 void getVertexNormals(Vector3f normalA, Vector3f normalB, Vector3f normalC)
           
 TexCoord2f getVertexTexCoordA()
           
 void getVertexTexCoordA(TexCoord2f texCoord)
           
 TexCoord2f getVertexTexCoordB()
           
 void getVertexTexCoordB(TexCoord2f texCoord)
           
 TexCoord2f getVertexTexCoordC()
           
 void getVertexTexCoordC(TexCoord2f texCoord)
           
 void getVertexTexCoords(TexCoord2f texCoordA, TexCoord2f texCoordB, TexCoord2f texCoordC)
           
 float intersects(Point3f rayOrigin, Vector3f rayDirection)
          Tests the triangle for intersection with a ray.
 float intersects(Ray3f ray)
          Tests the triangle for intersection with a ray.
 float intersects(Ray3f ray, float nearestDist)
          Tests the triangle for intersection with a ray.
 boolean quickIntersectionTest(Ray3f pickRay)
          Does a quick ray-intersection test, that doesn't very precise.
 void setFeatures(int features)
          
 void setVertexA(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 void setVertexB(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 void setVertexC(Tuple3f coord, Vector3f normal, Colorf color, TexCoord2f texCoord)
           
 void setVertexColorA(Colorf color)
           
 void setVertexColorB(Colorf color)
           
 void setVertexColorC(Colorf color)
           
 void setVertexColors(Colorf colorA, Colorf colorB, Colorf colorC)
           
 void setVertexCoordA(Tuple3f coord)
           
 void setVertexCoordB(Tuple3f coord)
           
 void setVertexCoordC(Tuple3f coord)
           
 void setVertexCoords(Tuple3f coordA, Tuple3f coordB, Tuple3f coordC)
           
 void setVertexIndexA(int index)
          Sets the index of the vertexA (just meta info).
 void setVertexIndexB(int index)
          Sets the index of the vertexB (just meta info).
 void setVertexIndexC(int index)
          Sets the index of the vertexC (just meta info).
 void setVertexIndices(int indexA, int indexB, int indexC)
          Sets the indices of the vertices A, B, C (just meta info).
 void setVertexNormalA(Vector3f normal)
           
 void setVertexNormalB(Vector3f normal)
           
 void setVertexNormalC(Vector3f normal)
           
 void setVertexNormals(Vector3f normalA, Vector3f normalB, Vector3f normalC)
           
 void setVertexTexCoordA(TexCoord2f texCoord)
           
 void setVertexTexCoordB(TexCoord2f texCoord)
           
 void setVertexTexCoordC(TexCoord2f texCoord)
           
 void setVertexTexCoords(TexCoord2f texCoordA, TexCoord2f texCoordB, TexCoord2f texCoordC)
           
 int sign3D(Tuple3f a, Tuple3f b, Tuple3f c, Tuple3f d)
           
 void transform(Matrix4f matrix)
           
 
Methods inherited from class org.openmali.spatial.polygons.Polygon
getFeatures, getTexCoordsSize, hasFeature, removeFeature, setTexCoordsSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Triangle

public Triangle(int features,
                int texCoordsSize)

Triangle

public Triangle()
Method Detail

setFeatures

public void setFeatures(int features)

Overrides:
setFeatures in class Polygon

addFeature

public void addFeature(int feature)

Overrides:
addFeature in class Polygon

setVertexCoordA

public void setVertexCoordA(Tuple3f coord)

setVertexCoordB

public void setVertexCoordB(Tuple3f coord)

setVertexCoordC

public void setVertexCoordC(Tuple3f coord)

getVertexCoordA

public void getVertexCoordA(Tuple3f coord)

getVertexCoordA

public Point3f getVertexCoordA()

getVertexCoordB

public void getVertexCoordB(Tuple3f coord)

getVertexCoordB

public Point3f getVertexCoordB()

getVertexCoordC

public void getVertexCoordC(Tuple3f coord)

getVertexCoordC

public Point3f getVertexCoordC()

setVertexCoords

public void setVertexCoords(Tuple3f coordA,
                            Tuple3f coordB,
                            Tuple3f coordC)

getVertexCoords

public void getVertexCoords(Tuple3f coordA,
                            Tuple3f coordB,
                            Tuple3f coordC)

setVertexNormalA

public void setVertexNormalA(Vector3f normal)

setVertexNormalB

public void setVertexNormalB(Vector3f normal)

setVertexNormalC

public void setVertexNormalC(Vector3f normal)

getVertexNormalA

public void getVertexNormalA(Vector3f normal)

getVertexNormalA

public Vector3f getVertexNormalA()

getVertexNormalB

public void getVertexNormalB(Vector3f normal)

getVertexNormalB

public Vector3f getVertexNormalB()

getVertexNormalC

public void getVertexNormalC(Vector3f normal)

getVertexNormalC

public Vector3f getVertexNormalC()

setVertexNormals

public void setVertexNormals(Vector3f normalA,
                             Vector3f normalB,
                             Vector3f normalC)

getVertexNormals

public void getVertexNormals(Vector3f normalA,
                             Vector3f normalB,
                             Vector3f normalC)

setVertexColorA

public void setVertexColorA(Colorf color)

setVertexColorB

public void setVertexColorB(Colorf color)

setVertexColorC

public void setVertexColorC(Colorf color)

getVertexColorA

public void getVertexColorA(Colorf color)

getVertexColorA

public Colorf getVertexColorA()

getVertexColorB

public void getVertexColorB(Colorf color)

getVertexColorB

public Colorf getVertexColorB()

getVertexColorC

public void getVertexColorC(Colorf color)

getVertexColorC

public Colorf getVertexColorC()

setVertexColors

public void setVertexColors(Colorf colorA,
                            Colorf colorB,
                            Colorf colorC)

getVertexColors

public void getVertexColors(Colorf colorA,
                            Colorf colorB,
                            Colorf colorC)

setVertexTexCoordA

public void setVertexTexCoordA(TexCoord2f texCoord)

setVertexTexCoordB

public void setVertexTexCoordB(TexCoord2f texCoord)

setVertexTexCoordC

public void setVertexTexCoordC(TexCoord2f texCoord)

getVertexTexCoordA

public void getVertexTexCoordA(TexCoord2f texCoord)

getVertexTexCoordA

public TexCoord2f getVertexTexCoordA()

getVertexTexCoordB

public void getVertexTexCoordB(TexCoord2f texCoord)

getVertexTexCoordB

public TexCoord2f getVertexTexCoordB()

getVertexTexCoordC

public void getVertexTexCoordC(TexCoord2f texCoord)

getVertexTexCoordC

public TexCoord2f getVertexTexCoordC()

setVertexTexCoords

public void setVertexTexCoords(TexCoord2f texCoordA,
                               TexCoord2f texCoordB,
                               TexCoord2f texCoordC)

getVertexTexCoords

public void getVertexTexCoords(TexCoord2f texCoordA,
                               TexCoord2f texCoordB,
                               TexCoord2f texCoordC)

setVertexA

public void setVertexA(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

getVertexA

public void getVertexA(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

setVertexB

public void setVertexB(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

getVertexB

public void getVertexB(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

setVertexC

public void setVertexC(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

getVertexC

public void getVertexC(Tuple3f coord,
                       Vector3f normal,
                       Colorf color,
                       TexCoord2f texCoord)

getAngleA

public float getAngleA()
Calculates angle between the edges AC and AB.


getAngleB

public float getAngleB()
Calculates angle between the edges BA and BC.


getAngleC

public float getAngleC()
Calculates angle between the edges CB and CA.


getFaceNormalACAB

public void getFaceNormalACAB(Vector3f faceNormal)
Calculates the face normal from the cross product of edge AC and AB.

Parameters:
faceNormal -

getFaceNormalACAB

public Vector3f getFaceNormalACAB()
Calculates the face normal from the cross product of edge AC and AB.


getFaceNormalBABC

public void getFaceNormalBABC(Vector3f faceNormal)
Calculates the face normal from the cross product of edge BA and BC.

Parameters:
faceNormal -

getFaceNormalBABC

public Vector3f getFaceNormalBABC()
Calculates the face normal from the cross product of edge BA and BC.


getFaceNormalCBCA

public void getFaceNormalCBCA(Vector3f faceNormal)
Calculates the face normal from the cross product of edge AB and AC.

Parameters:
faceNormal -

getFaceNormalCBCA

public Vector3f getFaceNormalCBCA()
Calculates the face normal from the cross product of edge AB and AC.


getFaceNormal

public void getFaceNormal(Vector3f faceNormal)
Calculates the face normal and writes it to the parameter.

Parameters:
faceNormal -

getFaceNormal

public Vector3f getFaceNormal()
Calculates and returns the face normal.


setVertexIndexA

public void setVertexIndexA(int index)
Sets the index of the vertexA (just meta info).

Parameters:
index -

getVertexIndexA

public int getVertexIndexA()
Returns:
the index of the vertexA (just meta info).

setVertexIndexB

public void setVertexIndexB(int index)
Sets the index of the vertexB (just meta info).

Parameters:
index -

getVertexIndexB

public int getVertexIndexB()
Returns:
the index of the vertexB (just meta info).

setVertexIndexC

public void setVertexIndexC(int index)
Sets the index of the vertexC (just meta info).

Parameters:
index -

getVertexIndexC

public int getVertexIndexC()
Returns:
the index of the vertexC (just meta info).

setVertexIndices

public void setVertexIndices(int indexA,
                             int indexB,
                             int indexC)
Sets the indices of the vertices A, B, C (just meta info).

Parameters:
indexA -
indexB -
indexC -

sign3D

public int sign3D(Tuple3f a,
                  Tuple3f b,
                  Tuple3f c,
                  Tuple3f d)

quickIntersectionTest

public boolean quickIntersectionTest(Ray3f pickRay)
Does a quick ray-intersection test, that doesn't very precise. It provides a reliable negative-boolean result.

Parameters:
pickRay -
Returns:
true, if an intersection is possible

intersects

public float intersects(Point3f rayOrigin,
                        Vector3f rayDirection)
Tests the triangle for intersection with a ray.

Parameters:
rayOrigin -
rayDirection -
Returns:
the distance between the ray origin and the intersection point

intersects

public float intersects(Ray3f ray)
Tests the triangle for intersection with a ray.

Parameters:
ray -
Returns:
the distance between the ray origin and the intersection point

intersects

public float intersects(Ray3f ray,
                        float nearestDist)
Tests the triangle for intersection with a ray.
This firs uses quickIntersectionTest() to cheaply test for a possible intersection.

Parameters:
ray -
nearestDist - the nearest distance to be accepted (for optimizations)
Returns:
the distance between the ray origin and the intersection point

transform

public void transform(Matrix4f matrix)