Package org.sunflow.math
Class Matrix4
java.lang.Object
org.sunflow.math.Matrix4
This class is used to represent general affine transformations in 3D. The
bottom row of the matrix is assumed to be [0,0,0,1]. Note that the rotation
matrices assume a right-handed convention.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMatrix4(float[] m, boolean rowMajor) Initialize a matrix from the specified 16 element array.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) Creates a matrix with the specified elements -
Method Summary
Modifier and TypeMethodDescriptionfinal float[]final float[]static final Matrix4final floatCompute the matrix determinant.final booleanstatic final Matrix4fromBasis(OrthoNormalBasis basis) Creates a rotation matrix from an OrthonormalBasis.final Matrix4inverse()Compute the inverse of this matrix and return it as a new object.final booleanstatic final Matrix4Creates a camera positioning matrix from the given eye and target points and up vector.final Matrix4Computes this*m and return the result as a new Matrix4static final Matrix4rotate(float x, float y, float z, float theta) Creates a rotation matrix about the specified axis.static final Matrix4rotateX(float theta) Creates a rotation matrix about the X axis.static final Matrix4rotateY(float theta) Creates a rotation matrix about the Y axis.static final Matrix4rotateZ(float theta) Creates a rotation matrix about the Z axis.static final Matrix4scale(float s) Create a uniform scaling matrix.static final Matrix4scale(float sx, float sy, float sz) Creates a non-uniform scaling matrix.final BoundingBoxTransforms each corner of the specified axis-aligned bounding box and returns a new bounding box which incloses the transformed corners.final Point3transformP(Point3 p) Computes this*p and returns the result as a new Point3 object.final floattransformPX(float x, float y, float z) Computes the x component of this*(x,y,z,1).final floattransformPY(float x, float y, float z) Computes the y component of this*(x,y,z,1).final floattransformPZ(float x, float y, float z) Computes the z component of this*(x,y,z,1).final Vector3Computes (this^T)*v and returns the result as a new Vector3 object.final floattransformTransposeVX(float x, float y, float z) Computes the x component of (this^T)*(x,y,z,0).final floattransformTransposeVY(float x, float y, float z) Computes the y component of (this^T)*(x,y,z,0).final floattransformTransposeVZ(float x, float y, float z) Computes the z component of (this^T)*(x,y,z,0).final Vector3Computes this*v and returns the result as a new Vector3 object.final floattransformVX(float x, float y, float z) Computes the x component of this*(x,y,z,0).final floattransformVY(float x, float y, float z) Computes the y component of this*(x,y,z,0).final floattransformVZ(float x, float y, float z) Computes the z component of this*(x,y,z,0).static final Matrix4translation(float x, float y, float z) Create a translation matrix for the specified vector.
-
Field Details
-
ZERO
-
IDENTITY
-
-
Constructor Details
-
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) Creates a matrix with the specified elements- Parameters:
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 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.- Parameters:
m- a 16 element array in row or column major formrowMajor-trueif the array is in row major form,falseif it is in column major form
-
-
Method Details
-
isIndentity
public final boolean isIndentity() -
equals
-
asRowMajor
public final float[] asRowMajor() -
asColMajor
public final float[] asColMajor() -
determinant
public final float determinant()Compute the matrix determinant.- Returns:
- determinant of this matrix
-
inverse
Compute the inverse of this matrix and return it as a new object. If the matrix is not invertible,nullis returned.- Returns:
- the inverse of this matrix, or
nullif not invertible
-
multiply
Computes this*m and return the result as a new Matrix4- Parameters:
m- right hand side of the multiplication- Returns:
- a new Matrix4 object equal to
this*m
-
transform
Transforms each corner of the specified axis-aligned bounding box and returns a new bounding box which incloses the transformed corners.- Parameters:
b- original bounding box- Returns:
- a new BoundingBox object which encloses the transform version of b
-
transformV
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].- Parameters:
v- vector to multiply- Returns:
- a new Vector3 object equal to
this*v
-
transformTransposeV
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].- Parameters:
v- vector to multiply- Returns:
- a new Vector3 object equal to
(this^T)*v
-
transformP
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].- Parameters:
p- point to multiply- Returns:
- a new Point3 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- z coordinate transformation result
-
transformTransposeVX
public final float transformTransposeVX(float x, float y, float z) Computes the x component of (this^T)*(x,y,z,0).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- zcoordinate transformation result
-
transformPX
public final float transformPX(float x, float y, float z) Computes the x component of this*(x,y,z,1).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- 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).- Parameters:
x- x coordinate of the vector to multiplyy- y coordinate of the vector to multiplyz- z coordinate of the vector to multiply- Returns:
- z coordinate transformation result
-
translation
Create a translation matrix for the specified vector.- Parameters:
x- x component of translationy- y component of translationz- z component of translation- Returns:
- a new Matrix4 object representing the translation
-
rotateX
Creates a rotation matrix about the X axis.- Parameters:
theta- angle to rotate about the X axis in radians- Returns:
- a new Matrix4 object representing the rotation
-
rotateY
Creates a rotation matrix about the Y axis.- Parameters:
theta- angle to rotate about the Y axis in radians- Returns:
- a new Matrix4 object representing the rotation
-
rotateZ
Creates a rotation matrix about the Z axis.- Parameters:
theta- angle to rotate about the Z axis in radians- Returns:
- a new Matrix4 object representing the rotation
-
rotate
Creates a rotation matrix about the specified axis. The axis vector need not be normalized.- Parameters:
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- Returns:
- a new Matrix4 object representing the rotation
-
scale
Create a uniform scaling matrix.- Parameters:
s- scale factor for all three axes- Returns:
- a new Matrix4 object representing the uniform scale
-
scale
Creates a non-uniform scaling matrix.- Parameters:
sx- scale factor in the x dimensionsy- scale factor in the y dimensionsz- scale factor in the z dimension- Returns:
- a new Matrix4 object representing the non-uniform scale
-
fromBasis
Creates a rotation matrix from an OrthonormalBasis.- Parameters:
basis-
-
lookAt
Creates a camera positioning matrix from the given eye and target points and up vector.- Parameters:
eye- location of the eyetarget- location of the targetup- vector pointing upwards- Returns:
-
blend
-