com.threerings.math
Class Matrix3f

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

public final class Matrix3f
extends Object
implements Encodable, com.threerings.io.Streamable

A 3x3 column-major matrix.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
static Matrix3f IDENTITY
          The identity matrix.
 float m00
          The values of the matrix.
 float m01
           
 float m02
           
 float m10
          The values of the matrix.
 float m11
           
 float m12
           
 float m20
          The values of the matrix.
 float m21
           
 float m22
           
 
Constructor Summary
Matrix3f()
          Creates an identity matrix.
Matrix3f(float[] values)
          Creates a matrix from an array of values.
Matrix3f(float m00, float m10, float m20, float m01, float m11, float m21, float m02, float m12, float m22)
          Creates a matrix from its components.
Matrix3f(Matrix3f other)
          Copy constructor.
 
Method Summary
 float approximateUniformScale()
          Returns an approximation of the uniform scale for this matrix (the square root of the signed area of the parallelogram spanned by the axis vectors).
 void decodeFromStream(DataInputStream in)
          Initializes this object with data read from the specified stream.
 void decodeFromString(String string)
          Initializes this object with the contents of the specified string.
 void encodeToStream(DataOutputStream out)
          Encodes this object to the specified stream.
 String encodeToString()
          Returns a string representation of this object.
 boolean equals(Object other)
           
 float extractRotation()
          Extracts the rotation component of the matrix.
 Vector2f extractScale()
          Extracts the scale component of the matrix.
 Vector2f extractScale(Vector2f result)
          Extracts the scale component of the matrix and places it in the provided result vector.
 FloatBuffer get(FloatBuffer buf)
          Places the contents of this matrix into the given buffer in the standard OpenGL order.
 int hashCode()
           
 Matrix3f invert()
          Inverts this matrix.
 Matrix3f invert(Matrix3f result)
          Inverts this matrix and places the result in the given object.
 Matrix3f invertAffine()
          Inverts this matrix as an affine matrix.
 Matrix3f invertAffine(Matrix3f result)
          Inverts this matrix as an affine matrix and places the result in the given object.
 Matrix3f invertAffineLocal()
          Inverts this matrix in-place as an affine matrix.
 Matrix3f invertLocal()
          Inverts this matrix in-place.
 boolean isAffine()
          Determines whether this matrix represents an affine transformation.
 Matrix3f lerp(Matrix3f other, float t)
          Linearly interpolates between this and the specified other matrix.
 Matrix3f lerp(Matrix3f other, float t, Matrix3f result)
          Linearly interpolates between this and the specified other matrix, placing the result in the object provided.
 Matrix3f lerpAffine(Matrix3f other, float t)
          Linearly interpolates between this and the specified other matrix, treating the matrices as affine.
 Matrix3f lerpAffine(Matrix3f other, float t, Matrix3f result)
          Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in the object provided.
 Matrix3f lerpAffineLocal(Matrix3f other, float t)
          Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in this matrix.
 Matrix3f lerpLocal(Matrix3f other, float t)
          Linearly interpolates between the this and the specified other matrix, placing the result in this matrix.
 Matrix3f mult(Matrix3f other)
          Multiplies this matrix by another.
 Matrix3f mult(Matrix3f other, Matrix3f result)
          Multiplies this matrix by another and stores the result in the object provided.
 Matrix3f multAffine(Matrix3f other)
          Multiplies this matrix by another, treating the matrices as affine.
 Matrix3f multAffine(Matrix3f other, Matrix3f result)
          Multiplies this matrix by another, treating the matrices as affine, and stores the result in the object provided.
 Matrix3f multAffineLocal(Matrix3f other)
          Multiplies this matrix in-place by another, treating the matricees as affine.
 Matrix3f multLocal(Matrix3f other)
          Multiplies this matrix in-place by another.
 Matrix3f set(float[] values)
          Copies the elements of an array.
 Matrix3f set(float m00, float m10, float m20, float m01, float m11, float m21, float m02, float m12, float m22)
          Sets all of the matrix's components at once.
 Matrix3f set(Matrix3f other)
          Copies the contents of another matrix.
 Matrix3f setToIdentity()
          Sets this matrix to the identity matrix.
 Matrix3f setToReflection(float x, float y, float z)
          Sets this to a reflection across a plane intersecting the origin with the supplied normal.
 Matrix3f setToReflection(Vector3f normal)
          Sets this to a reflection across a plane intersecting the origin with the supplied normal.
 Matrix3f setToRotation(float angle)
          Sets this to a rotation matrix.
 Matrix3f setToRotation(float angle, float x, float y, float z)
          Sets this to a rotation matrix.
 Matrix3f setToRotation(float angle, Vector3f axis)
          Sets this to a rotation matrix.
 Matrix3f setToRotation(Quaternion quat)
          Sets this to a rotation matrix.
 Matrix3f setToRotation(Vector3f from, Vector3f to)
          Sets this to a rotation matrix that rotates one vector onto another.
 Matrix3f setToScale(float s)
          Sets this to a uniform scale matrix.
 Matrix3f setToScale(float x, float y, float z)
          Sets this to a scale matrix.
 Matrix3f setToScale(Vector3f scale)
          Sets this to a scale matrix.
 Matrix3f setToTransform(Vector2f translation, float rotation)
          Sets this to a matrix that first rotates, then translates.
 Matrix3f setToTransform(Vector2f translation, float rotation, float scale)
          Sets this to a matrix that first scales, then rotates, then translates.
 Matrix3f setToTransform(Vector2f translation, float rotation, Vector2f scale)
          Sets this to a matrix that first scales, then rotates, then translates.
 Matrix3f setToTranslation(float x, float y)
          Sets this to a translation matrix.
 Matrix3f setToTranslation(Vector2f translation)
          Sets this to a translation matrix.
 Matrix3f setTranslation(float x, float y)
          Sets the translation component of this matrix.
 Matrix3f setTranslation(Vector2f translation)
          Sets the translation component of this matrix.
 String toString()
           
 Vector3f transform(Vector3f vector)
          Transforms a vector by this matrix.
 Vector3f transform(Vector3f vector, Vector3f result)
          Transforms a vector by this matrix and places the result in the object provided.
 Vector3f transformLocal(Vector3f vector)
          Transforms a vector in-place by the inner 3x3 part of this matrix.
 Vector2f transformPoint(Vector2f point)
          Transforms a point by this matrix.
 Vector2f transformPoint(Vector2f point, Vector2f result)
          Transforms a point by this matrix and places the result in the object provided.
 Vector2f transformPointLocal(Vector2f point)
          Transforms a point in-place by this matrix.
 Vector2f transformVector(Vector2f vector)
          Transforms a vector by this inner 2x2 part of this matrix.
 Vector2f transformVector(Vector2f vector, Vector2f result)
          Transforms a vector by the inner 2x2 part of this matrix and places the result in the object provided.
 Vector2f transformVectorLocal(Vector2f vector)
          Transforms a vector in-place by the inner 2x2 part of this matrix.
 Matrix3f transpose()
          Transposes this matrix.
 Matrix3f transpose(Matrix3f result)
          Transposes this matrix, storing the result in the provided object.
 Matrix3f transposeLocal()
          Transposes this matrix in-place.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final Matrix3f IDENTITY
The identity matrix.


m00

public float m00
The values of the matrix.


m10

public float m10
The values of the matrix.


m20

public float m20
The values of the matrix.


m01

public float m01

m11

public float m11

m21

public float m21

m02

public float m02

m12

public float m12

m22

public float m22
Constructor Detail

Matrix3f

public Matrix3f(float m00,
                float m10,
                float m20,
                float m01,
                float m11,
                float m21,
                float m02,
                float m12,
                float m22)
Creates a matrix from its components.


Matrix3f

public Matrix3f(float[] values)
Creates a matrix from an array of values.


Matrix3f

public Matrix3f(Matrix3f other)
Copy constructor.


Matrix3f

public Matrix3f()
Creates an identity matrix.

Method Detail

setToIdentity

public Matrix3f setToIdentity()
Sets this matrix to the identity matrix.

Returns:
a reference to this matrix, for chaining.

setToRotation

public Matrix3f setToRotation(Vector3f from,
                              Vector3f to)
Sets this to a rotation matrix that rotates one vector onto another.

Returns:
a reference to this matrix, for chaining.

setToRotation

public Matrix3f setToRotation(float angle,
                              Vector3f axis)
Sets this to a rotation matrix.

Returns:
a reference to this matrix, for chaining.

setToRotation

public Matrix3f setToRotation(float angle,
                              float x,
                              float y,
                              float z)
Sets this to a rotation matrix. The formula comes from the OpenGL documentation for the glRotatef function.

Returns:
a reference to this matrix, for chaining.

setToRotation

public Matrix3f setToRotation(Quaternion quat)
Sets this to a rotation matrix. The formula comes from the Matrix and Quaternion FAQ.

Returns:
a reference to this matrix, for chaining.

setToScale

public Matrix3f setToScale(Vector3f scale)
Sets this to a scale matrix.

Returns:
a reference to this matrix, for chaining.

setToScale

public Matrix3f setToScale(float s)
Sets this to a uniform scale matrix.

Returns:
a reference to this matrix, for chaining.

setToScale

public Matrix3f setToScale(float x,
                           float y,
                           float z)
Sets this to a scale matrix.

Returns:
a reference to this matrix, for chaining.

setToReflection

public Matrix3f setToReflection(Vector3f normal)
Sets this to a reflection across a plane intersecting the origin with the supplied normal.

Returns:
a reference to this matrix, for chaining.

setToReflection

public Matrix3f setToReflection(float x,
                                float y,
                                float z)
Sets this to a reflection across a plane intersecting the origin with the supplied normal.

Returns:
a reference to this matrix, for chaining.

setToTransform

public Matrix3f setToTransform(Vector2f translation,
                               float rotation)
Sets this to a matrix that first rotates, then translates.

Returns:
a reference to this matrix, for chaining.

setToTransform

public Matrix3f setToTransform(Vector2f translation,
                               float rotation,
                               float scale)
Sets this to a matrix that first scales, then rotates, then translates.

Returns:
a reference to this matrix, for chaining.

setToTransform

public Matrix3f setToTransform(Vector2f translation,
                               float rotation,
                               Vector2f scale)
Sets this to a matrix that first scales, then rotates, then translates.

Returns:
a reference to this matrix, for chaining.

setToTranslation

public Matrix3f setToTranslation(Vector2f translation)
Sets this to a translation matrix.

Returns:
a reference to this matrix, for chaining.

setToTranslation

public Matrix3f setToTranslation(float x,
                                 float y)
Sets this to a translation matrix.

Returns:
a reference to this matrix, for chaining.

setTranslation

public Matrix3f setTranslation(Vector2f translation)
Sets the translation component of this matrix.

Returns:
a reference to this matrix, for chaining.

setTranslation

public Matrix3f setTranslation(float x,
                               float y)
Sets the translation component of this matrix.

Returns:
a reference to this matrix, for chaining.

setToRotation

public Matrix3f setToRotation(float angle)
Sets this to a rotation matrix.

Returns:
a reference to this matrix, for chaining.

transposeLocal

public Matrix3f transposeLocal()
Transposes this matrix in-place.

Returns:
a reference to this matrix, for chaining.

transpose

public Matrix3f transpose()
Transposes this matrix.

Returns:
a new matrix containing the result.

transpose

public Matrix3f transpose(Matrix3f result)
Transposes this matrix, storing the result in the provided object.

Returns:
the result matrix, for chaining.

multLocal

public Matrix3f multLocal(Matrix3f other)
Multiplies this matrix in-place by another.

Returns:
a reference to this matrix, for chaining.

mult

public Matrix3f mult(Matrix3f other)
Multiplies this matrix by another.

Returns:
a new matrix containing the result.

mult

public Matrix3f mult(Matrix3f other,
                     Matrix3f result)
Multiplies this matrix by another and stores the result in the object provided.

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

isAffine

public boolean isAffine()
Determines whether this matrix represents an affine transformation.


multAffineLocal

public Matrix3f multAffineLocal(Matrix3f other)
Multiplies this matrix in-place by another, treating the matricees as affine.

Returns:
a reference to this matrix, for chaining.

multAffine

public Matrix3f multAffine(Matrix3f other)
Multiplies this matrix by another, treating the matrices as affine.

Returns:
a new matrix containing the result.

multAffine

public Matrix3f multAffine(Matrix3f other,
                           Matrix3f result)
Multiplies this matrix by another, treating the matrices as affine, and stores the result in the object provided.

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

invertLocal

public Matrix3f invertLocal()
Inverts this matrix in-place.

Returns:
a reference to this matrix, for chaining.

invert

public Matrix3f invert()
Inverts this matrix.

Returns:
a new matrix containing the result.

invert

public Matrix3f invert(Matrix3f result)
                throws SingularMatrixException
Inverts this matrix and places the result in the given object. This code is based on the examples in the Matrix and Quaternion FAQ.

Returns:
a reference to the result matrix, for chaining.
Throws:
SingularMatrixException

invertAffineLocal

public Matrix3f invertAffineLocal()
Inverts this matrix in-place as an affine matrix.

Returns:
a reference to this matrix, for chaining.

invertAffine

public Matrix3f invertAffine()
Inverts this matrix as an affine matrix.

Returns:
a new matrix containing the result.

invertAffine

public Matrix3f invertAffine(Matrix3f result)
                      throws SingularMatrixException
Inverts this matrix as an affine matrix and places the result in the given object.

Returns:
a reference to the result matrix, for chaining.
Throws:
SingularMatrixException

lerpLocal

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

Returns:
a reference to this matrix, for chaining.

lerp

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

Returns:
a new matrix containing the result.

lerp

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

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

lerpAffineLocal

public Matrix3f lerpAffineLocal(Matrix3f other,
                                float t)
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in this matrix.

Returns:
a reference to this matrix, for chaining.

lerpAffine

public Matrix3f lerpAffine(Matrix3f other,
                           float t)
Linearly interpolates between this and the specified other matrix, treating the matrices as affine.

Returns:
a new matrix containing the result.

lerpAffine

public Matrix3f lerpAffine(Matrix3f other,
                           float t,
                           Matrix3f result)
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in the object provided.

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

set

public Matrix3f set(Matrix3f other)
Copies the contents of another matrix.

Returns:
a reference to this matrix, for chaining.

set

public Matrix3f set(float[] values)
Copies the elements of an array.

Returns:
a reference to this matrix, for chaining.

set

public Matrix3f set(float m00,
                    float m10,
                    float m20,
                    float m01,
                    float m11,
                    float m21,
                    float m02,
                    float m12,
                    float m22)
Sets all of the matrix's components at once.

Returns:
a reference to this matrix, for chaining.

get

public FloatBuffer get(FloatBuffer buf)
Places the contents of this matrix into the given buffer in the standard OpenGL order.

Returns:
a reference to the buffer, for chaining.

transformLocal

public Vector3f transformLocal(Vector3f vector)
Transforms a vector in-place by the inner 3x3 part of this matrix.

Returns:
a reference to the vector, for chaining.

transform

public Vector3f transform(Vector3f vector)
Transforms a vector by this matrix.

Returns:
a new vector containing the result.

transform

public Vector3f transform(Vector3f vector,
                          Vector3f result)
Transforms a vector by this matrix and places the result in the object provided.

Returns:
a reference to the result, for chaining.

transformPointLocal

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

Returns:
a reference to the point, for chaining.

transformPoint

public Vector2f transformPoint(Vector2f point)
Transforms a point by this matrix.

Returns:
a new vector containing the result.

transformPoint

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

Returns:
a reference to the result, for chaining.

transformVectorLocal

public Vector2f transformVectorLocal(Vector2f vector)
Transforms a vector in-place by the inner 2x2 part of this matrix.

Returns:
a reference to the vector, for chaining.

transformVector

public Vector2f transformVector(Vector2f vector)
Transforms a vector by this inner 2x2 part of this matrix.

Returns:
a new vector containing the result.

transformVector

public Vector2f transformVector(Vector2f vector,
                                Vector2f result)
Transforms a vector by the inner 2x2 part of this matrix and places the result in the object provided.

Returns:
a reference to the result, for chaining.

extractRotation

public float extractRotation()
Extracts the rotation component of the matrix. This uses the iterative polar decomposition algorithm described by Ken Shoemake.


extractScale

public Vector2f extractScale()
Extracts the scale component of the matrix.

Returns:
a new vector containing the result.

extractScale

public Vector2f extractScale(Vector2f result)
Extracts the scale component of the matrix and places it in the provided result vector.

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

approximateUniformScale

public float approximateUniformScale()
Returns an approximation of the uniform scale for this matrix (the square root of the signed area of the parallelogram spanned by the axis vectors).


encodeToString

public String encodeToString()
Description copied from interface: Encodable
Returns a string representation of this object.

Specified by:
encodeToString in interface Encodable

decodeFromString

public void decodeFromString(String string)
                      throws Exception
Description copied from interface: Encodable
Initializes this object with the contents of the specified string.

Specified by:
decodeFromString in interface Encodable
Throws:
Exception

encodeToStream

public void encodeToStream(DataOutputStream out)
                    throws IOException
Description copied from interface: Encodable
Encodes this object to the specified stream.

Specified by:
encodeToStream in interface Encodable
Throws:
IOException

decodeFromStream

public void decodeFromStream(DataInputStream in)
                      throws IOException
Description copied from interface: Encodable
Initializes this object with data read from the specified stream.

Specified by:
decodeFromStream in interface Encodable
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.