APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.math

public Class Matrix3

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, com.badlogic.gdx.utils.GdxRuntimeException

A 3x3 column major matrix; useful for 2D transforms.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private static final long
private float[]
public float[]

Constructor Summary

AccessConstructor and Description
public
public
Matrix3(Matrix3 matrix)

public
Matrix3(float[]
The float array to copy. Remember that this matrix is in column major order. (The float array is not modified.)
values
)

Constructs a matrix from the given float array.

Method Summary

Modifier and TypeMethod and Description
public float
det()

Returns: The determinant of this matrix

public float
public float
public Vector2
getScale(Vector2
The vector which will receive the (non-negative) scale components on each axis.
scale
)

Returns: The provided vector for chaining.

public Vector2
public float[]

Returns:

The float values that make up this matrix in column-major order.
getValues
()

Get the values in this matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
idt
()

Sets this matrix to the identity matrix

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
inv
()

Inverts this matrix given that the determinant is != 0.

public Matrix3

Returns:

This matrix for the purpose of chaining operations together.
mul
(Matrix3
Matrix to multiply by.
m
)

Postmultiplies this matrix with the provided matrix and stores the result in this matrix.

private static void
mul(float[]
The float array representing the first matrix. Must have at least 9 elements.
mata
,
float[]
The float array representing the second matrix. Must have at least 9 elements.
matb
)

Multiplies matrix a with matrix b in the following manner:

mul(A, B) => A := AB
public Matrix3

Returns:

This matrix for the purpose of chaining operations.
mulLeft
(Matrix3
The other Matrix to multiply by
m
)

Premultiplies this matrix with the provided matrix and stores the result in this matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
rotate
(float
The angle in degrees
degrees
)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
rotateRad
(float
The angle in radians
radians
)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
scale
(float
The scale in the x-axis.
scaleX
,
float
The scale in the y-axis.
scaleY
)

Postmultiplies this matrix with a scale matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
scale
(Vector2
The vector to scale the matrix by.
scale
)

Postmultiplies this matrix with a scale matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining methods together.
scl
(float
The single value that will be used to scale both the x and y components.
scale
)

Scale the matrix in the both the x and y components by the scalar value.

public Matrix3

Returns:

This matrix for the purpose of chaining methods together.
scl
(Vector2
The Vector3 to use to scale this matrix.
scale
)

Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.

public Matrix3

Returns:

This matrix for the purpose of chaining methods together.
scl
(Vector3
The Vector3 to use to scale this matrix. The z component will be ignored.
scale
)

Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.

public Matrix3

Returns:

This matrix for the purposes of chaining.
set
(Matrix3
The matrix to copy.
mat
)

Copies the values from the provided matrix to this matrix.

public Matrix3

Returns:

This matrix for the purposes of chaining.
set
(Affine2
The affine matrix to copy.
affine
)

Copies the values from the provided affine matrix to this matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
set
(Matrix4
The matrix whose top left corner will be copied. This matrix will not be modified.
mat
)

Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining methods together.
set
(float[]
The matrix, in float form, that is to be copied. Remember that this matrix is in column major order.
values
)

Sets the matrix to the given matrix as a float array.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToRotation
(float
the angle in degrees.
degrees
)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

public Matrix3
setToRotation(Vector3 axis, float degrees)

public Matrix3
setToRotation(Vector3 axis, float cos, float sin)

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToRotationRad
(float
the angle in radians.
radians
)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToScaling
(float
the scale in x
scaleX
,
float
the scale in y
scaleY
)

Sets this matrix to a scaling matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToScaling
(Vector2
The scale vector.
scale
)

Sets this matrix to a scaling matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToTranslation
(float
the translation in x
x
,
float
the translation in y
y
)

Sets this matrix to a translation matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining operations.
setToTranslation
(Vector2
The translation vector.
translation
)

Sets this matrix to a translation matrix.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Matrix3

Returns:

This matrix for the purpose of chaining.
translate
(float
The x-component of the translation vector.
x
,
float
The y-component of the translation vector.
y
)

Postmultiplies this matrix by a translation matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
translate
(Vector2
The translation vector.
translation
)

Postmultiplies this matrix by a translation matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining methods together.
transpose
()

Transposes the current matrix.

public Matrix3

Returns:

This matrix for the purpose of chaining.
trn
(Vector2
The translation vector.
vector
)

Adds a translational component to the matrix in the 3rd column.

public Matrix3

Returns:

This matrix for the purpose of chaining.
trn
(float
The x-component of the translation vector.
x
,
float
The y-component of the translation vector.
y
)

Adds a translational component to the matrix in the 3rd column.

public Matrix3

Returns:

This matrix for the purpose of chaining.
trn
(Vector3
The translation vector. (The z-component of the vector is ignored because this is a 3x3 matrix)
vector
)

Adds a translational component to the matrix in the 3rd column.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

M00back to summary
public static final int M00
M01back to summary
public static final int M01
M02back to summary
public static final int M02
M10back to summary
public static final int M10
M11back to summary
public static final int M11
M12back to summary
public static final int M12
M20back to summary
public static final int M20
M21back to summary
public static final int M21
M22back to summary
public static final int M22
serialVersionUIDback to summary
private static final long serialVersionUID
tmpback to summary
private float[] tmp
valback to summary
public float[] val

Constructor Detail

Matrix3back to summary
public Matrix3()
Matrix3back to summary
public Matrix3(Matrix3 matrix)
Matrix3back to summary
public Matrix3(float[] values)

Constructs a matrix from the given float array. The array must have at least 9 elements; the first 9 will be copied.

Parameters
values:float[]

The float array to copy. Remember that this matrix is in column major order. (The float array is not modified.)

Method Detail

detback to summary
public float det()
Returns:float

The determinant of this matrix

getRotationback to summary
public float getRotation()
getRotationRadback to summary
public float getRotationRad()
getScaleback to summary
public Vector2 getScale(Vector2 scale)
Parameters
scale:Vector2

The vector which will receive the (non-negative) scale components on each axis.

Returns:Vector2

The provided vector for chaining.

getTranslationback to summary
public Vector2 getTranslation(Vector2 position)
getValuesback to summary
public float[] getValues()

Get the values in this matrix.

Returns:float[]

The float values that make up this matrix in column-major order.

idtback to summary
public Matrix3 idt()

Sets this matrix to the identity matrix

Returns:Matrix3

This matrix for the purpose of chaining operations.

invback to summary
public Matrix3 inv()

Inverts this matrix given that the determinant is != 0.

Returns:Matrix3

This matrix for the purpose of chaining operations.

Exceptions
GdxRuntimeException:
if the matrix is singular (not invertible)
mulback to summary
public Matrix3 mul(Matrix3 m)

Postmultiplies this matrix with the provided matrix and stores the result in this matrix. For example:

A.mul(B) results in A := AB
Parameters
m:Matrix3

Matrix to multiply by.

Returns:Matrix3

This matrix for the purpose of chaining operations together.

mulback to summary
private static void mul(float[] mata, float[] matb)

Multiplies matrix a with matrix b in the following manner:

mul(A, B) => A := AB
Parameters
mata:float[]

The float array representing the first matrix. Must have at least 9 elements.

matb:float[]

The float array representing the second matrix. Must have at least 9 elements.

mulLeftback to summary
public Matrix3 mulLeft(Matrix3 m)

Premultiplies this matrix with the provided matrix and stores the result in this matrix. For example:

A.mulLeft(B) results in A := BA
Parameters
m:Matrix3

The other Matrix to multiply by

Returns:Matrix3

This matrix for the purpose of chaining operations.

rotateback to summary
public Matrix3 rotate(float degrees)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
degrees:float

The angle in degrees

Returns:Matrix3

This matrix for the purpose of chaining.

rotateRadback to summary
public Matrix3 rotateRad(float radians)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
radians:float

The angle in radians

Returns:Matrix3

This matrix for the purpose of chaining.

scaleback to summary
public Matrix3 scale(float scaleX, float scaleY)

Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
scaleX:float

The scale in the x-axis.

scaleY:float

The scale in the y-axis.

Returns:Matrix3

This matrix for the purpose of chaining.

scaleback to summary
public Matrix3 scale(Vector2 scale)

Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
scale:Vector2

The vector to scale the matrix by.

Returns:Matrix3

This matrix for the purpose of chaining.

sclback to summary
public Matrix3 scl(float scale)

Scale the matrix in the both the x and y components by the scalar value.

Parameters
scale:float

The single value that will be used to scale both the x and y components.

Returns:Matrix3

This matrix for the purpose of chaining methods together.

sclback to summary
public Matrix3 scl(Vector2 scale)

Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.

Parameters
scale:Vector2

The Vector3 to use to scale this matrix.

Returns:Matrix3

This matrix for the purpose of chaining methods together.

sclback to summary
public Matrix3 scl(Vector3 scale)

Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.

Parameters
scale:Vector3

The Vector3 to use to scale this matrix. The z component will be ignored.

Returns:Matrix3

This matrix for the purpose of chaining methods together.

setback to summary
public Matrix3 set(Matrix3 mat)

Copies the values from the provided matrix to this matrix.

Parameters
mat:Matrix3

The matrix to copy.

Returns:Matrix3

This matrix for the purposes of chaining.

setback to summary
public Matrix3 set(Affine2 affine)

Copies the values from the provided affine matrix to this matrix. The last row is set to (0, 0, 1).

Parameters
affine:Affine2

The affine matrix to copy.

Returns:Matrix3

This matrix for the purposes of chaining.

setback to summary
public Matrix3 set(Matrix4 mat)

Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.

Parameters
mat:Matrix4

The matrix whose top left corner will be copied. This matrix will not be modified.

Returns:Matrix3

This matrix for the purpose of chaining operations.

setback to summary
public Matrix3 set(float[] values)

Sets the matrix to the given matrix as a float array. The float array must have at least 9 elements; the first 9 will be copied.

Parameters
values:float[]

The matrix, in float form, that is to be copied. Remember that this matrix is in column major order.

Returns:Matrix3

This matrix for the purpose of chaining methods together.

setToRotationback to summary
public Matrix3 setToRotation(float degrees)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

Parameters
degrees:float

the angle in degrees.

Returns:Matrix3

This matrix for the purpose of chaining operations.

setToRotationback to summary
public Matrix3 setToRotation(Vector3 axis, float degrees)
setToRotationback to summary
public Matrix3 setToRotation(Vector3 axis, float cos, float sin)
setToRotationRadback to summary
public Matrix3 setToRotationRad(float radians)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

Parameters
radians:float

the angle in radians.

Returns:Matrix3

This matrix for the purpose of chaining operations.

setToScalingback to summary
public Matrix3 setToScaling(float scaleX, float scaleY)

Sets this matrix to a scaling matrix.

Parameters
scaleX:float

the scale in x

scaleY:float

the scale in y

Returns:Matrix3

This matrix for the purpose of chaining operations.

setToScalingback to summary
public Matrix3 setToScaling(Vector2 scale)

Sets this matrix to a scaling matrix.

Parameters
scale:Vector2

The scale vector.

Returns:Matrix3

This matrix for the purpose of chaining operations.

setToTranslationback to summary
public Matrix3 setToTranslation(float x, float y)

Sets this matrix to a translation matrix.

Parameters
x:float

the translation in x

y:float

the translation in y

Returns:Matrix3

This matrix for the purpose of chaining operations.

setToTranslationback to summary
public Matrix3 setToTranslation(Vector2 translation)

Sets this matrix to a translation matrix.

Parameters
translation:Vector2

The translation vector.

Returns:Matrix3

This matrix for the purpose of chaining operations.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

translateback to summary
public Matrix3 translate(float x, float y)

Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
x:float

The x-component of the translation vector.

y:float

The y-component of the translation vector.

Returns:Matrix3

This matrix for the purpose of chaining.

translateback to summary
public Matrix3 translate(Vector2 translation)

Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.

Parameters
translation:Vector2

The translation vector.

Returns:Matrix3

This matrix for the purpose of chaining.

transposeback to summary
public Matrix3 transpose()

Transposes the current matrix.

Returns:Matrix3

This matrix for the purpose of chaining methods together.

trnback to summary
public Matrix3 trn(Vector2 vector)

Adds a translational component to the matrix in the 3rd column. The other columns are untouched.

Parameters
vector:Vector2

The translation vector.

Returns:Matrix3

This matrix for the purpose of chaining.

trnback to summary
public Matrix3 trn(float x, float y)

Adds a translational component to the matrix in the 3rd column. The other columns are untouched.

Parameters
x:float

The x-component of the translation vector.

y:float

The y-component of the translation vector.

Returns:Matrix3

This matrix for the purpose of chaining.

trnback to summary
public Matrix3 trn(Vector3 vector)

Adds a translational component to the matrix in the 3rd column. The other columns are untouched.

Parameters
vector:Vector3

The translation vector. (The z-component of the vector is ignored because this is a 3x3 matrix)

Returns:Matrix3

This matrix for the purpose of chaining.