org.instantreality.InstantIO
Class Matrix3f

java.lang.Object
  extended by org.instantreality.InstantIO.Matrix3f

public class Matrix3f
extends java.lang.Object

Helper class for exchanging 3x3 matrices of float values.

Matrix3f is a basic helper class for exchanging matrices of 3x3 float values between different software components. It does not contain any means for matrix arithmetics, only methods for setting and getting the matrix elements. It is not meant to be used directly by software components for matrix representation. Instead, software components should use their own, appropriate classes for handling matrices. Only when sending matrices to an OutSlot, or when receiving matrices from an InSlot, the internal representation of matrices should be converted to Matrix3f's. This ensures the interoperability between different software components that use different internal representations for matrices.

Author:
Patrick Dähne

Field Summary
static Matrix3f IDENTITY
          The identity matrix.
 
Constructor Summary
Matrix3f(float[] matrix)
          Creates a new Matrix3f object that gets initialized by a given 9 element float array representing a 3x3 matrix.
Matrix3f(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
          Creates a new Matrix3f object that gets initialized by given 9 float values representing a 3x3 matrix.
Matrix3f(Matrix3f matrix)
          Constructor that initializes the components of the Matrix3f object with the elements taken from another Matrix3f object.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares the matrix to another object.
 void get(float[] matrix)
          Returns the matrix elements.
 float get(int index)
          Returns one element of the matrix.
 java.lang.String toString()
          Converts the matrix to a string.
static Matrix3f valueOf(java.lang.String str)
          Converts a string to a Matrix3f object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final Matrix3f IDENTITY
The identity matrix.

Constructor Detail

Matrix3f

public Matrix3f(float m11,
                float m12,
                float m13,
                float m21,
                float m22,
                float m23,
                float m31,
                float m32,
                float m33)
Creates a new Matrix3f object that gets initialized by given 9 float values representing a 3x3 matrix.

Parameters:
m11 - The value at row 1, column 1 of the matrix
m12 - The value at row 1, column 2 of the matrix
m13 - The value at row 1, column 3 of the matrix
m21 - The value at row 2, column 1 of the matrix
m22 - The value at row 2, column 2 of the matrix
m23 - The value at row 2, column 3 of the matrix
m31 - The value at row 3, column 1 of the matrix
m32 - The value at row 3, column 2 of the matrix
m33 - The value at row 3, column 3 of the matrix

Matrix3f

public Matrix3f(float[] matrix)
Creates a new Matrix3f object that gets initialized by a given 9 element float array representing a 3x3 matrix.

Parameters:
matrix - The nine components of the matrix

Matrix3f

public Matrix3f(Matrix3f matrix)
Constructor that initializes the components of the Matrix3f object with the elements taken from another Matrix3f object.

The following example demonstrates how to create a Matrix3f object that is an exact copy of another Matrix3f object:

 Matrix3f given_mat = ...;
 Matrix3f mat = new Matrix3f(given_mat);
 

Parameters:
matrix - The other matrix used to initialize the new matrix.
Method Detail

get

public final void get(float[] matrix)
Returns the matrix elements.

The following example extracts the translation vector from the matrix and prints it to the console:

 Matrix3f mat = ...;
 float[] m = new float[9];
 mat.get(m);
 float x = m[6];
 float y = m[7];
 System.out.println("Translation = " + x + " " + y);
 

Parameters:
matrix - A float array that gets filled with the elements of the matrix. This array must have at least nine elements.

get

public final float get(int index)
Returns one element of the matrix.

The following example extracts the translation vector from the matrix and prints it to the console:

 Matrix3f mat = ...;
 float x = mat.get(6);
 float y = mat.get(7);
 System.out.println("Translation = " + x + " " + y);
 

Parameters:
index - The index of the element. This must be between 0 and 8, inclusively.
Returns:
The value of the element.

equals

public final boolean equals(java.lang.Object obj)
Compares the matrix to another object. The result is true if the object is not null and is a Matrix3f object and the matrix elements of the other Matrix3f object are the same as the matrix elements of this matrix.

The following example compares two matrices and prints the result to the console:

 Matrix3f mat1 = ...;
 Matrix3f mat2 = ...;
 System.out.println("Matrices are the same: " + mat1.equals(mat2));
 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare the matrix to
Returns:
true when the matrices are equal, false otherwise

toString

public final java.lang.String toString()
Converts the matrix to a string. The string representation consists of the nine matrix elements, separated by space characters.

The following example prints the string representation of a Matrix3f object to the console:

 Matrix3f mat = ...;
 System.out.println("Matrix = " + mat.toString());
 

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the matrix.

valueOf

public static final Matrix3f valueOf(java.lang.String str)
Converts a string to a Matrix3f object. The string must consist of the nine matrix elements, separated by space characters.

The following example creates a new Matrix3f object that represents a translation of 1 unit along the x axis and 2 units along the y axis:

 Matrix3f mat = Matrix3f.valueOf("1.0 0.0 0.0 0.0 1.0 0.0 1.0 2.0 1.0");
 

Parameters:
str - The string representation of the matrix.
Returns:
The new Matrix3f object, parsed from the string.