com.threerings.math
Class Transform2D

java.lang.Object
  extended by com.threerings.math.Transform2D
All Implemented Interfaces:
Exportable, com.threerings.io.Streamable

public final class Transform2D
extends Object
implements Exportable, com.threerings.io.Streamable

Represents a 2D transformation in such a way as to accelerate operations such as composition and inversion by keeping track of the nature of the transform.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
static int AFFINE
          An affine transformation represented by the upper two rows of a 3x3 matrix.
static int GENERAL
          A general transformation represented by a 3x3 matrix.
static int IDENTITY
          An identity transformation.
static int RIGID
          A rigid transformation represented by a translation vector and a rotation value.
static int UNIFORM
          A transformation represented by translation, rotation, and a uniform scale value.
 
Constructor Summary
Transform2D()
          Creates an identity transformation.
Transform2D(int type)
          Creates an identity transformation of the specified type.
Transform2D(Matrix3f matrix)
          Creates a transformation from the values in the supplied matrix.
Transform2D(Matrix3f matrix, boolean affine)
          Creates a transformation from the values in the supplied matrix.
Transform2D(Transform2D transform)
          Copy constructor.
Transform2D(Transform3D transform)
          Creates a flattened version of the supplied transform.
Transform2D(Vector2f translation, float rotation)
          Creates a transformation from the values in the supplied objects.
Transform2D(Vector2f translation, float rotation, float scale)
          Creates a transformation from the values in the supplied objects.
Transform2D(Vector2f translation, float rotation, Vector2f scale)
          Creates a transformation from the values in the supplied objects.
 
Method Summary
 float approximateUniformScale()
          Extracts an approximation of the uniform scale from this transform.
 Transform2D compose(Transform2D other)
          Composes this transform with another.
 Transform2D compose(Transform2D other, Transform2D result)
          Composes this transform with another, storing the result in the object provided.
 Transform2D composeLocal(Transform2D other)
          Composes this transform in-place with another.
 boolean equals(Object other)
           
 float extractRotation()
          Extracts the rotation component of the transform.
 Vector2f extractTranslation()
          Extracts the translation component of the transform.
 Vector2f extractTranslation(Vector2f result)
          Extracts the translation component of the transform and places it in the provided result vector.
 Matrix3f getMatrix()
          Returns a reference to the transformation matrix, which is only definitive when the type is AFFINE or GENERAL.
 float getRotation()
          Returns the rotation value, which is only definitive when the type is RIGID or UNIFORM.
 float getScale()
          Returns the uniform scale, which is only definitive when the type is UNIFORM.
 Vector2f getTranslation()
          Returns a reference to the translation vector, which is only definitive when the type is RIGID or UNIFORM.
 int getType()
          Returns the type of this transformation.
 int hashCode()
           
 Transform2D invert()
          Inverts this transform.
 Transform2D invert(Transform2D result)
          Inverts this transform, storing the result in the provided object.
 Transform2D invertLocal()
          Inverts this transform in-place.
 Transform2D lerp(Transform2D other, float t)
          Linearly interpolates between this and the specified other transform.
 Transform2D lerp(Transform2D other, float t, Transform2D result)
          Linearly interpolates between this and the specified other transform, placing the result in the transform provided.
 Transform2D lerpLocal(Transform2D other, float t)
          Linearly interpolates between this and the specified other transform, placing the result in this transform.
 Transform2D promote(int type)
          Promotes this transform to the specified type, which must be greater than or equal to its current type.
 void readFields(Importer in)
          Custom field read method.
 Transform2D set(Matrix3f matrix)
          Sets the transform using the supplied matrix.
 Transform2D set(Matrix3f matrix, boolean affine)
          Sets the transform using the supplied matrix.
 Transform2D set(Transform2D transform)
          Copies the values contained in another transform.
 Transform2D set(Transform3D transform)
          Sets the transform to a flattened version of a 3D transform.
 Transform2D set(Vector2f translation, float rotation)
          Sets the transform using the supplied values.
 Transform2D set(Vector2f translation, float rotation, float scale)
          Sets the transform using the supplied values.
 Transform2D set(Vector2f translation, float rotation, Vector2f scale)
          Sets the transform using the supplied values.
 float setRotation(float rotation)
          Sets the rotation.
 float setScale(float scale)
          Sets the uniform scale.
 Transform2D setToIdentity()
          Sets the transform to the identity transform.
 void setType(int type)
          Sets the type of the transformation.
 String toString()
           
 Vector2f transformPoint(Vector2f pt)
          Transforms a point by this transform.
 Vector2f transformPoint(Vector2f pt, Vector2f result)
          Transforms a point by this transform and places the result in the object provided.
 Vector2f transformPointLocal(Vector2f pt)
          Transforms a point in-place by this transform.
 Vector2f transformVector(Vector2f vec)
          Transforms a vector by this transform.
 Vector2f transformVector(Vector2f vec, Vector2f result)
          Transforms a vector by this transform and places the result in the object provided.
 Vector2f transformVectorLocal(Vector2f vec)
          Transforms a vector in-place by this transform.
 Transform2D update(int utype)
          Updates the transform fields corresponding to the specified type.
 void writeFields(Exporter out)
          Custom field write method.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final int IDENTITY
An identity transformation.

See Also:
Constant Field Values

RIGID

public static final int RIGID
A rigid transformation represented by a translation vector and a rotation value.

See Also:
Constant Field Values

UNIFORM

public static final int UNIFORM
A transformation represented by translation, rotation, and a uniform scale value.

See Also:
Constant Field Values

AFFINE

public static final int AFFINE
An affine transformation represented by the upper two rows of a 3x3 matrix.

See Also:
Constant Field Values

GENERAL

public static final int GENERAL
A general transformation represented by a 3x3 matrix.

See Also:
Constant Field Values
Constructor Detail

Transform2D

public Transform2D()
Creates an identity transformation.


Transform2D

public Transform2D(int type)
Creates an identity transformation of the specified type.


Transform2D

public Transform2D(Vector2f translation,
                   float rotation)
Creates a transformation from the values in the supplied objects.


Transform2D

public Transform2D(Vector2f translation,
                   float rotation,
                   float scale)
Creates a transformation from the values in the supplied objects.


Transform2D

public Transform2D(Vector2f translation,
                   float rotation,
                   Vector2f scale)
Creates a transformation from the values in the supplied objects.


Transform2D

public Transform2D(Matrix3f matrix)
Creates a transformation from the values in the supplied matrix.


Transform2D

public Transform2D(Matrix3f matrix,
                   boolean affine)
Creates a transformation from the values in the supplied matrix.

Parameters:
affine - whether or not the provided matrix is known to be affine.

Transform2D

public Transform2D(Transform3D transform)
Creates a flattened version of the supplied transform.


Transform2D

public Transform2D(Transform2D transform)
Copy constructor.

Method Detail

getType

public int getType()
Returns the type of this transformation.


setType

public void setType(int type)
Sets the type of the transformation. This doesn't actually change any of the values, but it does initialize the fields required for the type if they are null. To promote to a more general transform type, see promote(int).


getTranslation

public Vector2f getTranslation()
Returns a reference to the translation vector, which is only definitive when the type is RIGID or UNIFORM.


getRotation

public float getRotation()
Returns the rotation value, which is only definitive when the type is RIGID or UNIFORM.


setRotation

public float setRotation(float rotation)
Sets the rotation.

Returns:
the rotation value set, for chaining.

getScale

public float getScale()
Returns the uniform scale, which is only definitive when the type is UNIFORM.


setScale

public float setScale(float scale)
Sets the uniform scale.

Returns:
the scale value set, for chaining.

getMatrix

public Matrix3f getMatrix()
Returns a reference to the transformation matrix, which is only definitive when the type is AFFINE or GENERAL.


invertLocal

public Transform2D invertLocal()
Inverts this transform in-place.

Returns:
a reference to this transform, for chaining.

invert

public Transform2D invert()
Inverts this transform.

Returns:
a new transform containing the result.

invert

public Transform2D invert(Transform2D result)
Inverts this transform, storing the result in the provided object.

Returns:
a reference to the result transform, for chaining.

composeLocal

public Transform2D composeLocal(Transform2D other)
Composes this transform in-place with another.

Returns:
a reference to this transform, for chaining.

compose

public Transform2D compose(Transform2D other)
Composes this transform with another.

Returns:
a new transform containing the result.

compose

public Transform2D compose(Transform2D other,
                           Transform2D result)
Composes this transform with another, storing the result in the object provided.


lerpLocal

public Transform2D lerpLocal(Transform2D other,
                             float t)
Linearly interpolates between this and the specified other transform, placing the result in this transform.

Returns:
a reference to this transform, for chaining.

lerp

public Transform2D lerp(Transform2D other,
                        float t)
Linearly interpolates between this and the specified other transform.

Returns:
a new transform containing the result.

lerp

public Transform2D lerp(Transform2D other,
                        float t,
                        Transform2D result)
Linearly interpolates between this and the specified other transform, placing the result in the transform provided.

Returns:
a reference to the result transform, for chaining.

set

public Transform2D set(Transform2D transform)
Copies the values contained in another transform.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Transform3D transform)
Sets the transform to a flattened version of a 3D transform.

Returns:
a reference to this transform, for chaining.

setToIdentity

public Transform2D setToIdentity()
Sets the transform to the identity transform.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Vector2f translation,
                       float rotation)
Sets the transform using the supplied values.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Vector2f translation,
                       float rotation,
                       float scale)
Sets the transform using the supplied values.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Vector2f translation,
                       float rotation,
                       Vector2f scale)
Sets the transform using the supplied values.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Matrix3f matrix)
Sets the transform using the supplied matrix.

Returns:
a reference to this transform, for chaining.

set

public Transform2D set(Matrix3f matrix,
                       boolean affine)
Sets the transform using the supplied matrix.

Parameters:
affine - whether or not the provided matrix is affine.
Returns:
a reference to this transform, for chaining.

promote

public Transform2D promote(int type)
Promotes this transform to the specified type, which must be greater than or equal to its current type.

Returns:
a reference to this transform, for chaining.

update

public Transform2D update(int utype)
Updates the transform fields corresponding to the specified type. For example, if this matrix is IDENTITY and type is RIGID, then the translation and rotation fields are set to zero.

Parameters:
utype - the desired type, which must be greater than or equal to the type of this transform.
Returns:
a reference to this transform, for chaining.

transformPointLocal

public Vector2f transformPointLocal(Vector2f pt)
Transforms a point in-place by this transform.

Returns:
a reference to the point, for chaining.

transformPoint

public Vector2f transformPoint(Vector2f pt)
Transforms a point by this transform.

Returns:
a new vector containing the result.

transformPoint

public Vector2f transformPoint(Vector2f pt,
                               Vector2f result)
Transforms a point by this transform and places the result in the object provided.

Returns:
a reference to the result object, for chaining.

transformVectorLocal

public Vector2f transformVectorLocal(Vector2f vec)
Transforms a vector in-place by this transform.

Returns:
a reference to the transformed vector, for chaining.

transformVector

public Vector2f transformVector(Vector2f vec)
Transforms a vector by this transform.

Returns:
a new vector containing the result.

transformVector

public Vector2f transformVector(Vector2f vec,
                                Vector2f result)
Transforms a vector by this transform and places the result in the object provided.

Returns:
a reference to the result vector, for chaining.

extractTranslation

public Vector2f extractTranslation()
Extracts the translation component of the transform.

Returns:
a new vector containing the result.

extractTranslation

public Vector2f extractTranslation(Vector2f result)
Extracts the translation component of the transform and places it in the provided result vector.

Returns:
a reference to the result vector, for chaining.

extractRotation

public float extractRotation()
Extracts the rotation component of the transform.


approximateUniformScale

public float approximateUniformScale()
Extracts an approximation of the uniform scale from this transform.


writeFields

public void writeFields(Exporter out)
                 throws IOException
Custom field write method.

Throws:
IOException

readFields

public void readFields(Importer in)
                throws IOException
Custom field read method.

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.