org.mt4j.util.opengl
Class GluTrianglulator

java.lang.Object
  extended by javax.media.opengl.glu.GLUtessellatorCallbackAdapter
      extended by org.mt4j.util.opengl.GluTrianglulator
All Implemented Interfaces:
javax.media.opengl.glu.GLUtessellatorCallback

public class GluTrianglulator
extends javax.media.opengl.glu.GLUtessellatorCallbackAdapter

    

This tesselator produces no triangle strips/fans but only pure triangles.

Author:
Chris

Constructor Summary
GluTrianglulator(processing.core.PApplet p)
          Creates a new GLU tesselator object and defines callback methods, which the tesselator will later call.
 
Method Summary
 void begin(int type)
           
 void combine(double[] coords, java.lang.Object[] data, float[] weight, java.lang.Object[] outData)
          CombineCallback is used to create a new vertex when edges intersect.
 void deleteTess()
          Delete tess.
 void edgeFlag(boolean boundaryEdge)
           
 void end()
           
 void error(int errnum)
           
 javax.media.opengl.glu.GLUtessellator getTesselator()
          Gets the tesselator.
 java.util.List<Vertex> getTriList()
          Gets the tri list.
 java.util.List<Vertex> tesselate(java.util.List<Vertex[]> contours)
          Tesselate.
 java.util.List<Vertex> tesselate(java.util.List<Vertex[]> contours, int windingRule)
          Triangulates the given vertex contours and returns a list of triangles.
 java.util.List<Vertex> tesselate(Vertex[] contour, int windingRule)
          Tesselates/triangulates the given contours with the given winding rule (ie.
 MTTriangleMesh toTriangleMesh(java.util.List<Vertex[]> contours, int windingRule)
          Triangulates the given vertex arrays and creates a single triangle mesh.
 void vertex(java.lang.Object vertexData)
          Callback function.
 void vertexData(java.lang.Object vertexData, java.lang.Object polygonData)
           
 
Methods inherited from class javax.media.opengl.glu.GLUtessellatorCallbackAdapter
beginData, combineData, edgeFlagData, endData, errorData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GluTrianglulator

public GluTrianglulator(processing.core.PApplet p)
Creates a new GLU tesselator object and defines callback methods, which the tesselator will later call. These are defined in this class.
NOTE: always remember to delete the used triangulator with deleteTess() after use to prevent memory leaking!

Parameters:
p - the processing context
Method Detail

edgeFlag

public void edgeFlag(boolean boundaryEdge)
Specified by:
edgeFlag in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
edgeFlag in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter

deleteTess

public void deleteTess()
Delete tess.


toTriangleMesh

public MTTriangleMesh toTriangleMesh(java.util.List<Vertex[]> contours,
                                     int windingRule)
Triangulates the given vertex arrays and creates a single triangle mesh.

Parameters:
contours - the contours
windingRule - the winding rule
Returns:
the MT triangle mesh

tesselate

public java.util.List<Vertex> tesselate(Vertex[] contour,
                                        int windingRule)
Tesselates/triangulates the given contours with the given winding rule (ie. GLU.GLU_TESS_WINDING_ODD).

Parameters:
contour - the contour
windingRule - the winding rule
Returns:
the list< vertex>

tesselate

public java.util.List<Vertex> tesselate(java.util.List<Vertex[]> contours)
Tesselate.

Parameters:
contours - the contours
Returns:
the list< vertex>

tesselate

public java.util.List<Vertex> tesselate(java.util.List<Vertex[]> contours,
                                        int windingRule)
Triangulates the given vertex contours and returns a list of triangles.

Parameters:
contours - the vertex arrays to triangulate into one list of triangles
windingRule - the winding rule which determines which parts of the specified shape is "inside" or "outside" the shape.
Returns:
the list< vertex>
See Also:
exmaple GLU.GLU_TESS_WINDING_ODD the produced triangles

begin

public void begin(int type)
Specified by:
begin in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
begin in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter

vertex

public void vertex(java.lang.Object vertexData)
Callback function. Gets called by the tesselator when a new vertex should be drawn.

Specified by:
vertex in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
vertex in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter
Parameters:
vertexData - the vertex data

vertexData

public void vertexData(java.lang.Object vertexData,
                       java.lang.Object polygonData)
Specified by:
vertexData in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
vertexData in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter

combine

public void combine(double[] coords,
                    java.lang.Object[] data,
                    float[] weight,
                    java.lang.Object[] outData)
CombineCallback is used to create a new vertex when edges intersect. coordinate location is trivial to calculate, but weight[4] may be used to average color, normal, or texture coordinate data.

This is called before the call to the vertex-callback method,

Specified by:
combine in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
combine in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter
Parameters:
coords - the coords
data - the data
weight - the weight
outData - the out data

end

public void end()
Specified by:
end in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
end in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter

error

public void error(int errnum)
Specified by:
error in interface javax.media.opengl.glu.GLUtessellatorCallback
Overrides:
error in class javax.media.opengl.glu.GLUtessellatorCallbackAdapter

getTesselator

public javax.media.opengl.glu.GLUtessellator getTesselator()
Gets the tesselator.

Returns:
the tesselator

getTriList

public java.util.List<Vertex> getTriList()
Gets the tri list.

Returns:
the tri list