Package com.ardor3d.math
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 Summary
-
Constructor Summary
ConstructorDescriptionTriangle()
Construct a new, mutable triangle with all points at 0,0,0 and an index of 0.Triangle
(ReadOnlyTriangle source) Copy constructor.Triangle
(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC) Construct a new, mutable triangle using the given points and an index of 0.Triangle
(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, int index) Constructs a new triangle using the given points and index. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Recalculates the center point of this triangle by averaging the triangle's three points.protected void
Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA.clone()
boolean
static final Triangle
get
(int index) getA()
getB()
getC()
Obtains the center point of this triangle...int
getIndex()
Obtains the unit length normal vector of this triangle...int
hashCode()
static boolean
Check a triangle... if it is null or its points are invalid, return false.void
read
(InputCapsule capsule) void
Used with serialization.static final void
Releases a Triangle back to be used by a future call to fetchTempInstance.void
set
(int index, ReadOnlyVector3 point) Sets a point to a new value.set
(ReadOnlyTriangle source) Copies the values of the given source Triangle into this Triangle.void
setA
(ReadOnlyVector3 pointA) Sets the first point of this triangle to the values of the given vector.void
setB
(ReadOnlyVector3 pointB) Sets the second point of this triangle to the values of the given vector.void
setC
(ReadOnlyVector3 pointC) Sets the third point of this triangle to the values of the given vector.void
setIndex
(int index) Sets the index value of this triangle to the given int value.toString()
void
write
(OutputCapsule capsule) void
Used with serialization.
-
Field Details
-
_pointA
-
_pointB
-
_pointC
-
_center
-
_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
Copy constructor.- Parameters:
source
- the triangle to copy from.
-
Triangle
Construct a new, mutable triangle using the given points and an index of 0.- Parameters:
pointA
- the point ApointB
- the point BpointC
- the point C
-
Triangle
Constructs a new triangle using the given points and index.- Parameters:
pointA
- the point ApointB
- the point BpointC
- the point Cindex
- the index
-
-
Method Details
-
set
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 interfaceReadOnlyTriangle
-
get
- Specified by:
get
in interfaceReadOnlyTriangle
-
getA
- Specified by:
getA
in interfaceReadOnlyTriangle
-
getB
- Specified by:
getB
in interfaceReadOnlyTriangle
-
getC
- Specified by:
getC
in interfaceReadOnlyTriangle
-
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 interfaceReadOnlyTriangle
- Returns:
- the normal vector
- Throws:
NullPointerException
- if store is null.
-
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 interfaceReadOnlyTriangle
-
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
Sets the first point of this triangle to the values of the given vector.- Parameters:
pointA
- the point A to set
-
setB
Sets the second point of this triangle to the values of the given vector.- Parameters:
pointB
- the point B to set
-
setC
Sets the third point of this triangle to the values of the given vector.- Parameters:
pointC
- the point C to set
-
set
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
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
-
hashCode
public int hashCode() -
equals
-
clone
- Specified by:
clone
in interfaceReadOnlyTriangle
- Overrides:
clone
in classObject
-
getClassTag
- Specified by:
getClassTag
in interfaceSavable
-
write
- Specified by:
write
in interfaceSavable
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Throws:
IOException
-
readExternal
Used with serialization. Not to be called manually.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- ObjectInput- Throws:
IOException
- if something wrong occurs while readingClassNotFoundException
- if a class is not found
-
writeExternal
Used with serialization. Not to be called manually.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- ObjectOutput- Throws:
IOException
- if something wrong occurs while writing
-
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
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.
-