public final class Matrix4 extends java.lang.Object implements Struct<Matrix4>, java.io.Serializable
Matrix4 mat = Matrix4.rotateFromEuler(90, 0, 0);
Matrix4 mat2 = Matrix4.translate(0, 10, -50);
Matrix4 transform = Matrix4.mul(mat2, mat);
Vector4 pos = new Vector4(10, 9, 0, 1);
Vector4 transformed = Matrix4.mul(transform, pos);
| Modifier and Type | Field and Description |
|---|---|
double |
m00
The m00.
|
double |
m01
The m01.
|
double |
m02
The m02.
|
double |
m03
The m03.
|
double |
m10
The m10.
|
double |
m11
The m11.
|
double |
m12
The m12.
|
double |
m13
The m13.
|
double |
m20
The m20.
|
double |
m21
The m21.
|
double |
m22
The m22.
|
double |
m23
The m23.
|
double |
m30
The m30.
|
double |
m31
The m31.
|
double |
m32
The m32.
|
double |
m33
The m33.
|
| Constructor and Description |
|---|
Matrix4() |
Matrix4(double[] m)
Initializes a new instance of the
Matrix4 struct. |
Matrix4(double m00,
double m01,
double m02,
double m03,
double m10,
double m11,
double m12,
double m13,
double m20,
double m21,
double m22,
double m23,
double m30,
double m31,
double m32,
double m33)
Initializes a new instance of the
Matrix4 struct. |
Matrix4(FMatrix4 m)
|
Matrix4(Vector4 r0,
Vector4 r1,
Vector4 r2,
Vector4 r3)
Constructs matrix from 4 rows.
|
| Modifier and Type | Method and Description |
|---|---|
Matrix4 |
clone()
Clone current instance
|
Matrix4 |
concatenate(Matrix4 m2)
Concatenates the two matrices
|
void |
copyFrom(Matrix4 src)
Copy internal state from argument t
|
boolean |
decompose(Vector3 translation,
Vector3 scaling,
Quaternion rotation)
Decompose the transformation matrix.
|
boolean |
equals(java.lang.Object obj) |
double |
getDeterminant()
Gets the determinant of the matrix.
|
static Matrix4 |
getIdentity()
Gets the identity matrix.
|
int |
hashCode() |
Matrix4 |
inverse()
Inverses this instance.
|
static Matrix4 |
mul(Matrix4 lhs,
double v)
Multiply the matrix and double value
|
static Matrix4 |
mul(Matrix4 lhs,
Matrix4 rhs)
Multiply the two matrices
|
static Vector3 |
mul(Matrix4 lhs,
Vector3 v)
Multiply the matrix and vector3
|
static Vector4 |
mul(Matrix4 lhs,
Vector4 v)
Multiply the matrix and vector4
|
Matrix4 |
normalize()
Normalizes this instance.
|
static Matrix4 |
rotate(double angle,
Vector3 axis)
Create a rotation matrix by rotation angle and axis
|
static Matrix4 |
rotate(Quaternion q)
Create a rotation matrix from a quaternion
|
static Matrix4 |
rotateFromEuler(double rx,
double ry,
double rz)
Create a rotation matrix from Euler angle
|
static Matrix4 |
rotateFromEuler(Vector3 eul)
Create a rotation matrix from Euler angle
|
static Matrix4 |
scale(double s)
Creates a matrix that scales along the x-axis, the y-axis and the z-axis.
|
static Matrix4 |
scale(double sx,
double sy,
double sz)
Creates a matrix that scales along the x-axis, the y-axis and the z-axis.
|
static Matrix4 |
scale(Vector3 s)
Creates a matrix that scales along the x-axis, the y-axis and the z-axis.
|
void |
setTRS(Vector3 translation,
Vector3 rotation,
Vector3 scale)
Initializes the matrix with translation/rotation/scale
|
double[] |
toArray()
Converts matrix to array.
|
java.lang.String |
toString()
Returns a
String that represents the current Matrix4. |
static Matrix4 |
translate(double tx,
double ty,
double tz)
Creates a matrix that translates along the x-axis, the y-axis and the z-axis
|
static Matrix4 |
translate(Vector3 t)
Creates a matrix that translates along the x-axis, the y-axis and the z-axis
|
Matrix4 |
transpose()
Transposes this instance.
|
public double m00
public double m01
public double m02
public double m03
public double m10
public double m11
public double m12
public double m13
public double m20
public double m21
public double m22
public double m23
public double m30
public double m31
public double m32
public double m33
public Matrix4(Vector4 r0, Vector4 r1, Vector4 r2, Vector4 r3)
r0 - R0.r1 - R1.r2 - R2.r3 - R3.public Matrix4(double m00,
double m01,
double m02,
double m03,
double m10,
double m11,
double m12,
double m13,
double m20,
double m21,
double m22,
double m23,
double m30,
double m31,
double m32,
double m33)
Matrix4 struct.m00 - M00.m01 - M01.m02 - M02.m03 - M03.m10 - M10.m11 - M11.m12 - M12.m13 - M13.m20 - M20.m21 - M21.m22 - M22.m23 - M23.m30 - M30.m31 - M31.m32 - M32.m33 - M33.
Example:
var mat = new Matrix4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
10, 20, 0, 1);
var pos = new Vector3(10, 0, -1);
var transformed = Matrix4.mul(mat, pos);
public Matrix4(FMatrix4 m)
public Matrix4(double[] m)
Matrix4 struct.m - M.public Matrix4()
public static Matrix4 getIdentity()
public Matrix4 concatenate(Matrix4 m2)
m2 - M2.
Matrix4 t = Matrix4.translate(0, 10, 9);
Matrix4 s = Matrix4.scale(10, 10, 10);
Matrix4 transform = t.concatenate(s);
Vector3 pos = new Vector3(10, 0, -1);
Vector3 transformed = Matrix4.mul(transform, pos);
public Matrix4 transpose()
Matrix4 t = Matrix4.translate(0, 10, 9);
Matrix4 mat = t.transpose();
System.out.printf("Transposed Matrix: %s", mat);
public Matrix4 normalize()
public Matrix4 inverse()
Matrix4 t = Matrix4.translate(0, 10, 9);
Matrix4 mat = t.inverse();
System.out.printf("Inversed Matrix: %s", mat);
public double getDeterminant()
public static Matrix4 mul(Matrix4 lhs, Matrix4 rhs)
lhs - Lhs.rhs - Rhs.public static Vector3 mul(Matrix4 lhs, Vector3 v)
lhs - Lhs.v - V.public void setTRS(Vector3 translation, Vector3 rotation, Vector3 scale)
translation - Translation.rotation - Euler angles for rotation, fields are in degree.scale - Scale.public static Vector4 mul(Matrix4 lhs, Vector4 v)
lhs - Lhs.v - V.public static Matrix4 mul(Matrix4 lhs, double v)
lhs - Lhs.v - V.public double[] toArray()
public boolean decompose(Vector3 translation, Vector3 scaling, Quaternion rotation)
translation - The translation.scaling - The scaling.rotation - The rotation.public java.lang.String toString()
String that represents the current Matrix4.toString in class java.lang.ObjectString that represents the current Matrix4.public static Matrix4 translate(Vector3 t)
t - Translate offset
Example:
The following code shows how to create a matrix for translate operation.
Matrix4 t = Matrix4.translate(new Vector3(10, 0, 0));
Vector3 pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 translate(double tx, double ty, double tz)
tx - X-coordinate offsetty - Y-coordinate offsettz - Z-coordinate offset
Example:
The following code shows how to create a matrix for translate operation.
var t = Matrix4.translate(10, 0, 0);
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 scale(Vector3 s)
s - Scaling factories applies to the x-axis, the y-axis and the z-axis
Example:
The following code shows how to create a matrix for scale operation.
var t = Matrix4.scale(new Vector3(10, 10, 10));
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 scale(double s)
s - Scaling factories applies to all axex
Example:
The following code shows how to create a matrix for scale operation.
var t = Matrix4.scale(10);
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 scale(double sx, double sy, double sz)
sx - Scaling factories applies to the x-axissy - Scaling factories applies to the y-axissz - Scaling factories applies to the z-axis
Example:
The following code shows how to create a matrix for scale operation.
var t = Matrix4.scale(10, 20, 10);
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 rotateFromEuler(Vector3 eul)
eul - Rotation in radian
Example:
The following code shows how to create a matrix for rotate operation.
var t = Matrix4.rotateFromEuler(new Vector3(0, Math.PI, 0));
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 rotateFromEuler(double rx, double ry, double rz)
rx - Rotation in x axis in radianry - Rotation in y axis in radianrz - Rotation in z axis in radian
Example:
The following code shows how to create a matrix for rotate operation.
var t = Matrix4.rotateFromEuler(0, Math.PI, 0);
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 rotate(double angle, Vector3 axis)
angle - Rotate angle in radianaxis - Rotation axis
Example:
The following code shows how to create a matrix for rotate operation.
var t = Matrix4.rotate(Math.PI, new Vector3(0, 1, 0));
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public static Matrix4 rotate(Quaternion q)
q - Rotation quaternion
Example:
The following code shows how to create a matrix for rotate operation.
var t = Matrix4.rotate(Quaternion.fromAngleAxis(Math.PI, Vector3.getUnitY()));
var pos = new Vector3(1, 1, 10);
System.out.printf("Transformed: %s", Matrix4.mul(t, pos));
public void copyFrom(Matrix4 src)
Structpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object