com.cult3d.math
Class Matrix4x4

java.lang.Object
  |
  +--com.cult3d.math.Matrix4x4

public class Matrix4x4
extends java.lang.Object

This class represents a 4x4 matrix and define a few matrix operations.

Since:
Cult3D 4.2

Constructor Summary
Matrix4x4()
          Constructs and initializes a Matri4x4 to all zeros.
Matrix4x4(float[] array)
          Constructor that creates a new matrix4x4 from an array of floats with length of 16.
Matrix4x4(Matrix4x4 matrix)
          Constructs a Matrix4x4 with the same values as the given parameter.
 
Method Summary
 void add(Matrix4x4 matrix)
          Adds the matrix given as parameter to this matrix, element by element.
 boolean equals(java.lang.Object obj)
          Returns true if this matrix and the Object given as argument are equal.
 java.lang.String getInfo()
          This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.
 float[] getMatrix()
          Returns a float array containing the elements of this matrix row by row.
 float getValue(int row, int col)
          Gets the value of the element at a specific row and column.
 void identity()
          Sets this Matrix to the identity Matrix.
 void mult(float f)
          Multiplies each element of this matrix with the value given as parameter.
 void setMatrix(float[] array)
          Sets the values of this matrix using the values supplied by the given float array.
 void setMatrix(Matrix4x4 matrix)
          Copies the values from the source matrix, given as argument, to this matrix.
 void setValue(int row, int col, float value)
          Sets the value of the element at a specific row and column.
 void sub(Matrix4x4 matrix)
          Subtracts the matrix given as parameter from this matrix, element by element.
 java.lang.String toString()
           Returns a string representation of the values of this object.
 void transpose()
          Transposes this matrix.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Matrix4x4

public Matrix4x4()
Constructs and initializes a Matri4x4 to all zeros.
Since:
Cult3D 4.2

Matrix4x4

public Matrix4x4(Matrix4x4 matrix)
Constructs a Matrix4x4 with the same values as the given parameter.
Parameters:
matrix - The source matrix
Since:
Cult3D 4.2

Matrix4x4

public Matrix4x4(float[] array)
Constructor that creates a new matrix4x4 from an array of floats with length of 16. If the array is shorter than 16 an ArrayIndexOutOfBoundsException will be thrown. If it is longer, the extra elements will be ignored.

The array elements will be placed in the matrix as follows:

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

Parameters:
array - A float array of length 16 that contains the values of the matrix.
Since:
Cult3D 4.2
Method Detail

setMatrix

public void setMatrix(Matrix4x4 matrix)
Copies the values from the source matrix, given as argument, to this matrix.
Parameters:
matrix - The source matrix
Since:
Cult3D 4.2

setMatrix

public void setMatrix(float[] array)
Sets the values of this matrix using the values supplied by the given float array. The array must have 16 elements, if it is shorter an ArrayIndexOutOfBoundsException will be thrown, and if it is longer, the extra elements will be ignored.

The array elements will be placed in the matrix as follows:

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

Parameters:
array - The source array with length 16
Since:
Cult3D 4.2

getMatrix

public float[] getMatrix()
Returns a float array containing the elements of this matrix row by row.
Returns:
An array with length 16 containing the Matrix values
Since:
Cult3D 4.2

setValue

public void setValue(int row,
                     int col,
                     float value)
Sets the value of the element at a specific row and column.
Parameters:
row - the row
col - the column
value - the new value
Since:
Cult3D 4.2

getValue

public float getValue(int row,
                      int col)
Gets the value of the element at a specific row and column.
Parameters:
row - the row
col - the column
Returns:
the indexed value
Since:
Cult3D 4.2

add

public void add(Matrix4x4 matrix)
Adds the matrix given as parameter to this matrix, element by element.
Parameters:
matrix - the matrix to add
Since:
Cult3D 4.2

sub

public void sub(Matrix4x4 matrix)
Subtracts the matrix given as parameter from this matrix, element by element.
Parameters:
matrix - The matrix to subtract
Since:
Cult3D 4.2

mult

public void mult(float f)
Multiplies each element of this matrix with the value given as parameter.
Parameters:
f - The value to multiplie with
Since:
Cult3D 4.2

transpose

public void transpose()
Transposes this matrix.
Since:
Cult3D 4.2

identity

public void identity()
Sets this Matrix to the identity Matrix.
Since:
Cult3D 4.2

equals

public boolean equals(java.lang.Object obj)
Returns true if this matrix and the Object given as argument are equal. To be equal the given Object must be of the type Matrix4x4 and must have the same value of each element.
Overrides:
equals in class java.lang.Object
Returns:
true if the Object given as argument is equal to this Object.
Since:
Cult3D 4.2

getInfo

public java.lang.String getInfo()
This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.
Returns:
A string representing this object.
Since:
Cult3D 5.3

toString

public java.lang.String toString()

Returns a string representation of the values of this object.

The string contains the name of this class, and the values of the matrix.

This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.

Overrides:
toString in class java.lang.Object
Returns:
A string representing this object.