mr3d.lang
Class TriangleBased3DObject

java.lang.Object
  extended bymr3d.debug.ErrorHandling
      extended bymr3d.lang.TriangleBased3DObject
All Implemented Interfaces:
Debugable, Transformable

public class TriangleBased3DObject
extends ErrorHandling
implements Debugable, Transformable

Representation of a 3D object as a composition of a number of Triangle3D objects.

Since:
MR3Dv1.0
Version:
10-2004
Author:
Manuel Ruelke

Field Summary
 int firstPAI
          Stores where in the PointArrayTable the object points can be found.
 int lastPAI
          Stores where in the PointArrayTable the object points can be found.
(package private)  java.util.Vector planes
          Vector containing all triangles of the 3D object.
private  boolean recalculate
          Internal boolean to avoid uneccessary recalculations.
(package private)  Vector3D rotVector
          Keeps track of the objects movements in respects of translation or rotation.
(package private)  Vector3D scaleVector
          Skale factor of the object.
(package private)  Vector3D transVector
          Keeps track of the objects movements in respects of translation or rotation.
private  boolean visibilityBit
          Visibility bit.
 
Fields inherited from class mr3d.debug.ErrorHandling
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
TriangleBased3DObject()
          Creates a new TriangleBased3DObject
 
Method Summary
 void addPlane(Triangle3D newTriangle)
          Adds a new plane (triangle) to the plane vector.
 Triangle3D getPlane(int index)
          Returns the triangle object at the specified index in the planes field.
 boolean isVisible()
          Determines if the object is visible or not.
 void move(int x, int y, int z)
          Moves the object for the specified values in each direction.
 void move(Vector3D relcoords)
          Moves the object for the specified values in each direction.
 void moveNulltoReferencePoint(Vector3D referencePointCoords)
          Moves the object coordinate systems null point to the point specified in the vector referencePointCoords.
 void moveTo(int x, int y, int z)
          Moves the objects to the specified coordinates in the way that the object coordinate null point is in the specified world-coordinate position.
 void moveTo(Vector3D newPos)
          Moves the objects to the specified coordinates.
 Vector3D objectPosition()
          Returns the object position in world coordinates.
 void recalculate()
          recalculates the position of all points and all plane normals of the object according to the current rotation and rotation settings.
 void redefine(Vector3D refpoint, Vector3D transvec, Vector3D rotvec)
          Moves the obejct in the object coordinate system.
 void reset()
          Resets the object to its initial values.
 void rotate(int x, int y, int z)
          Rotates the object about the center of the object coordinate system relatively to its current positon.
 void rotate(Vector3D relcoords)
          Rotates the object about the center of the object coordinate system.
 void rotateAround(Vector3D rotationPointCoords, Vector3D rotationAngles)
          Rotates the object around a point other than the object coordinate null point.
 void rotateTo(int x, int y, int z)
          Rotates the object about the center of the object coordinate system to the specified angles.
 void rotateTo(Vector3D absVector)
          Rotates the object about the center of the object coordinate system to the specified angles.
 Vector3D rotVector()
          Returns the rotation vector of the object..
 void scale(int x, int y, int z)
          Sets the scalation of the object.
 void setVisibility(boolean toggleVis)
          Affects the visibilty of the object.
 int size()
          Returns the triangles in the planes field.
 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)
          Transforms the points objects.
 
Methods inherited from class mr3d.debug.ErrorHandling
getErrMsg, notifyError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

firstPAI

public int firstPAI
Stores where in the PointArrayTable the object points can be found.


lastPAI

public int lastPAI
Stores where in the PointArrayTable the object points can be found.


planes

java.util.Vector planes
Vector containing all triangles of the 3D object.


recalculate

private boolean recalculate
Internal boolean to avoid uneccessary recalculations. If a status vector changes the variable is set to true. After calling recalculate() it is set to false.


rotVector

Vector3D rotVector
Keeps track of the objects movements in respects of translation or rotation.


scaleVector

Vector3D scaleVector
Skale factor of the object. This value is normally 128 = 100%.


transVector

Vector3D transVector
Keeps track of the objects movements in respects of translation or rotation.


visibilityBit

private boolean visibilityBit
Visibility bit. If true the object is visible, if false object is invisible.

Constructor Detail

TriangleBased3DObject

public TriangleBased3DObject()
Creates a new TriangleBased3DObject

Method Detail

addPlane

public void addPlane(Triangle3D newTriangle)
Adds a new plane (triangle) to the plane vector.

Parameters:
newTriangle - the triangle object to be added to the plane vector

getPlane

public Triangle3D getPlane(int index)
Returns the triangle object at the specified index in the planes field.

Parameters:
index - index of the plane in the object vector
Returns:
triangle object

isVisible

public boolean isVisible()
Determines if the object is visible or not.

Returns:
true if the object is visible, false if object is invisible.

move

public void move(int x,
                 int y,
                 int z)
Moves the object for the specified values in each direction.

Parameters:
x - move for specified number of units into the direction of the x-axis
y - move for specified number of units into the direction of the y-axis
z - move for specified number of units into the direction of the z-axis

move

public void move(Vector3D relcoords)
Moves the object for the specified values in each direction.

Parameters:
relcoords - move the objects for the coordinates specified

moveNulltoReferencePoint

public void moveNulltoReferencePoint(Vector3D referencePointCoords)
Moves the object coordinate systems null point to the point specified in the vector referencePointCoords. Those coordinates are specifications in the current object coordinate system.

Parameters:
referencePointCoords - object coordinates of new reference point

moveTo

public void moveTo(int x,
                   int y,
                   int z)
Moves the objects to the specified coordinates in the way that the object coordinate null point is in the specified world-coordinate position.

Parameters:
x - x-coordinate of the destination point
y - y-coordinate of the destination point
z - z-coordinate of the destination point

moveTo

public void moveTo(Vector3D newPos)
Moves the objects to the specified coordinates.

Parameters:
newPos - contains the coordinates of the destination point

objectPosition

public Vector3D objectPosition()
Returns the object position in world coordinates.

Returns:
a copy of the referencePointCoords vector

recalculate

public void recalculate()
recalculates the position of all points and all plane normals of the object according to the current rotation and rotation settings.


redefine

public void redefine(Vector3D refpoint,
                     Vector3D transvec,
                     Vector3D rotvec)
Moves the obejct in the object coordinate system. This method calculates the new positions in the object coordinate system and overwrites the base vectors. Do not use this method too often for it is subject to rounding errors.

Parameters:
refpoint - the new reference point (center of rotation) in object coordinates
transvec - changes object position relative to its current position
rotvec - changes the object rotation relative to its current rotation

reset

public void reset()
Resets the object to its initial values.


rotate

public void rotate(int x,
                   int y,
                   int z)
Rotates the object about the center of the object coordinate system relatively to its current positon.

Parameters:
x - angle for rotation about the x-axis
y - angle for rotation about the y-axis
z - angle for rotation about the z-axis

rotate

public void rotate(Vector3D relcoords)
Rotates the object about the center of the object coordinate system.

Parameters:
relcoords - contains the angles of the object rotation

rotateAround

public void rotateAround(Vector3D rotationPointCoords,
                         Vector3D rotationAngles)
Rotates the object around a point other than the object coordinate null point. This rotation is not stored by the transformation vectors. If an object is persitently supposed to be rotated around another point but the object coordinate null point the programmer has to repeat the complete rotation each time after the reacalulation of the object.

Parameters:
rotationPointCoords - coordinates of center of rotation
rotationAngles - angles the object should be rotated

rotateTo

public void rotateTo(int x,
                     int y,
                     int z)
Rotates the object about the center of the object coordinate system to the specified angles.

Parameters:
x - angle for rotation about the x-axis
y - angle for rotation about the y-axis
z - angle for rotation about the z-axis

rotateTo

public void rotateTo(Vector3D absVector)
Rotates the object about the center of the object coordinate system to the specified angles.

Parameters:
absVector - angles for rotation about the x-, y- and z-axis in a 3d-vector

rotVector

public Vector3D rotVector()
Returns the rotation vector of the object..

Returns:
a copy of the rotation vector

scale

public void scale(int x,
                  int y,
                  int z)
Sets the scalation of the object. The values can have any value but should always be greater than zero. Otherwise the rendered images may get a bit funky.

Parameters:
x - scalation in x-direction
y - scalation in x-direction
z - scalation in x-direction

setVisibility

public void setVisibility(boolean toggleVis)
Affects the visibilty of the object.

Parameters:
toggleVis - true for visibility and false for invisibility

size

public int size()
Returns the triangles in the planes field.

Returns:
number of elements of planes-object

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)
Transforms the points objects. The method multiplies the coordinate vectors of the points with the matrix.

Specified by:
transform in interface Transformable
Parameters:
transMat - transformation matrix