glmodel
Class GL_Triangle

java.lang.Object
  extended by glmodel.GL_Triangle

public class GL_Triangle
extends java.lang.Object

Describes a triangular face. Holds references to three vertices, their normals and texture coodinates. Vertex normals are stored here and not in the Vertex object because a vertex may be shared between two or more faces, and the faces may have very different normals (ie. if the faces are at a 90 degree angle and make a sharp edge). To smooth normals and preserve sharp edges, the Triangle object holds the neighboring triangles for each vert. Based on the angles between this triangle and its neighbors, the smoothing algorithm can decide whether to smooth the normals across the triangles, or to use the face normal to create a hard edge. jun 2006: added makeClone()


Field Summary
 int groupID
           
 int ID
           
 GL_Vector n
           
 java.util.ArrayList neighborsP1
           
 java.util.ArrayList neighborsP2
           
 java.util.ArrayList neighborsP3
           
 GL_Vector norm1
           
 GL_Vector norm2
           
 GL_Vector norm3
           
 GL_Vertex p1
           
 GL_Vertex p2
           
 GL_Vertex p3
           
 GL_Vector uvw1
           
 GL_Vector uvw2
           
 GL_Vector uvw3
           
 float Zdepth
           
 
Constructor Summary
GL_Triangle(GL_Vertex a, GL_Vertex b, GL_Vertex c)
           
 
Method Summary
 void calcZdepth()
          Calculate average screen Z depth of this triangle.
 GL_Vector getCenter()
           
 GL_Vector getWeightedNormal()
           
 GL_Triangle makeClone()
           
static boolean onSameSurface(GL_Triangle t1, GL_Triangle t2, float cos_angle)
          Return true if two triangles should be smoothed as one surface.
 void recalcFaceNormal()
          Calculate the face normal for this triangle
 GL_Vector recalcVertexNormal(java.util.ArrayList neighbors)
          Recalculate the vertex normal, by averagin the normals of the neighboring triangles.
 void resetNeighbors()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

p1

public GL_Vertex p1

p2

public GL_Vertex p2

p3

public GL_Vertex p3

norm1

public GL_Vector norm1

norm2

public GL_Vector norm2

norm3

public GL_Vector norm3

uvw1

public GL_Vector uvw1

uvw2

public GL_Vector uvw2

uvw3

public GL_Vector uvw3

neighborsP1

public java.util.ArrayList neighborsP1

neighborsP2

public java.util.ArrayList neighborsP2

neighborsP3

public java.util.ArrayList neighborsP3

n

public GL_Vector n

Zdepth

public float Zdepth

ID

public int ID

groupID

public int groupID
Constructor Detail

GL_Triangle

public GL_Triangle(GL_Vertex a,
                   GL_Vertex b,
                   GL_Vertex c)
Method Detail

recalcFaceNormal

public void recalcFaceNormal()
Calculate the face normal for this triangle


recalcVertexNormal

public GL_Vector recalcVertexNormal(java.util.ArrayList neighbors)
Recalculate the vertex normal, by averagin the normals of the neighboring triangles. The neighbor list holds only triangles that we want to average with this vertex.

Parameters:
neighbors - neighboring triangles for this vert
Returns:
vertex normal
See Also:
GL_Object.registerNeighbors()

getWeightedNormal

public GL_Vector getWeightedNormal()

getCenter

public GL_Vector getCenter()

resetNeighbors

public void resetNeighbors()

calcZdepth

public void calcZdepth()
Calculate average screen Z depth of this triangle. This function requires that the vertex screen positions have been set (vertex.posS).

See Also:
GL_Mesh.project()

onSameSurface

public static boolean onSameSurface(GL_Triangle t1,
                                    GL_Triangle t2,
                                    float cos_angle)
Return true if two triangles should be smoothed as one surface. cos_angle is the minumum angle for smoothing. If the angle between the faces is > cos_angle, then the faces are considered to be a continuous surface. Ie. 90 degrees is a sharp corner, 180 degrees is a flat surface.


makeClone

public GL_Triangle makeClone()