mr3d.lang
Class Triangle3D

java.lang.Object
  extended bymr3d.lang.Triangle3D
All Implemented Interfaces:
Debugable, Transformable

public class Triangle3D
extends java.lang.Object
implements Debugable, Transformable

The class Triangle3D is able to represent a triangle. It is a composite object consisting of three edges (Edge3D)

Example

 // create points forming a triangle
 
 Point3D nullPoint = new Point3D();
 Point3D myEndPoint1 = new Point3D(10,0,0);
 Point3D myEndPoint2 = new Point3D(0,10,0);
 	
 // create edges of the triangle
 	
 Edge3D myEdge1 = new Edge3D(nullPoint, myEndPoint1);
 Edge3D myEdge2 = new Edge3D(myEndPoint1, myEndPoint2);
 Edge3D myEdge3 = new Edge3D(myEndPoint2, nullPoint);
 
 // define color code
 
 int red = 255;
 int green = 100;
 int blue = 20;
 int myColorCode = mr3d.Graph2D.getColorCode(red, green, blue);
 
 // create the triangle object	
 Triangle3D myTraingle = new Triangle3D(myEdge1, myEdge2, myEdge3, myColorCode);
 myTraingle.planeNormal.toConsole();       // (0,0,-100)
 

Since:
MR3Dv1.0
Version:
10-2004
Author:
Manuel Ruelke
See Also:
Vector3D, Edge3D

Field Summary
 int colorCode
          Color code of the triangle.
 Edge3D edge1
          Edge of triangle.
 Edge3D edge2
          Edge of triangle.
 Edge3D edge3
          Edge of triangle.
 Vector3D planeNormalCCS
          Vector object that is used to store the plane normal.
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
Triangle3D(Edge3D newEdge1, Edge3D newEdge2, Edge3D newEdge3, int color)
          Constructs a triangle object from three edge objects.
 
Method Summary
 Vector3D calculateNormalCCS()
          Calculates the plane normal of the triangle using the camera coordinates The start and end points of edge1 and edge2 are used to create two vectors.
 void reset()
          Resets the points to their initial value.
 void toConsole()
          Prints the contents of the object to the Java console.
 void toConsole(java.lang.String msgString)
          Prints the contents of the object to the Java console together with an information string.
 void transform(Matrix transMat)
          Delegate the transformation matrix to the 3D points in the edges.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colorCode

public int colorCode
Color code of the triangle. The color code defines the color the traingle will be drawn on the screen. The color code is a single number, which can be calculated through he following formula:

colorCode = blueValue + 256*greenValue + 65536*redValue

The color values for blue, green and red used to calculated the the color code can be values between 0 and 255. The color code may be a number between 0 (black) and 16.777.215 (white).


edge1

public Edge3D edge1
Edge of triangle. The three edge objects create one triangle. The edges and the 3D points within the edges have to be in a counter- clockwise order. By this convention the MR3D system can determine the visibility of single triangles in terms of if they are facing the virtual camera or not.


edge2

public Edge3D edge2
Edge of triangle. The three edge objects create one triangle. The edges and the 3D points within the edges have to be in a counter- clockwise order. By this convention the MR3D system can determine the visibility of single triangles in terms of if they are facing the virtual camera or not.


edge3

public Edge3D edge3
Edge of triangle. The three edge objects create one triangle. The edges and the 3D points within the edges have to be in a counter- clockwise order. By this convention the MR3D system can determine the visibility of single triangles in terms of if they are facing the virtual camera or not.


planeNormalCCS

public Vector3D planeNormalCCS
Vector object that is used to store the plane normal. Note, that this plane normal is the normal in the camera coordinate system.

See Also:
Vector3D
Constructor Detail

Triangle3D

public Triangle3D(Edge3D newEdge1,
                  Edge3D newEdge2,
                  Edge3D newEdge3,
                  int color)
Constructs a triangle object from three edge objects.

Parameters:
newEdge1 - edge object to define the border of the triangle
newEdge2 - edge object to define the border of the triangle
newEdge3 - edge object to define the border of the triangle
color - color code of the triangle
Method Detail

calculateNormalCCS

public Vector3D calculateNormalCCS()
Calculates the plane normal of the triangle using the camera coordinates The start and end points of edge1 and edge2 are used to create two vectors. The cross product of those two vectors is a vector that is the plane normal.

Returns:
plane normal of the traingle in camera coordinates

reset

public void reset()
Resets the points to their initial value.

See Also:
Point3D.reset()

toConsole

public void toConsole()
Description copied from interface: Debugable
Prints the contents of the object to the Java console. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

toConsole

public void toConsole(java.lang.String msgString)
Description copied from interface: Debugable
Prints the contents of the object to the Java console together with an information string. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

transform

public void transform(Matrix transMat)
Delegate the transformation matrix to the 3D points in the edges.

Specified by:
transform in interface Transformable
Parameters:
transMat - transformation or translation matrix
See Also:
MatrixFactory.createTransMatrix(int, int, int)