Class Triangle

java.lang.Object
com.ardor3d.math.Triangle
All Implemented Interfaces:
Poolable, ReadOnlyTriangle, Savable, Externalizable, Serializable, Cloneable

public class Triangle extends Object implements Cloneable, Savable, Externalizable, ReadOnlyTriangle, Poolable
Triangle is a math class defining a three sided polygon by three points in space.
See Also:
  • Field Details

    • _pointA

      protected final Vector3 _pointA
    • _pointB

      protected final Vector3 _pointB
    • _pointC

      protected final Vector3 _pointC
    • _center

      protected transient Vector3 _center
    • _normal

      protected transient Vector3 _normal
    • _index

      protected int _index
  • Constructor Details

    • Triangle

      public Triangle()
      Construct a new, mutable triangle with all points at 0,0,0 and an index of 0.
    • Triangle

      public Triangle(ReadOnlyTriangle source)
      Copy constructor.
      Parameters:
      source - the triangle to copy from.
    • Triangle

      public Triangle(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC)
      Construct a new, mutable triangle using the given points and an index of 0.
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
    • Triangle

      public Triangle(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, int index)
      Constructs a new triangle using the given points and index.
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      index - the index
  • Method Details

    • set

      public Triangle set(ReadOnlyTriangle source)
      Copies the values of the given source Triangle into this Triangle.
      Parameters:
      source - the source triangle
      Returns:
      this Triangle for chaining
      Throws:
      NullPointerException - if source is null.
    • getIndex

      public int getIndex()
      Specified by:
      getIndex in interface ReadOnlyTriangle
    • get

      public ReadOnlyVector3 get(int index)
      Specified by:
      get in interface ReadOnlyTriangle
    • getA

      public ReadOnlyVector3 getA()
      Specified by:
      getA in interface ReadOnlyTriangle
    • getB

      public ReadOnlyVector3 getB()
      Specified by:
      getB in interface ReadOnlyTriangle
    • getC

      public ReadOnlyVector3 getC()
      Specified by:
      getC in interface ReadOnlyTriangle
    • getNormal

      public ReadOnlyVector3 getNormal()
      Obtains the unit length normal vector of this triangle... Will create and recalculate this normal vector if this is the first request, or if one of the points on the triangle has changed since the last request.
      Specified by:
      getNormal in interface ReadOnlyTriangle
      Returns:
      the normal vector
      Throws:
      NullPointerException - if store is null.
    • getCenter

      public ReadOnlyVector3 getCenter()
      Obtains the center point of this triangle... Will create and recalculate this point if this is the first request, or if one of the points on the triangle has changed since the last request.
      Specified by:
      getCenter in interface ReadOnlyTriangle
    • setIndex

      public void setIndex(int index)
      Sets the index value of this triangle to the given int value.
      Parameters:
      index - the index to set
    • setA

      public void setA(ReadOnlyVector3 pointA)
      Sets the first point of this triangle to the values of the given vector.
      Parameters:
      pointA - the point A to set
    • setB

      public void setB(ReadOnlyVector3 pointB)
      Sets the second point of this triangle to the values of the given vector.
      Parameters:
      pointB - the point B to set
    • setC

      public void setC(ReadOnlyVector3 pointC)
      Sets the third point of this triangle to the values of the given vector.
      Parameters:
      pointC - the point C to set
    • set

      public void set(int index, ReadOnlyVector3 point)
      Sets a point to a new value.
      Parameters:
      index - the index of the point to set (0-2, corresponding to A-C)
      point - the new value
      Throws:
      IllegalArgumentException - if index is not in [0, 2]
    • calculateCenter

      protected void calculateCenter()
      Recalculates the center point of this triangle by averaging the triangle's three points.
    • calculateNormal

      protected void calculateNormal()
      Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA.
    • isValid

      public static boolean isValid(Triangle triangle)
      Check a triangle... if it is null or its points are invalid, return false. Else return true.
      Parameters:
      triangle - the triangle to check
      Returns:
      true or false as stated above.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the string representation of this triangle.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      returns a unique code for this triangle object based on its values. If two triangles have the same points and index, they will return the same hash code value.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare for equality
      Returns:
      true if this triangle and the provided triangle have the same index and point values.
    • clone

      public Triangle clone()
      Specified by:
      clone in interface ReadOnlyTriangle
      Overrides:
      clone in class Object
    • getClassTag

      public Class<? extends Triangle> getClassTag()
      Specified by:
      getClassTag in interface Savable
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Used with serialization. Not to be called manually.
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - ObjectInput
      Throws:
      IOException - if something wrong occurs while reading
      ClassNotFoundException - if a class is not found
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Used with serialization. Not to be called manually.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - ObjectOutput
      Throws:
      IOException - if something wrong occurs while writing
    • fetchTempInstance

      public static final Triangle fetchTempInstance()
      Returns:
      An instance of Triangle that is intended for temporary use in calculations and so forth. Multiple calls to the method should return instances of this class that are not currently in use.
    • releaseTempInstance

      public static final void releaseTempInstance(Triangle tri)
      Releases a Triangle back to be used by a future call to fetchTempInstance. TAKE CARE: this Triangle object should no longer have other classes referencing it or "Bad Things" will happen.
      Parameters:
      tri - the Triangle to release.