This class is used to represent general geometric transformations in 3D. Note
that the rotation matrices assume a right-handed convention.
Matrix4
public Matrix4()
Creates an empty matrix. All elements are 0.
Matrix4
public Matrix4(float m00,
float m01,
float m02,
float m03,
float m10,
float m11,
float m12,
float m13,
float m20,
float m21,
float m22,
float m23,
float m30,
float m31,
float m32,
float m33)
Creates a matrix with the specified elements
m00
- value at row 0, col 0m01
- value at row 0, col 1m02
- value at row 0, col 2m03
- value at row 0, col 3m10
- value at row 1, col 0m11
- value at row 1, col 1m12
- value at row 1, col 2m13
- value at row 1, col 3m20
- value at row 2, col 0m21
- value at row 2, col 1m22
- value at row 2, col 2m23
- value at row 2, col 3m30
- value at row 3, col 0m31
- value at row 3, col 1m32
- value at row 3, col 2m33
- value at row 3, col 3
Matrix4
public Matrix4(float[] m,
boolean rowMajor)
Initialize a matrix from the specified 16 element array. The matrix may
be given in row or column major form.
m
- a 16 element array in row or column major formrowMajor
- true
if the array is in row major form,
false
if it is in column major form
asColMajor
public final float[] asColMajor()
asRowMajor
public final float[] asRowMajor()
determinant
public final float determinant()
Compute the matrix determinant.
- determinant of this matrix
fromBasis
public static final Matrix4 fromBasis(OrthoNormalBasis basis)
Creates a rotation matrix from an OrthonormalBasis.
inverse
public final Matrix4 inverse()
Compute the inverse of this matrix and return it as a new object. If the
matrix is not invertible, null
is returned.
- the inverse of this matrix, or
null
if not
invertible
multiply
public final Matrix4 multiply(Matrix4 m)
Computes this*m and return the result as a new Matrix4
m
- right hand side of the multiplication
- a new Matrix4 object equal to
this*m
rotate
public static final Matrix4 rotate(float x,
float y,
float z,
float theta)
Creates a rotation matrix about the specified axis. The axis vector need
not be normalized.
x
- x component of the axis vectory
- y component of the axis vectorz
- z component of the axis vectortheta
- angle to rotate about the axis in radians
- a new Matrix4 object representing the rotation
rotateX
public static final Matrix4 rotateX(float theta)
Creates a rotation matrix about the X axis.
theta
- angle to rotate about the X axis in radians
- a new Matrix4 object representing the rotation
rotateY
public static final Matrix4 rotateY(float theta)
Creates a rotation matrix about the Y axis.
theta
- angle to rotate about the Y axis in radians
- a new Matrix4 object representing the rotation
rotateZ
public static final Matrix4 rotateZ(float theta)
Creates a rotation matrix about the Z axis.
theta
- angle to rotate about the Z axis in radians
- a new Matrix4 object representing the rotation
scale
public static final Matrix4 scale(float s)
Create a uniform scaling matrix.
s
- scale factor for all three axes
- a new Matrix4 object representing the uniform scale
scale
public static final Matrix4 scale(float sx,
float sy,
float sz)
Creates a non-uniform scaling matrix.
sx
- scale factor in the x dimensionsy
- scale factor in the y dimensionsz
- scale factor in the z dimension
- a new Matrix4 object representing the non-uniform scale
transform
public final BoundingBox transform(BoundingBox b)
Transforms each corner of the specified axis-aligned bounding box and
returns a new bounding box which incloses the transformed corners.
b
- original bounding box
- a new BoundingBox object which encloses the transform version of
b
transformP
public final Point3 transformP(Point3 p)
Computes this*p and returns the result as a new Point3 object. This
method assumes the bottom row of the matrix is [0,0,0,1]
.
- a new Point3 object equal to
this*v
transformPX
public final float transformPX(float x,
float y,
float z)
Computes the x component of this*(x,y,z,1).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- x coordinate transformation result
transformPY
public final float transformPY(float x,
float y,
float z)
Computes the y component of this*(x,y,z,1).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- y coordinate transformation result
transformPZ
public final float transformPZ(float x,
float y,
float z)
Computes the z component of this*(x,y,z,1).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- z coordinate transformation result
transformTransposeV
public final Vector3 transformTransposeV(Vector3 v)
Computes (this^T)*v and returns the result as a new Vector3 object. This
method assumes the bottom row of the matrix is [0,0,0,1]
.
- a new Vector3 object equal to
(this^T)*v
transformTransposeVX
public final float transformTransposeVX(float x,
float y,
float z)
Computes the x component of (this^T)*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- x coordinate transformation result
transformTransposeVY
public final float transformTransposeVY(float x,
float y,
float z)
Computes the y component of (this^T)*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- y coordinate transformation result
transformTransposeVZ
public final float transformTransposeVZ(float x,
float y,
float z)
Computes the z component of (this^T)*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- zcoordinate transformation result
transformV
public final Vector3 transformV(Vector3 v)
Computes this*v and returns the result as a new Vector3 object. This
method assumes the bottom row of the matrix is [0,0,0,1]
.
- a new Vector3 object equal to
this*v
transformVX
public final float transformVX(float x,
float y,
float z)
Computes the x component of this*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- x coordinate transformation result
transformVY
public final float transformVY(float x,
float y,
float z)
Computes the y component of this*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- y coordinate transformation result
transformVZ
public final float transformVZ(float x,
float y,
float z)
Computes the z component of this*(x,y,z,0).
x
- x coordinate of the vector to multiplyy
- y coordinate of the vector to multiplyz
- z coordinate of the vector to multiply
- z coordinate transformation result
translation
public static final Matrix4 translation(float x,
float y,
float z)
Create a translation matrix for the specified vector.
x
- x component of translationy
- y component of translationz
- z component of translation
- a new Matrix4 object representing the translation