Package gaiasky.util.math
Class Matrix3d
java.lang.Object
gaiasky.util.math.Matrix3d
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
det()
double
double
getTranslation
(Vector2d position) double[]
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
(double degrees) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.rotateRad
(double radians) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.scale
(double scaleX, double scaleY) Postmultiplies this matrix with a scale matrix.scale
(com.badlogic.gdx.math.Vector2 scale) Postmultiplies this matrix with a scale matrix.scl
(double scale) Scale the matrix in the both the x and y components by the scalar value.scl
(com.badlogic.gdx.math.Vector2 scale) Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.scl
(com.badlogic.gdx.math.Vector3 scale) Scale this matrix using the x and y components of the vector but leave the rest of the matrix alone.set
(double[] values) Sets the matrix to the given matrix as a double array.set
(com.badlogic.gdx.math.Affine2 affine) Copies the values from the provided affine matrix to this matrix.set
(com.badlogic.gdx.math.Matrix4 mat) Sets this 3x3 matrix to the top left 3x3 corner of the provided 4x4 matrix.Copies the values from the provided matrix to this matrix.setToRotation
(double degrees) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToRotation
(Vector3d axis, double degrees) setToRotation
(Vector3d axis, double cos, double sin) setToRotationRad
(double radians) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToScaling
(double scaleX, double scaleY) Sets this matrix to a scaling matrix.setToScaling
(com.badlogic.gdx.math.Vector2 scale) Sets this matrix to a scaling matrix.setToTranslation
(double x, double y) Sets this matrix to a translation matrix.setToTranslation
(com.badlogic.gdx.math.Vector2 translation) Sets this matrix to a translation matrix.toString()
translate
(double x, double y) Postmultiplies this matrix by a translation matrix.translate
(com.badlogic.gdx.math.Vector2 translation) Postmultiplies this matrix by a translation matrix.Transposes the current matrix.trn
(double x, double y) Adds a translational component to the matrix in the 3rd column.trn
(com.badlogic.gdx.math.Vector2 vector) Adds a translational component to the matrix in the 3rd column.trn
(com.badlogic.gdx.math.Vector3 vector) 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 double[] val
-
-
Constructor Details
-
Matrix3d
public Matrix3d() -
Matrix3d
-
Matrix3d
public Matrix3d(double[] values) Constructs a matrix from the given double array. The array must have at least 9 elements; the first 9 will be copied.- Parameters:
values
- The double array to copy. Remember that this matrix is in column major order. (The double array is not modified.)
-
-
Method Details
-
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 double 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:
com.badlogic.gdx.utils.GdxRuntimeException
- 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 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
Sets the matrix to the given matrix as a double array. The double array must have at least 9 elements; the first 9 will be copied.- Parameters:
values
- The matrix, in double 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 double[] getValues()Get the values in this matrix.- Returns:
- The double values that make up this matrix in column-major order.
-
getTranslation
-
getScale
- Parameters:
scale
- The vector which will receive the (non-negative) scale components on each axis.- Returns:
- The provided vector for chaining.
-
getRotation
public double getRotation() -
getRotationRad
public double 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
- TheVector3
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
- TheVector3
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.
-