Package com.badlogic.gdx.math
Class Matrix3
- java.lang.Object
-
- com.badlogic.gdx.math.Matrix3
-
- All Implemented Interfaces:
java.io.Serializable
public class Matrix3 extends java.lang.Object implements java.io.SerializableA 3x3 column major matrix; useful for 2D transforms.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatdet()floatgetRotation()floatgetRotationRad()Vector2getScale(Vector2 scale)Vector2getTranslation(Vector2 position)float[]getValues()Get the values in this matrix.Matrix3idt()Sets this matrix to the identity matrixMatrix3inv()Inverts this matrix given that the determinant is != 0.Matrix3mul(Matrix3 m)Postmultiplies this matrix with the provided matrix and stores the result in this matrix.Matrix3mulLeft(Matrix3 m)Premultiplies this matrix with the provided matrix and stores the result in this matrix.Matrix3rotate(float degrees)Postmultiplies this matrix with a (counter-clockwise) rotation matrix.Matrix3rotateRad(float radians)Postmultiplies this matrix with a (counter-clockwise) rotation matrix.Matrix3scale(float scaleX, float scaleY)Postmultiplies this matrix with a scale matrix.Matrix3scale(Vector2 scale)Postmultiplies this matrix with a scale matrix.Matrix3scl(float scale)Scale the matrix in the both the x and y components by the scalar value.Matrix3scl(Vector2 scale)Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.Matrix3scl(Vector3 scale)Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.Matrix3set(float[] values)Sets the matrix to the given matrix as a float array.Matrix3set(Affine2 affine)Copies the values from the provided affine matrix to this matrix.Matrix3set(Matrix3 mat)Copies the values from the provided matrix to this matrix.Matrix3set(Matrix4 mat)Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.Matrix3setToRotation(float degrees)Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.Matrix3setToRotation(Vector3 axis, float degrees)Matrix3setToRotation(Vector3 axis, float cos, float sin)Matrix3setToRotationRad(float radians)Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.Matrix3setToScaling(float scaleX, float scaleY)Sets this matrix to a scaling matrix.Matrix3setToScaling(Vector2 scale)Sets this matrix to a scaling matrix.Matrix3setToTranslation(float x, float y)Sets this matrix to a translation matrix.Matrix3setToTranslation(Vector2 translation)Sets this matrix to a translation matrix.java.lang.StringtoString()Matrix3translate(float x, float y)Postmultiplies this matrix by a translation matrix.Matrix3translate(Vector2 translation)Postmultiplies this matrix by a translation matrix.Matrix3transpose()Transposes the current matrix.Matrix3trn(float x, float y)Adds a translational component to the matrix in the 3rd column.Matrix3trn(Vector2 vector)Adds a translational component to the matrix in the 3rd column.Matrix3trn(Vector3 vector)Adds a translational component to the matrix in the 3rd column.
-
-
-
Field Detail
-
M00
public static final int M00
- See Also:
- Constant Field Values
-
M01
public static final int M01
- See Also:
- Constant Field Values
-
M02
public static final int M02
- See Also:
- Constant Field Values
-
M10
public static final int M10
- See Also:
- Constant Field Values
-
M11
public static final int M11
- See Also:
- Constant Field Values
-
M12
public static final int M12
- See Also:
- Constant Field Values
-
M20
public static final int M20
- See Also:
- Constant Field Values
-
M21
public static final int M21
- See Also:
- Constant Field Values
-
M22
public static final int M22
- See Also:
- Constant Field Values
-
val
public float[] val
-
-
Constructor Detail
-
Matrix3
public Matrix3()
-
Matrix3
public Matrix3(Matrix3 matrix)
-
Matrix3
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- The float array to copy. Remember that this matrix is in column major order. (The float array is not modified.)
-
-
Method Detail
-
idt
public Matrix3 idt()
Sets this matrix to the identity matrix- Returns:
- This matrix for the purpose of chaining operations.
-
mul
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- Matrix to multiply by.- Returns:
- This matrix for the purpose of chaining operations together.
-
mulLeft
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- The other Matrix to multiply by- Returns:
- This matrix for the purpose of chaining operations.
-
setToRotation
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- the angle in degrees.- Returns:
- This matrix for the purpose of chaining operations.
-
setToRotationRad
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- the angle in radians.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTranslation
public Matrix3 setToTranslation(float x, float y)
Sets this matrix to a translation matrix.- Parameters:
x- the translation in xy- the translation in y- Returns:
- This matrix for the purpose of chaining operations.
-
setToTranslation
public Matrix3 setToTranslation(Vector2 translation)
Sets this matrix to a translation matrix.- Parameters:
translation- The translation vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToScaling
public Matrix3 setToScaling(float scaleX, float scaleY)
Sets this matrix to a scaling matrix.- Parameters:
scaleX- the scale in xscaleY- the scale in y- Returns:
- This matrix for the purpose of chaining operations.
-
setToScaling
public Matrix3 setToScaling(Vector2 scale)
Sets this matrix to a scaling matrix.- Parameters:
scale- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
det
public float det()
- Returns:
- The determinant of this matrix
-
inv
public Matrix3 inv()
Inverts this matrix given that the determinant is != 0.- Returns:
- This matrix for the purpose of chaining operations.
- Throws:
GdxRuntimeException- if the matrix is singular (not invertible)
-
set
public Matrix3 set(Matrix3 mat)
Copies the values from the provided matrix to this matrix.- Parameters:
mat- The matrix to copy.- Returns:
- This matrix for the purposes of chaining.
-
set
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- The affine matrix to copy.- Returns:
- This matrix for the purposes of chaining.
-
set
public Matrix3 set(Matrix4 mat)
Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.- Parameters:
mat- The matrix whose top left corner will be copied. This matrix will not be modified.- Returns:
- This matrix for the purpose of chaining operations.
-
set
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- The matrix, in float form, that is to be copied. Remember that this matrix is in column major order.- Returns:
- This matrix for the purpose of chaining methods together.
-
trn
public Matrix3 trn(Vector2 vector)
Adds a translational component to the matrix in the 3rd column. The other columns are untouched.- Parameters:
vector- The translation vector.- Returns:
- This matrix for the purpose of chaining.
-
trn
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- The x-component of the translation vector.y- The y-component of the translation vector.- Returns:
- This matrix for the purpose of chaining.
-
trn
public Matrix3 trn(Vector3 vector)
Adds a translational component to the matrix in the 3rd column. The other columns are untouched.- Parameters:
vector- The translation vector. (The z-component of the vector is ignored because this is a 3x3 matrix)- Returns:
- This matrix for the purpose of chaining.
-
translate
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- The x-component of the translation vector.y- The y-component of the translation vector.- Returns:
- This matrix for the purpose of chaining.
-
translate
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- The translation vector.- Returns:
- This matrix for the purpose of chaining.
-
rotate
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- The angle in degrees- Returns:
- This matrix for the purpose of chaining.
-
rotateRad
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- The angle in radians- Returns:
- This matrix for the purpose of chaining.
-
scale
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- The scale in the x-axis.scaleY- The scale in the y-axis.- Returns:
- This matrix for the purpose of chaining.
-
scale
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- The vector to scale the matrix by.- Returns:
- This matrix for the purpose of chaining.
-
getValues
public float[] getValues()
Get the values in this matrix.- Returns:
- The float values that make up this matrix in column-major order.
-
getScale
public Vector2 getScale(Vector2 scale)
- Parameters:
scale- The vector which will receive the (non-negative) scale components on each axis.- Returns:
- The provided vector for chaining.
-
getRotation
public float getRotation()
-
getRotationRad
public float getRotationRad()
-
scl
public Matrix3 scl(float scale)
Scale the matrix in the both the x and y components by the scalar value.- Parameters:
scale- The single value that will be used to scale both the x and y components.- Returns:
- This matrix for the purpose of chaining methods together.
-
scl
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- TheVector3to use to scale this matrix.- Returns:
- This matrix for the purpose of chaining methods together.
-
scl
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- TheVector3to use to scale this matrix. The z component will be ignored.- Returns:
- This matrix for the purpose of chaining methods together.
-
transpose
public Matrix3 transpose()
Transposes the current matrix.- Returns:
- This matrix for the purpose of chaining methods together.
-
-