nl.kun.Engine3D
Class TPolyObject3D

java.lang.Object
  |
  +--nl.kun.Engine3D.TVector3D
        |
        +--nl.kun.Engine3D.TCoordSys3D
              |
              +--nl.kun.Engine3D.TEntity3D
                    |
                    +--nl.kun.Engine3D.TEntityList3D
                          |
                          +--nl.kun.Engine3D.TPolyObject3D
Direct Known Subclasses:
LWImportedObj

public class TPolyObject3D
extends TEntityList3D

An object that is specially optimized to contain large amounts of polygons. This object uses arrays of fixed size. Tell the object (using setNoPolygons and setNoVertices) exactly how many vertices and polygons are inside the object. Do this before you add vertices and polygons, because the arrays are initialised (and thus emptied) when the array size is changed!! Then add all the vertices and polygons to the object using insertVertex and insertPolygon (or insertQuad, insertTriangle) as follows:

Vertices get a fixed number (i), use insertVertex(i, x,y,z) to insert a vertex at location i in the array. Polygons connect succeeding vertices with lines and are automatically closed. To create a polygon, make an array of succeeding vertex index numbers (for example int poly[] = {4, 5, 2, 1};) and use this as an input for insertPolygon. For creating triangles or quads use insertTriangle or insertQuad.

NOTE: setNoPolygons and setNoVertices create new arrays with lengths determined by the input. Make sure you actually insert enough polygons and vertices to fill up the entire array starting with index 0 and ending at the length you chose.

NOTE 2: polygons have only one side! For speed reasons, the polygons are only drawn when they are pointing at (and not away from) the camera. The visible side of the polygon is determined by the right hand rule.


Field Summary
protected  java.awt.Color[] ColorArr
          Color shading array
 
Fields inherited from class nl.kun.Engine3D.TEntityList3D
depth, index, MaxBuf, MAXOBJECTS, ObjectList, size
 
Fields inherited from class nl.kun.Engine3D.TEntity3D
color, GlobalCords, ParentGlobalCords, Vissible
 
Fields inherited from class nl.kun.Engine3D.TCoordSys3D
Xaxis, Yaxis, Zaxis
 
Fields inherited from class nl.kun.Engine3D.TVector3D
DBSCIENTIFIC, DBSTANDARD, x, y, z
 
Constructor Summary
TPolyObject3D()
          Empty constructor.
TPolyObject3D(double _x, double _y, double _z, java.awt.Color _color)
          Simpler constructor.
TPolyObject3D(double _x, double _y, double _z, double _xax, double _xay, double _xaz, double _yax, double _yay, double _yaz, double _zax, double _zay, double _zaz, java.awt.Color _color)
          Constructor.
 
Method Summary
 double Depth(TCamera3D _cam)
          This routine prerenders the objects and calculates the distances from the object to the camera (depth).
 void Draw(TCamera3D _cam, Viewport _Viewport)
          Draws the vissible parts of this object onto the viewport, as if it where projecting itself on a camera.
 void insertPolygon(int i, int[] _Polygons, int _noOfVertices)
          Inserts a polygon at a specified array index number i in the polygon array.
 void insertQuad(int i, int _v1, int _v2, int _v3, int _v4)
          Insert a quad (polygon with 4 vertices) at a specified array index number i in the polygon array.
 void insertTriangle(int i, int _v1, int _v2, int _v3)
          Insert a triangle (polygon with 3 vertices) at a specified array index number i in the polygon array.
 void insertVertex(int i, double _x, double _y, double _z)
          Inserts a vertex at a specified array index number i in the vertex array.
 void ScaleVertices(double _x, double _y, double _z)
          Scales the vertices of this object in the x, y and z direction.
 void setNoPolygons(int _noPolygons)
          This sets the number of polygons in the polygon array.
 void setNoVertices(int _noVertices)
          This sets the number of vertices in the vertex array.
 
Methods inherited from class nl.kun.Engine3D.TEntityList3D
Append, Clear, InheritGlobalCords, Insert, Remove, Remove, Rotate, Sort, Translate, Translate
 
Methods inherited from class nl.kun.Engine3D.TEntity3D
Vector3D, Vector3D
 
Methods inherited from class nl.kun.Engine3D.TCoordSys3D
CoordSys3D, CoordSys3D, CoordSys3D, Global2Local, Global2Local, Global2Local, Local2Global, Local2Global, Local2Global, toString
 
Methods inherited from class nl.kun.Engine3D.TVector3D
Angle, Double2String, Double2String, Modulus, Modulus, Negate, Negate, Normalize, Normalize, NulVec, StdXaxis, StdYaxis, StdZaxis, String2Double, VAdd, VCrossProduct, VCrossProduct, VDotProduct, Vector3D, VPerpendicular, VPerpendicular, VScalarProduct, VScalarProduct, VScalarProduct, VSubstract, VSubstract
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ColorArr

protected java.awt.Color[] ColorArr
Color shading array
Constructor Detail

TPolyObject3D

public TPolyObject3D(double _x,
                     double _y,
                     double _z,
                     double _xax,
                     double _xay,
                     double _xaz,
                     double _yax,
                     double _yay,
                     double _yaz,
                     double _zax,
                     double _zay,
                     double _zaz,
                     java.awt.Color _color)
Constructor.
Parameters:
_x - the x-value of the origin vector
_y - the y-value of the origin vector
_z - the z-value of the origin vector
_xax - the x-value of the x-axis vector
_xay - the y-value of the x-axis vector
_xaz - the z-value of the x-axis vector
_yax - the x-value of the y-axis vector
_yay - the y-value of the y-axis vector
_yaz - the z-value of the y-axis vector
_zax - the x-value of the z-axis vector
_zay - the y-value of the z-axis vector
_zaz - the z-value of the z-axis vector
_color - the color of this object.

TPolyObject3D

public TPolyObject3D(double _x,
                     double _y,
                     double _z,
                     java.awt.Color _color)
Simpler constructor. Only needs a position and uses (x,y,z,1,0,0,0,1,0,0,0,1) as it's coordinate system.
Parameters:
_x - the x-value of the origin vector
_y - the y-value of the origin vector
_z - the z-value of the origin vector
_color - the color of this object.

TPolyObject3D

public TPolyObject3D()
Empty constructor. Creates a TPolyObject3D with coordinate system ( (0,0,0); (1,0,0); (0,1,0); (0,0,1) )
Method Detail

setNoPolygons

public void setNoPolygons(int _noPolygons)
This sets the number of polygons in the polygon array. You should use this routine before you add any polygons, because the entire array is emptied after calling this routine! You should also fill the entire array using insertPolygon, insertQuad or insertTriangle before any manipulation of the object (including drawing and depth sorting) is possible.
Parameters:
_noPolygons - The number of polygons that will be added to this object

setNoVertices

public void setNoVertices(int _noVertices)
This sets the number of vertices in the vertex array. You should use this routine before you add any vertices, because the entire array is emptied after calling this routine! You should also fill the entire array using insertVertex before any manipulation of the object (including drawing and depth sorting) is possible.
Parameters:
_noPolygons - The number of Vertices that will be added to this object

insertVertex

public void insertVertex(int i,
                         double _x,
                         double _y,
                         double _z)
Inserts a vertex at a specified array index number i in the vertex array.
Parameters:
i - The index number in the array for this vertex.
_x - The x component of the vertex.
_y - The y component of the vertex.
_z - The z component of the vertex.

insertPolygon

public void insertPolygon(int i,
                          int[] _Polygons,
                          int _noOfVertices)
Inserts a polygon at a specified array index number i in the polygon array.
Parameters:
i - the index number of this polygon in the polygon array.
_Polygons - an array of vertex index numbers, in succeeding order and with the visible side determined by the right hand rule.
_noOfPoints - the number of vertices in _Polygons.

insertQuad

public void insertQuad(int i,
                       int _v1,
                       int _v2,
                       int _v3,
                       int _v4)
Insert a quad (polygon with 4 vertices) at a specified array index number i in the polygon array.
Parameters:
i - the index number of this polygon in the polygon array.
_v1 - the first vertex of the quad.
_v2 - the second vertex of the quad.
_v3 - the third vertex of the quad.
_v4 - the fourth vertex of the quad.

insertTriangle

public void insertTriangle(int i,
                           int _v1,
                           int _v2,
                           int _v3)
Insert a triangle (polygon with 3 vertices) at a specified array index number i in the polygon array.
Parameters:
i - the index number of this polygon in the polygon array.
_v1 - the first vertex of the triangle.
_v2 - the second vertex of the triangle.
_v3 - the third vertex of the triangle.

Depth

public double Depth(TCamera3D _cam)
Description copied from class: TEntity3D
This routine prerenders the objects and calculates the distances from the object to the camera (depth). If more than one 3D object is inside this object, it returns the average depth. This depth can be used by a a parent TEntityList3D object to sort all TEntity3D's according to depth.
Overrides:
Depth in class TEntityList3D
Tags copied from class: TEntity3D
Parameters:
_cam - The camera.

Draw

public void Draw(TCamera3D _cam,
                 Viewport _Viewport)
Description copied from class: TEntity3D
Draws the vissible parts of this object onto the viewport, as if it where projecting itself on a camera.
Overrides:
Draw in class TEntityList3D
Tags copied from class: TEntity3D
Parameters:
_cam - The camera.
_Viewport - Viewport object. This viewport object handles clipping and transformation of real world coordinates to screen coordinates. It does the real drawing on the screen.
See Also:
TCamera3D, Viewport

ScaleVertices

public void ScaleVertices(double _x,
                          double _y,
                          double _z)
Scales the vertices of this object in the x, y and z direction.
Parameters:
_x - Scale factor in x direction
_y - Scale factor in y direction
_z - Scale factor in z direction