y25.graphics
Class Transform

java.lang.Object
  extended byy25.graphics.Transform

public class Transform
extends Object

Represents a transform in three dimensional space that can be applied to points and vectors.

Internally, every transform is stored as a 4x4 matrix M. Applying a transform on a point p = (px,py,pz)^t simply means pre-multiplying the matrix after extending the point with the homogeneous coordinate of 1: p_transformed = M * (px,py,pz,1)^t ("^t" means transposed).

Similary, transforming a vector v = (vx,vy,vz) is accomplished by appending a homogeneous coordinate of 0 and then pre-multiplying by M: v_transformed = M * (vx,vy,vz,0)^t.

Therefore, all transformations that can be performed by this class are affine and projective transforms.


Nested Class Summary
static class Transform.Matrix4x4
          A representation for 4x4 matrices.
 
Field Summary
static int COLUMNS
          Storage specifier - indicates that the columns of a matrix are stored consecutively.
protected  Transform.Matrix4x4 inverse
          The matrix that stores the inverse of the current transform operation.
static int ROWS
          Storage specifier - indicates that the rows of a matrix are stored consecutively.
protected  Transform.Matrix4x4 transform
          The matrix that stores the current transform operation.
 
Constructor Summary
Transform()
          Creates an identity transform (a transform that has no effect when applied).
Transform(float[] m, int storeOrder)
          Creates a transform by means of a user specified transformation matrix.
Transform(Transform.Matrix4x4 trans)
          Creates a transform by means of a user specified transformation matrix.
Transform(Transform.Matrix4x4 trans, Transform.Matrix4x4 inv)
          Creates a transform by means of a user specified transformation matrix and its inverse.
Transform(Transform t)
          Creates a transform by copying the given transform.
 
Method Summary
 Point3D apply(Point3D p)
          Applies this transform to the passed point and returns a reference to that point.
 Transform apply(Transform t)
          Applies this transform to the passed transform and returns a reference to the modified passed transform.
 Vector3D apply(Vector3D v)
          Applies this transform to the passed vector and returns a reference to that vector.
 Point3D getApplied(Point3D p)
          Applies this transform to a copy of the passed point and returns the copy.
 Transform getApplied(Transform t)
          Applies this transform to a copy of the passed transform and returns a reference to that copy.
 Vector3D getApplied(Vector3D v)
          Applies this transform to the passed vector and returns a reference to that vector.
 float[] getArray(int storeOrder)
          Returns the entries of the matrix that represents this transform in the specified order.
 Transform getInverted()
          Returns copy of this transform that is the inverse of this transform.
 Transform invert()
          Inverts this transform.
static Transform lookAt(Point3D pos, Point3D look, Vector3D up)
          Creates a transform that can be used as a viewing transform that has the same effect as the OpenGL gluLookAt() routine.
static Transform perspective(float fov, float aspect, float zNear, float zFar)
          Creates a transform that can be used as a projection transform that has the same effect as the OpenGL gluPerspective() routine.
static Transform rotate(Vector3D axis, float angle)
          Creates a transform, that, when applied, performs a counter-clockwise rotation around the given vector.
static Transform rotateX(float angle)
          Creates a transform, that, when applied, performs a counter-clockwise rotation around the x-axis.
static Transform rotateY(float angle)
          Creates a transform, that, when applied, performs a counter-clockwise rotation around the y-axis.
static Transform rotateZ(float angle)
          Creates a transform, that, when applied, performs a counter-clockwise rotation around the z-axis.
static Transform scale(float x, float y, float z)
          Creates a transform, that, when applied, performs a scaling of the x,y,z-axes by the given factors.
 void setIdentity()
          Sets the current transform to the identity transform.
 String toString()
           
static Transform translate(Vector3D delta)
          Creates a transform, that, when applied, performs a translation by the given vector.
static Transform viewport(float x, float y, float width, float height)
          Creates a transform that can be used as a viewport transform that has the same effect as the OpenGL glViewport() routine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

transform

protected Transform.Matrix4x4 transform
The matrix that stores the current transform operation.


inverse

protected Transform.Matrix4x4 inverse
The matrix that stores the inverse of the current transform operation.


ROWS

public static final int ROWS
Storage specifier - indicates that the rows of a matrix are stored consecutively.

See Also:
Constant Field Values

COLUMNS

public static final int COLUMNS
Storage specifier - indicates that the columns of a matrix are stored consecutively.

See Also:
Constant Field Values
Constructor Detail

Transform

public Transform()
Creates an identity transform (a transform that has no effect when applied).


Transform

public Transform(Transform t)
Creates a transform by copying the given transform.


Transform

public Transform(float[] m,
                 int storeOrder)
Creates a transform by means of a user specified transformation matrix.

The passed array has to hold 4*4=16 values for all entries of a 4x4 matrix and the storeOrder specifies if columns or rows appear consecutively in the passed array.


Transform

public Transform(Transform.Matrix4x4 trans)
Creates a transform by means of a user specified transformation matrix.


Transform

public Transform(Transform.Matrix4x4 trans,
                 Transform.Matrix4x4 inv)
Creates a transform by means of a user specified transformation matrix and its inverse.

Method Detail

translate

public static Transform translate(Vector3D delta)
Creates a transform, that, when applied, performs a translation by the given vector.


scale

public static Transform scale(float x,
                              float y,
                              float z)
Creates a transform, that, when applied, performs a scaling of the x,y,z-axes by the given factors.


rotateX

public static Transform rotateX(float angle)
Creates a transform, that, when applied, performs a counter-clockwise rotation around the x-axis. More precisely, when looking down the negative x-axis, the rotation that is performed is counter-clockwise.

The passed angles are in degrees, not radians.


rotateY

public static Transform rotateY(float angle)
Creates a transform, that, when applied, performs a counter-clockwise rotation around the y-axis. More precisely, when looking down the negative y-axis, the rotation that is performed is counter-clockwise.

The passed angles are in degrees, not radians.


rotateZ

public static Transform rotateZ(float angle)
Creates a transform, that, when applied, performs a counter-clockwise rotation around the z-axis. More precisely, when looking down the negative z-axis, the rotation that is performed is counter-clockwise.

The passed angles are in degrees, not radians.


rotate

public static Transform rotate(Vector3D axis,
                               float angle)
Creates a transform, that, when applied, performs a counter-clockwise rotation around the given vector. More precisely, when looking in the opposite direction as the passed vector, the rotation performed is counter-clockwise.

The passed angles are in degrees, not radians.


lookAt

public static Transform lookAt(Point3D pos,
                               Point3D look,
                               Vector3D up)
Creates a transform that can be used as a viewing transform that has the same effect as the OpenGL gluLookAt() routine.

When a "viewing transform" is applied to a vector that has world coordinates, they are transformed to camera coordinates.


perspective

public static Transform perspective(float fov,
                                    float aspect,
                                    float zNear,
                                    float zFar)
Creates a transform that can be used as a projection transform that has the same effect as the OpenGL gluPerspective() routine.


viewport

public static Transform viewport(float x,
                                 float y,
                                 float width,
                                 float height)
Creates a transform that can be used as a viewport transform that has the same effect as the OpenGL glViewport() routine. It leaves the z-coordinates intact and only remaps x/y coordinates.


setIdentity

public void setIdentity()
Sets the current transform to the identity transform.


getArray

public float[] getArray(int storeOrder)
Returns the entries of the matrix that represents this transform in the specified order.


invert

public Transform invert()
Inverts this transform. Returns a reference to the inverted transform.


getInverted

public Transform getInverted()
Returns copy of this transform that is the inverse of this transform.


apply

public Point3D apply(Point3D p)
Applies this transform to the passed point and returns a reference to that point.


getApplied

public Point3D getApplied(Point3D p)
Applies this transform to a copy of the passed point and returns the copy.


apply

public Vector3D apply(Vector3D v)
Applies this transform to the passed vector and returns a reference to that vector.


getApplied

public Vector3D getApplied(Vector3D v)
Applies this transform to the passed vector and returns a reference to that vector.


apply

public Transform apply(Transform t)
Applies this transform to the passed transform and returns a reference to the modified passed transform.


getApplied

public Transform getApplied(Transform t)
Applies this transform to a copy of the passed transform and returns a reference to that copy.


toString

public String toString()