Package arc.math
Class Mat
java.lang.Object
arc.math.Mat
A 3x3 column major matrix; useful for 2D
transforms.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfloat
det()
float
float
getTranslation
(Vec2 position) float[]
Get the values in this matrix.idt()
Sets this matrix to the identity matrixinv()
Inverts this matrix given that the determinant is != 0.Postmultiplies this matrix with the provided matrix and stores the result in this matrix.Premultiplies this matrix with the provided matrix and stores the result in this matrix.rotate
(float degrees) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.rotateRad
(float radians) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.scale
(float scaleX, float scaleY) Postmultiplies this matrix with a scale matrix.Postmultiplies this matrix with a scale matrix.scl
(float scale) Scale the matrix in the both the x and y components by the scalar value.Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.set
(float[] values) Sets the matrix to the given matrix as a float array.Copies the values from the provided affine matrix to this matrix.Copies the values from the provided matrix to this matrix.setOrtho
(float x, float y, float width, float height) Sets this matrix to an orthographic projection.setToRotation
(float degrees) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToRotation
(Vec3 axis, float degrees) setToRotation
(Vec3 axis, float cos, float sin) setToRotationRad
(float radians) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToScaling
(float scaleX, float scaleY) Sets this matrix to a scaling matrix.setToScaling
(Vec2 scale) Sets this matrix to a scaling matrix.setToTranslation
(float x, float y) Sets this matrix to a translation matrix.setToTranslation
(Vec2 translation) Sets this matrix to a translation matrix.toString()
translate
(float x, float y) Postmultiplies this matrix by a translation matrix.Postmultiplies this matrix by a translation matrix.Transposes the current matrix.trn
(float x, float y) Adds a translational component to the matrix in the 3rd column.Adds a translational component to the matrix in the 3rd column.Adds a translational component to the matrix in the 3rd column.
-
Field Details
-
M00
public static final int M00- See Also:
-
M01
public static final int M01- See Also:
-
M02
public static final int M02- See Also:
-
M10
public static final int M10- See Also:
-
M11
public static final int M11- See Also:
-
M12
public static final int M12- See Also:
-
M20
public static final int M20- See Also:
-
M21
public static final int M21- See Also:
-
M22
public static final int M22- See Also:
-
val
public float[] val
-
-
Constructor Details
-
Mat
public Mat() -
Mat
-
Mat
public Mat(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 Details
-
setOrtho
Sets this matrix to an orthographic projection. -
idt
Sets this matrix to the identity matrix- Returns:
- This matrix for the purpose of chaining operations.
-
mul
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
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
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
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.
-
setToRotation
-
setToRotation
-
setToTranslation
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
Sets this matrix to a translation matrix.- Parameters:
translation
- The translation vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToScaling
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
Sets this matrix to a scaling matrix.- Parameters:
scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
toString
-
det
public float det()- Returns:
- The determinant of this matrix
-
inv
Inverts this matrix given that the determinant is != 0.- Returns:
- This matrix for the purpose of chaining operations.
- Throws:
ArcRuntimeException
- if the matrix is singular (not invertible)
-
set
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
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
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
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
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
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
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
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
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
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
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
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.
-
getTranslation
-
getScale
-
getRotation
public float getRotation() -
getRotationRad
public float getRotationRad() -
scl
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
Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.- Parameters:
scale
- TheVec3
to use to scale this matrix.- Returns:
- This matrix for the purpose of chaining methods together.
-
scl
Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.- Parameters:
scale
- TheVec3
to use to scale this matrix. The z component will be ignored.- Returns:
- This matrix for the purpose of chaining methods together.
-
transpose
Transposes the current matrix.- Returns:
- This matrix for the purpose of chaining methods together.
-