espresso3d.engine.lowlevel.geometry
Class E3DTriangle

java.lang.Object
  extended byespresso3d.engine.base.E3DEngineItem
      extended byespresso3d.engine.renderer.base.E3DRenderable
          extended byespresso3d.engine.renderer.base.E3DTexturedRenderable
              extended byespresso3d.engine.lowlevel.geometry.E3DTriangle

public class E3DTriangle
extends E3DTexturedRenderable

Author:
espresso3d Triangle class used in the engine. Be sure to ONLY modify vertex position information through the triangle object itself -- IE: do NOT get the vertex and modify the vertex by hand. It will cause normals to NOT be recalculated if you do so and will cause lots of problems.

Constructor Summary
E3DTriangle(E3DEngine engine)
           
E3DTriangle(E3DEngine engine, E3DVector3F vertexPosA, E3DVector3F vertexPosB, E3DVector3F vertexPosC)
          A triangle that doesn't care about texture coords/textures.
E3DTriangle(E3DEngine engine, E3DVector3F vertexPosA, E3DVector3F vertexPosB, E3DVector3F vertexPosC, E3DVector2F texCoordA, E3DVector2F texCoordB, E3DVector2F texCoordC, java.lang.String textureName)
           
E3DTriangle(E3DEngine engine, E3DVector3F vertexPosA, E3DVector3F vertexPosB, E3DVector3F vertexPosC, E3DVector2F texCoordA, E3DVector2F texCoordB, E3DVector2F texCoordC, java.lang.String textureName, E3DVector2F detail0TexCoordA, E3DVector2F detail0TexCoordB, E3DVector2F detail0TexCoordC, java.lang.String detail0TextureName)
           
E3DTriangle(E3DEngine engine, E3DVector3F vertexPosA, E3DVector3F vertexPosB, E3DVector3F vertexPosC, E3DVector2F texCoordA, E3DVector2F texCoordB, E3DVector2F texCoordC, java.lang.String textureName, E3DVector2F detail0TexCoordA, E3DVector2F detail0TexCoordB, E3DVector2F detail0TexCoordC, java.lang.String detail0TextureName, E3DVector2F detail1TexCoordA, E3DVector2F detail1TexCoordB, E3DVector2F detail1TexCoordC, java.lang.String detail1TextureName)
           
E3DTriangle(E3DTriangle toCopy)
           
 
Method Summary
 void appendTexCoordBuffer(java.nio.FloatBuffer texCoordBuffer)
           
 void appendTexCoordDetail0Buffer(java.nio.FloatBuffer texCoordDetail0Buffer)
           
 void appendTexCoordDetail1Buffer(java.nio.FloatBuffer texCoordDetail1Buffer)
           
 void appendVertexBuffer(java.nio.FloatBuffer vertexBuffer)
           
 void appendVertexColorBuffer(java.nio.FloatBuffer floatBuffer)
           
 E3DVector3F checkSegmentCollision(E3DVector3F startPos, E3DVector3F endPos)
          Checks for full fledged collision between the line segment formed between startPos and endPos and the triangle and returns the intersection point (or null if no collision occurs)
static E3DVector3F checkTriangleCollision(E3DTriangle colliderTriangle, E3DVector3F startPos, E3DVector3F endPos, E3DTriangle collideeTriangle)
          Checks for a collision between this and another triangle by checking to see if any of vertices when moved along a line segment of length endPos - startPos collide with the collideeTriangle.
 boolean doesSegmentCrossPlane(E3DVector3F startPos, E3DVector3F endPos)
           
 double getAlpha()
           
 E3DVector3F getCentroid()
           
 double getDistanceToPoint(E3DVector3F point)
           
 E3DVector3F getNormal()
           
 E3DVector4F getPlaneEquationCoords()
           
 E3DVector3F getPlaneIntersectionPoint(E3DVector3F startPos, E3DVector3F endPos)
          Gets the intersection point of the line segment formed between startPos and endPos and the triangle if it intersects
 E3DVector2F[] getTextureCoord()
           
 E3DVector2F getTextureCoordA()
          Get the texture coordinate of the first vertex
 E3DVector2F getTextureCoordB()
          Get the texture coordinate of the second vertex
 E3DVector2F getTextureCoordC()
          Get the texture coordinate of the third vertex
 E3DVector2F[] getTextureCoordDetail0()
           
 E3DVector2F getTextureCoordDetail0A()
          Get the texture coordinate of the first vertex
 E3DVector2F getTextureCoordDetail0B()
          Get the texture coordinate of the second vertex
 E3DVector2F getTextureCoordDetail0C()
          Get the texture coordinate of the third vertex
 E3DVector2F[] getTextureCoordDetail1()
           
 E3DVector2F getTextureCoordDetail1A()
          Get the texture coordinate of the first vertex
 E3DVector2F getTextureCoordDetail1B()
          Get the texture coordinate of the second vertex
 E3DVector2F getTextureCoordDetail1C()
          Get the texture coordinate of the third vertex
 E3DTexturedVertex getVertex(int index)
          Be sure to NOT MODIFY VERTEX INFORMATION DIRECTLY! Use the triangle helpers!
 E3DVector3F[] getVertexColor()
          Get an array of colors for each of the triangles vertices
 E3DVector3F getVertexColorA()
          Get the color of the first vertex
 E3DVector3F getVertexColorB()
          Get the color of the second vertex
 E3DVector3F getVertexColorC()
          Get the color of the third vertex
 E3DVector3F getVertexPos(int index)
           
 E3DVector3F getVertexPosA()
          Get the position of the 1st vertex of the triangle
 E3DVector3F getVertexPosB()
          Get the position of the 2nd vertex of the triangle
 E3DVector3F getVertexPosC()
          Get the position of the 3rd vertex of the triangle
 boolean isPointInTriangle(E3DVector3F point)
          This checks if a point is in a triangle by seeing if the interior angles add up to 360Deg.
 void normaliseVertexColors()
          Ensures all vertex colors are <= 1.0
 void render()
          To render outside of the normal rendering loop, this can be added to the external renderable list of the engine's because it implements render.
 void resetVertexColor(double color)
          Resets all the vertex colors to all be color.
 void rotate(double angle, E3DVector3F upVec, E3DVector3F translatedAmt)
          Rotate the triangle around aroundVec.
 void scale(double scaleAmt)
           
 void setAlpha(double alpha)
           
 void setNormal(E3DVector3F normal)
           
 void setPlaneEquationCoords(E3DVector4F planeEq)
           
 void setTextureCoord(E3DVector2F[] textureCoord)
           
 void setTextureCoord(E3DVector2F textureCoordA, E3DVector2F textureCoordB, E3DVector2F textureCoordC)
          Set the texture coords
 void setTextureCoordA(E3DVector2F textureCoord)
          Set the texture coordinate of the first vertex
 void setTextureCoordB(E3DVector2F textureCoord)
          Set the texture coordinate of the second vertex
 void setTextureCoordC(E3DVector2F textureCoord)
          Set the texture coordinate of the third vertex
 void setTextureCoordDetail0(E3DVector2F[] textureCoord)
           
 void setTextureCoordDetail0(E3DVector2F textureCoordA, E3DVector2F textureCoordB, E3DVector2F textureCoordC)
          Set the texture coords
 void setTextureCoordDetail0A(E3DVector2F textureCoord)
          Set the texture coordinate of the first vertex
 void setTextureCoordDetail0B(E3DVector2F textureCoord)
          Set the texture coordinate of the second vertex
 void setTextureCoordDetail0C(E3DVector2F textureCoord)
          Set the texture coordinate of the third vertex
 void setTextureCoordDetail1(E3DVector2F[] textureCoord)
           
 void setTextureCoordDetail1(E3DVector2F textureCoordA, E3DVector2F textureCoordB, E3DVector2F textureCoordC)
          Set the texture coords
 void setTextureCoordDetail1A(E3DVector2F textureCoord)
          Set the texture coordinate of the first vertex
 void setTextureCoordDetail1B(E3DVector2F textureCoord)
          Set the texture coordinate of the second vertex
 void setTextureCoordDetail1C(E3DVector2F textureCoord)
          Set the texture coordinate of the third vertex
 void setVertexA(E3DTexturedVertex vertex)
          Set the first vertex of the triangle
 void setVertexB(E3DTexturedVertex vertex)
          Set the second vertex of the triangle
 void setVertexC(E3DTexturedVertex vertex)
          Set the third vertex of the triangle
 void setVertexColor(E3DVector3F[] vertexColor)
          Set the colors of each vertex of a triangle
 void setVertexColor(E3DVector3F vertexColorA, E3DVector3F vertexColorB, E3DVector3F vertexColorC)
          Set the colors of each vertex of the triangle
 void setVertexColorA(E3DVector3F vertexColor)
          Set the color of the first vertex
 void setVertexColorB(E3DVector3F vertexColor)
          Set the color of the second vertex
 void setVertexColorC(E3DVector3F vertexColor)
          Set the color of the third vertex
 void setVertexPos(E3DVector3F vertexPosA, E3DVector3F vertexPosB, E3DVector3F vertexPosC)
          Set the vertices
 void setVertexPosA(E3DVector3F vertexPos)
          Set the position of the 1st vertex of the triangle
 void setVertexPosB(E3DVector3F vertexPos)
          Set the position of the 2nd vertex of the triangle
 void setVertexPosC(E3DVector3F vertexPos)
          Set the position of the 2nd vertex of the triangle
 void setVertices(E3DTexturedVertex[] vertices)
          Set the triangle's vertices
 java.lang.String toString()
           
 void translate(E3DVector3F translationAmt)
          Translate the triangle vertices
 
Methods inherited from class espresso3d.engine.renderer.base.E3DTexturedRenderable
getKey, getTexture, getTextureDetail0, getTextureDetail1, isTextureAvailable, isTextureDetail0Available, isTextureDetail1Available, setTexture, setTextureDetail0, setTextureDetail1
 
Methods inherited from class espresso3d.engine.renderer.base.E3DRenderable
getBlendMode, getRenderMode, initCorrectGeometryRenderer, isKeyChanged, setBlendMode, setKeyChanged, setRenderMode
 
Methods inherited from class espresso3d.engine.base.E3DEngineItem
getEngine, setEngine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

E3DTriangle

public E3DTriangle(E3DEngine engine)

E3DTriangle

public E3DTriangle(E3DTriangle toCopy)

E3DTriangle

public E3DTriangle(E3DEngine engine,
                   E3DVector3F vertexPosA,
                   E3DVector3F vertexPosB,
                   E3DVector3F vertexPosC)
A triangle that doesn't care about texture coords/textures. Be sure to never send this to the rendering pipeline!! This is for vertexFunctions ONLY, NOT for rendering!

Parameters:
engine -

E3DTriangle

public E3DTriangle(E3DEngine engine,
                   E3DVector3F vertexPosA,
                   E3DVector3F vertexPosB,
                   E3DVector3F vertexPosC,
                   E3DVector2F texCoordA,
                   E3DVector2F texCoordB,
                   E3DVector2F texCoordC,
                   java.lang.String textureName)

E3DTriangle

public E3DTriangle(E3DEngine engine,
                   E3DVector3F vertexPosA,
                   E3DVector3F vertexPosB,
                   E3DVector3F vertexPosC,
                   E3DVector2F texCoordA,
                   E3DVector2F texCoordB,
                   E3DVector2F texCoordC,
                   java.lang.String textureName,
                   E3DVector2F detail0TexCoordA,
                   E3DVector2F detail0TexCoordB,
                   E3DVector2F detail0TexCoordC,
                   java.lang.String detail0TextureName)

E3DTriangle

public E3DTriangle(E3DEngine engine,
                   E3DVector3F vertexPosA,
                   E3DVector3F vertexPosB,
                   E3DVector3F vertexPosC,
                   E3DVector2F texCoordA,
                   E3DVector2F texCoordB,
                   E3DVector2F texCoordC,
                   java.lang.String textureName,
                   E3DVector2F detail0TexCoordA,
                   E3DVector2F detail0TexCoordB,
                   E3DVector2F detail0TexCoordC,
                   java.lang.String detail0TextureName,
                   E3DVector2F detail1TexCoordA,
                   E3DVector2F detail1TexCoordB,
                   E3DVector2F detail1TexCoordC,
                   java.lang.String detail1TextureName)
Method Detail

setVertexA

public void setVertexA(E3DTexturedVertex vertex)
Set the first vertex of the triangle

Parameters:
vertex -

setVertexB

public void setVertexB(E3DTexturedVertex vertex)
Set the second vertex of the triangle

Parameters:
vertex -

setVertexC

public void setVertexC(E3DTexturedVertex vertex)
Set the third vertex of the triangle

Parameters:
vertex -

getVertexPos

public E3DVector3F getVertexPos(int index)

getVertex

public E3DTexturedVertex getVertex(int index)
Be sure to NOT MODIFY VERTEX INFORMATION DIRECTLY! Use the triangle helpers!

Parameters:
index -
Returns:

getVertexPosA

public E3DVector3F getVertexPosA()
Get the position of the 1st vertex of the triangle

Returns:

setVertexPosA

public void setVertexPosA(E3DVector3F vertexPos)
Set the position of the 1st vertex of the triangle

Parameters:
vertexPos -

getVertexPosB

public E3DVector3F getVertexPosB()
Get the position of the 2nd vertex of the triangle

Returns:

setVertexPosB

public void setVertexPosB(E3DVector3F vertexPos)
Set the position of the 2nd vertex of the triangle

Parameters:
vertexPos -

getVertexPosC

public E3DVector3F getVertexPosC()
Get the position of the 3rd vertex of the triangle

Returns:

setVertexPosC

public void setVertexPosC(E3DVector3F vertexPos)
Set the position of the 2nd vertex of the triangle

Parameters:
vertexPos -

getVertexColorA

public E3DVector3F getVertexColorA()
Get the color of the first vertex

Returns:
E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

setVertexColorA

public void setVertexColorA(E3DVector3F vertexColor)
Set the color of the first vertex

Parameters:
vertexColor - E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

getVertexColorB

public E3DVector3F getVertexColorB()
Get the color of the second vertex

Returns:
E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

setVertexColorB

public void setVertexColorB(E3DVector3F vertexColor)
Set the color of the second vertex

Parameters:
vertexColor - E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

getVertexColorC

public E3DVector3F getVertexColorC()
Get the color of the third vertex

Returns:
E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

setVertexColorC

public void setVertexColorC(E3DVector3F vertexColor)
Set the color of the third vertex

Parameters:
vertexColor - E3DVector3F specifying RGB components right 0.0 <= R.G.B. <= 1.0

getTextureCoordDetail1A

public E3DVector2F getTextureCoordDetail1A()
Get the texture coordinate of the first vertex

Returns:

setTextureCoordDetail1A

public void setTextureCoordDetail1A(E3DVector2F textureCoord)
Set the texture coordinate of the first vertex

Parameters:
textureCoord -

getTextureCoordDetail1B

public E3DVector2F getTextureCoordDetail1B()
Get the texture coordinate of the second vertex

Returns:

setTextureCoordDetail1B

public void setTextureCoordDetail1B(E3DVector2F textureCoord)
Set the texture coordinate of the second vertex

Parameters:
textureCoord -

getTextureCoordDetail1C

public E3DVector2F getTextureCoordDetail1C()
Get the texture coordinate of the third vertex

Returns:

setTextureCoordDetail1C

public void setTextureCoordDetail1C(E3DVector2F textureCoord)
Set the texture coordinate of the third vertex

Parameters:
textureCoord -

getTextureCoordDetail1

public E3DVector2F[] getTextureCoordDetail1()
Returns:
Returns an array of textureCoords for each vertex of the triangle.

setTextureCoordDetail1

public void setTextureCoordDetail1(E3DVector2F[] textureCoord)
Parameters:
textureCoord - The textureCoords to set for each vertex of the triangle. This must be length 3

setTextureCoordDetail1

public void setTextureCoordDetail1(E3DVector2F textureCoordA,
                                   E3DVector2F textureCoordB,
                                   E3DVector2F textureCoordC)
Set the texture coords

Parameters:
textureCoordA -
textureCoordB -
textureCoordC -

getTextureCoordDetail0A

public E3DVector2F getTextureCoordDetail0A()
Get the texture coordinate of the first vertex

Returns:

setTextureCoordDetail0A

public void setTextureCoordDetail0A(E3DVector2F textureCoord)
Set the texture coordinate of the first vertex

Parameters:
textureCoord -

getTextureCoordDetail0B

public E3DVector2F getTextureCoordDetail0B()
Get the texture coordinate of the second vertex

Returns:

setTextureCoordDetail0B

public void setTextureCoordDetail0B(E3DVector2F textureCoord)
Set the texture coordinate of the second vertex

Parameters:
textureCoord -

getTextureCoordDetail0C

public E3DVector2F getTextureCoordDetail0C()
Get the texture coordinate of the third vertex

Returns:

setTextureCoordDetail0C

public void setTextureCoordDetail0C(E3DVector2F textureCoord)
Set the texture coordinate of the third vertex

Parameters:
textureCoord -

getTextureCoordDetail0

public E3DVector2F[] getTextureCoordDetail0()
Returns:
Returns an array of textureCoords for each vertex of the triangle.

setTextureCoordDetail0

public void setTextureCoordDetail0(E3DVector2F[] textureCoord)
Parameters:
textureCoord - The textureCoords to set for each vertex of the triangle. This must be length 3

setTextureCoordDetail0

public void setTextureCoordDetail0(E3DVector2F textureCoordA,
                                   E3DVector2F textureCoordB,
                                   E3DVector2F textureCoordC)
Set the texture coords

Parameters:
textureCoordA -
textureCoordB -
textureCoordC -

getTextureCoordA

public E3DVector2F getTextureCoordA()
Get the texture coordinate of the first vertex

Returns:

setTextureCoordA

public void setTextureCoordA(E3DVector2F textureCoord)
Set the texture coordinate of the first vertex

Parameters:
textureCoord -

getTextureCoordB

public E3DVector2F getTextureCoordB()
Get the texture coordinate of the second vertex

Returns:

setTextureCoordB

public void setTextureCoordB(E3DVector2F textureCoord)
Set the texture coordinate of the second vertex

Parameters:
textureCoord -

getTextureCoordC

public E3DVector2F getTextureCoordC()
Get the texture coordinate of the third vertex

Returns:

setTextureCoordC

public void setTextureCoordC(E3DVector2F textureCoord)
Set the texture coordinate of the third vertex

Parameters:
textureCoord -

getTextureCoord

public E3DVector2F[] getTextureCoord()
Returns:
Returns an array of textureCoords for each vertex of the triangle.

setTextureCoord

public void setTextureCoord(E3DVector2F[] textureCoord)
Parameters:
textureCoord - The textureCoords to set for each vertex of the triangle. This must be length 3

setTextureCoord

public void setTextureCoord(E3DVector2F textureCoordA,
                            E3DVector2F textureCoordB,
                            E3DVector2F textureCoordC)
Set the texture coords

Parameters:
textureCoordA -
textureCoordB -
textureCoordC -

setVertices

public void setVertices(E3DTexturedVertex[] vertices)
Set the triangle's vertices


setVertexPos

public void setVertexPos(E3DVector3F vertexPosA,
                         E3DVector3F vertexPosB,
                         E3DVector3F vertexPosC)
Set the vertices


getVertexColor

public E3DVector3F[] getVertexColor()
Get an array of colors for each of the triangles vertices

Returns:
Array of E3DVector3F's. X = R, Y = G, Z = B

setVertexColor

public void setVertexColor(E3DVector3F[] vertexColor)
Set the colors of each vertex of a triangle

Parameters:
vertexColor - Array of E3DVector3F's. Must be length 3.

setVertexColor

public void setVertexColor(E3DVector3F vertexColorA,
                           E3DVector3F vertexColorB,
                           E3DVector3F vertexColorC)
Set the colors of each vertex of the triangle

Parameters:
vertexColorA -
vertexColorB -
vertexColorC -

resetVertexColor

public void resetVertexColor(double color)
Resets all the vertex colors to all be color. Value between 0 and 1 should be used


normaliseVertexColors

public void normaliseVertexColors()
Ensures all vertex colors are <= 1.0


appendVertexBuffer

public void appendVertexBuffer(java.nio.FloatBuffer vertexBuffer)

appendVertexColorBuffer

public void appendVertexColorBuffer(java.nio.FloatBuffer floatBuffer)

appendTexCoordBuffer

public void appendTexCoordBuffer(java.nio.FloatBuffer texCoordBuffer)

appendTexCoordDetail0Buffer

public void appendTexCoordDetail0Buffer(java.nio.FloatBuffer texCoordDetail0Buffer)

appendTexCoordDetail1Buffer

public void appendTexCoordDetail1Buffer(java.nio.FloatBuffer texCoordDetail1Buffer)

getCentroid

public E3DVector3F getCentroid()

isPointInTriangle

public boolean isPointInTriangle(E3DVector3F point)
This checks if a point is in a triangle by seeing if the interior angles add up to 360Deg. This is slightly slower than isPointInTriangle, but left for testing sake.

Parameters:
point -
Returns:

render

public void render()
To render outside of the normal rendering loop, this can be added to the external renderable list of the engine's because it implements render.

Specified by:
render in class E3DRenderable

setNormal

public void setNormal(E3DVector3F normal)
Parameters:
normal - The normal to set.

getNormal

public E3DVector3F getNormal()
Returns:
Returns the normal.

getPlaneEquationCoords

public E3DVector4F getPlaneEquationCoords()

setPlaneEquationCoords

public void setPlaneEquationCoords(E3DVector4F planeEq)

translate

public void translate(E3DVector3F translationAmt)
Translate the triangle vertices


scale

public void scale(double scaleAmt)

toString

public java.lang.String toString()

rotate

public void rotate(double angle,
                   E3DVector3F upVec,
                   E3DVector3F translatedAmt)
Rotate the triangle around aroundVec. Translated amt is how far the triangle has been translated from the origin (it needsd this so it can be centered around the up vec correctly and then rotate and moved back)

Parameters:
angle -
upVec -
translatedAmt -

getAlpha

public double getAlpha()

setAlpha

public void setAlpha(double alpha)

getDistanceToPoint

public double getDistanceToPoint(E3DVector3F point)

doesSegmentCrossPlane

public boolean doesSegmentCrossPlane(E3DVector3F startPos,
                                     E3DVector3F endPos)

getPlaneIntersectionPoint

public E3DVector3F getPlaneIntersectionPoint(E3DVector3F startPos,
                                             E3DVector3F endPos)
Gets the intersection point of the line segment formed between startPos and endPos and the triangle if it intersects

Parameters:
startPos -
endPos -
Returns:
returns intersection point

checkSegmentCollision

public E3DVector3F checkSegmentCollision(E3DVector3F startPos,
                                         E3DVector3F endPos)
Checks for full fledged collision between the line segment formed between startPos and endPos and the triangle and returns the intersection point (or null if no collision occurs)

Returns:
Returns the intersection point vector if there is a collision between the line segment (startPos, endPos) and triangle. Otherwise, returns null;

checkTriangleCollision

public static E3DVector3F checkTriangleCollision(E3DTriangle colliderTriangle,
                                                 E3DVector3F startPos,
                                                 E3DVector3F endPos,
                                                 E3DTriangle collideeTriangle)
Checks for a collision between this and another triangle by checking to see if any of vertices when moved along a line segment of length endPos - startPos collide with the collideeTriangle. TODO: This should also check the edges of the colliderTriangle...

Parameters:
colliderTriangle -
startPos -
endPos -
collideeTriangle -
Returns: