Package com.jme3.math
Class Triangle
java.lang.Object
com.jme3.math.AbstractTriangle
com.jme3.math.Triangle
- All Implemented Interfaces:
Collidable
,Savable
,Serializable
,Cloneable
Describes a triangle in terms of its vertex locations, with auxiliary storage
for its centroid, normal vector, projection, and index.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Recalculates the stored centroid based on the current vertex locations.void
Recalculates the stored normal based on the current vertex locations.clone()
Creates a copy of this triangle.static Vector3f
computeTriangleNormal
(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f store) get
(int i) Accesses the location of the indexed vertex.get1()
Accesses the location of the first vertex.get2()
Accesses the location of the 2nd vertex.get3()
Accesses the location of the 3rd vertex.Accesses the stored centroid (the average of the 3 vertex locations) calculating it if it is null.int
getIndex()
Returns the index of this triangle, used to identify it in an OBBTree.Accesses the stored normal, updating it if it is null.float
Returns the projection of the vertices relative to the line origin.void
read
(JmeImporter importer) De-serializes this triangle from the specified importer, for example when loading from a J3O file.void
set
(int i, float x, float y, float z) Alters the location of the indexed vertex and deletes the stored centroid and normal.void
Alters the location of the indexed vertex and deletes the stored centroid and normal.void
Alters the locations of all 3 vertices and deletes the stored centroid and normal.void
Alters the location of the first vertex and deletes the stored centroid and normal.void
Alters the location of the 2nd vertex and deletes the stored centroid and normal.void
Alters the location of the 3rd vertex and deletes the stored centroid and normal.void
Alters the stored centroid without affecting the stored normal or any vertex locations.void
setIndex
(int index) Alters the index of this triangle, used to identify it in an OBBTree.void
Alters the stored normal without affecting the stored centroid or any vertex locations.void
setProjection
(float projection) Alters the projection of the vertices relative to the line origin.void
write
(JmeExporter e) Serializes this triangle to the specified exporter, for example when saving to a J3O file.Methods inherited from class com.jme3.math.AbstractTriangle
collideWith
-
Constructor Details
-
Triangle
public Triangle()Instantiate a zero-size triangle at the origin. -
Triangle
Instantiates a triangle with the specified vertex locations. Vertices should be listed in the desired winding order, typically counter-clockwise.- Parameters:
p1
- the location of the first vertex (not null, unaffected)p2
- the location of the 2nd vertex (not null, unaffected)p3
- the location of the 3rd vertex (not null, unaffected)
-
-
Method Details
-
get
Accesses the location of the indexed vertex.- Parameters:
i
- the index of the vertex to access (0, 1, or 2)- Returns:
- a pre-existing location vector, or null if the index is invalid
-
get1
Accesses the location of the first vertex.- Specified by:
get1
in classAbstractTriangle
- Returns:
- the pre-existing location vector (not null)
-
get2
Accesses the location of the 2nd vertex.- Specified by:
get2
in classAbstractTriangle
- Returns:
- the pre-existing location vector (not null)
-
get3
Accesses the location of the 3rd vertex.- Specified by:
get3
in classAbstractTriangle
- Returns:
- the pre-existing location vector (not null)
-
set
Alters the location of the indexed vertex and deletes the stored centroid and normal.- Parameters:
i
- the index of the vertex to alter (0, 1, or 2)point
- the desired location (not null, unaffected)
-
set
public void set(int i, float x, float y, float z) Alters the location of the indexed vertex and deletes the stored centroid and normal.- Parameters:
i
- the index of the vertex to alter (0, 1, or 2)x
- the desired X coordinatey
- the desired Y coordinatez
- the desired Z coordinate
-
set1
Alters the location of the first vertex and deletes the stored centroid and normal.- Parameters:
v
- the desired location (not null, unaffected)
-
set2
Alters the location of the 2nd vertex and deletes the stored centroid and normal.- Parameters:
v
- the desired location (not null, unaffected)
-
set3
Alters the location of the 3rd vertex and deletes the stored centroid and normal.- Parameters:
v
- the desired location (not null, unaffected)
-
set
Alters the locations of all 3 vertices and deletes the stored centroid and normal.- Specified by:
set
in classAbstractTriangle
- Parameters:
v1
- the desired location of the first vertex (not null, unaffected)v2
- the desired location of the 2nd vertex (not null, unaffected)v3
- the desired location of the 3rd vertex (not null, unaffected)
-
calculateCenter
public void calculateCenter()Recalculates the stored centroid based on the current vertex locations. -
calculateNormal
public void calculateNormal()Recalculates the stored normal based on the current vertex locations. -
getCenter
Accesses the stored centroid (the average of the 3 vertex locations) calculating it if it is null.- Returns:
- the coordinates of the center (an internal vector subject to re-use)
-
setCenter
Alters the stored centroid without affecting the stored normal or any vertex locations.- Parameters:
center
- the desired value (alias created if not null)
-
getNormal
Accesses the stored normal, updating it if it is null.- Returns:
- unit normal vector (an internal vector subject to re-use)
-
setNormal
Alters the stored normal without affecting the stored centroid or any vertex locations.- Parameters:
normal
- the desired value (alias created if not null)
-
getProjection
public float getProjection()Returns the projection of the vertices relative to the line origin.- Returns:
- the stored projection value
-
setProjection
public void setProjection(float projection) Alters the projection of the vertices relative to the line origin.- Parameters:
projection
- the desired projection value
-
getIndex
public int getIndex()Returns the index of this triangle, used to identify it in an OBBTree.- Returns:
- the stored index
-
setIndex
public void setIndex(int index) Alters the index of this triangle, used to identify it in an OBBTree.- Parameters:
index
- the desired index
-
computeTriangleNormal
-
write
Serializes this triangle to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Parameters:
e
- (not null)- Throws:
IOException
- from the exporter
-
read
De-serializes this triangle from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
clone
Creates a copy of this triangle.
-