public class Matrix4
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
double[] |
m
The matrix's components, stored in row-major order.
|
Constructor and Description |
---|
Matrix4()
Constructs a 4 x 4 identity matrix.
|
Matrix4(double m11,
double m12,
double m13,
double m14,
double m21,
double m22,
double m23,
double m24,
double m31,
double m32,
double m33,
double m34,
double m41,
double m42,
double m43,
double m44)
Constructs a 4 x 4 matrix with specified components.
|
Matrix4(Matrix4 matrix)
Constructs a 4 x 4 matrix with the components of a specified matrix.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
boolean |
extractEigenvectors(Vec3 result1,
Vec3 result2,
Vec3 result3)
Returns this symmetric matrix's eigenvectors.
|
Vec3 |
extractEyePoint(Vec3 result)
Returns this viewing matrix's eye point.
|
Vec3 |
extractForwardVector(Vec3 result)
Returns this viewing matrix's forward vector.
|
int |
hashCode() |
Matrix4 |
invert()
Inverts this matrix in place.
|
Matrix4 |
invertMatrix(Matrix4 matrix)
Inverts the specified matrix and stores the result in this matrix.
|
Matrix4 |
invertOrthonormal()
Inverts this orthonormal transform matrix in place.
|
Matrix4 |
invertOrthonormalMatrix(Matrix4 matrix)
Inverts the specified orthonormal transform matrix and stores the result in 'this' matrix.
|
Matrix4 |
multiplyByMatrix(double m11,
double m12,
double m13,
double m14,
double m21,
double m22,
double m23,
double m24,
double m31,
double m32,
double m33,
double m34,
double m41,
double m42,
double m43,
double m44)
Multiplies this matrix by a matrix specified by individual components.
|
Matrix4 |
multiplyByMatrix(Matrix4 matrix)
Multiplies this matrix by a specified matrix.
|
Matrix4 |
multiplyByRotation(double x,
double y,
double z,
double angleDegrees)
Multiplies this matrix by a rotation matrix about a specified axis and angle.
|
Matrix4 |
multiplyByScale(double xScale,
double yScale,
double zScale)
Multiplies this matrix by a scale matrix with specified values.
|
Matrix4 |
multiplyByTranslation(double x,
double y,
double z)
Multiplies this matrix by a translation matrix with specified translation values.
|
Matrix4 |
offsetProjectionDepth(double depthOffset)
Applies a specified depth offset to this projection matrix.
|
boolean |
project(double x,
double y,
double z,
Viewport viewport,
Vec3 result)
Projects a Cartesian point to screen coordinates.
|
Matrix4 |
set(double m11,
double m12,
double m13,
double m14,
double m21,
double m22,
double m23,
double m24,
double m31,
double m32,
double m33,
double m34,
double m41,
double m42,
double m43,
double m44)
Sets this 4 x 4 matrix to specified components.
|
Matrix4 |
set(Matrix4 matrix)
Sets this 4 x 4 matrix to the components of a specified matrix.
|
Matrix4 |
setRotation(double x,
double y,
double z,
double angleDegrees)
Sets the rotation components of this matrix to a specified axis and angle.
|
Matrix4 |
setScale(double xScale,
double yScale,
double zScale)
Sets the scale components of this matrix to specified values.
|
Matrix4 |
setToCovarianceOfPoints(float[] array,
int count,
int stride)
Sets this matrix to the symmetric covariance Matrix computed from an array of points.
|
Matrix4 |
setToIdentity()
Sets this matrix to the 4 x 4 identity matrix.
|
Matrix4 |
setToInfiniteProjection(double viewportWidth,
double viewportHeight,
double fovyDegrees,
double nearDistance)
Sets this matrix to an infinite perspective projection matrix for the specified viewport dimensions, vertical
field of view and near clip distance.
|
Matrix4 |
setToMultiply(Matrix4 a,
Matrix4 b)
Sets this matrix to the matrix product of two specified matrices.
|
Matrix4 |
setToPerspectiveProjection(double viewportWidth,
double viewportHeight,
double fovyDegrees,
double nearDistance,
double farDistance)
Sets this matrix to a perspective projection matrix for the specified viewport dimensions, vertical field of view
and clip distances.
|
Matrix4 |
setToRotation(double x,
double y,
double z,
double angleDegrees)
Sets this matrix to a rotation matrix with a specified axis and angle.
|
Matrix4 |
setToScale(double xScale,
double yScale,
double zScale)
Sets this matrix to a scale matrix with specified scale components.
|
Matrix4 |
setToScreenProjection(double viewportWidth,
double viewportHeight)
Sets this matrix to a screen projection matrix for the specified viewport dimensions.
|
Matrix4 |
setToTranslation(double x,
double y,
double z)
Sets this matrix to a translation matrix with specified translation components.
|
Matrix4 |
setTranslation(double x,
double y,
double z)
Sets the translation components of this matrix to specified values.
|
java.lang.String |
toString() |
Matrix4 |
transpose()
Transposes this matrix in place.
|
Matrix4 |
transposeMatrix(Matrix4 matrix)
Sets this matrix to the transpose of a specified matrix.
|
float[] |
transposeToArray(float[] result,
int offset)
Transposes this matrix, storing the result in the specified single precision array.
|
boolean |
unProject(double x,
double y,
Viewport viewport,
Vec3 nearResult,
Vec3 farResult)
Un-projects a screen coordinate point to Cartesian coordinates at the near clip plane and the far clip plane.
|
public final double[] m
public Matrix4()
public Matrix4(double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44)
m11
- matrix element at row 1, column 1m12
- matrix element at row 1, column 2m13
- matrix element at row 1, column 3m14
- matrix element at row 1, column 4m21
- matrix element at row 2, column 1m22
- matrix element at row 2, column 2m23
- matrix element at row 2, column 3m24
- matrix element at row 2, column 4m31
- matrix element at row 3, column 1m32
- matrix element at row 3, column 2m33
- matrix element at row 3, column 3m34
- matrix element at row 3, column 4m41
- matrix element at row 4, column 1m42
- matrix element at row 4, column 2m43
- matrix element at row 4, column 3m44
- matrix element at row 4, column 4public Matrix4(Matrix4 matrix)
matrix
- the matrix specifying the new componentsjava.lang.IllegalArgumentException
- If the matrix is nullpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public Matrix4 set(double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44)
m11
- matrix element at row 1, column 1m12
- matrix element at row 1, column 2m13
- matrix element at row 1, column 3m14
- matrix element at row 1, column 4m21
- matrix element at row 2, column 1m22
- matrix element at row 2, column 2m23
- matrix element at row 2, column 3m24
- matrix element at row 2, column 4m31
- matrix element at row 3, column 1m32
- matrix element at row 3, column 2m33
- matrix element at row 3, column 3m34
- matrix element at row 3, column 4m41
- matrix element at row 4, column 1m42
- matrix element at row 4, column 2m43
- matrix element at row 4, column 3m44
- matrix element at row 4, column 4public Matrix4 set(Matrix4 matrix)
matrix
- the matrix specifying the new componentsjava.lang.IllegalArgumentException
- If the matrix is nullpublic Matrix4 setTranslation(double x, double y, double z)
x
- the X translation componenty
- the Y translation componentz
- the Z translation componentpublic Matrix4 setRotation(double x, double y, double z, double angleDegrees)
x
- the X component of the rotation axis unit vectory
- the Y component of the rotation axis unit vectorz
- the Z component of the rotation axis unit vectorangleDegrees
- the angle of rotation in degreespublic Matrix4 setScale(double xScale, double yScale, double zScale)
xScale
- the X scale componentyScale
- the Y scale componentzScale
- the Z scale componentpublic Matrix4 setToIdentity()
public Matrix4 setToTranslation(double x, double y, double z)
x
- the X translation componenty
- the Y translation componentz
- the Z translation componentpublic Matrix4 setToRotation(double x, double y, double z, double angleDegrees)
x
- the X component of the rotation axis unit vectory
- the Y component of the rotation axis unit vectorz
- the Z component of the rotation axis unit vectorangleDegrees
- the angle of rotation in degreespublic Matrix4 setToScale(double xScale, double yScale, double zScale)
xScale
- the X scale componentyScale
- the Y scale componentzScale
- the Z scale componentpublic Matrix4 setToMultiply(Matrix4 a, Matrix4 b)
a
- the first matrix multiplicandb
- The second matrix multiplicandjava.lang.IllegalArgumentException
- If either matrix is nullpublic Matrix4 setToInfiniteProjection(double viewportWidth, double viewportHeight, double fovyDegrees, double nearDistance)
viewportWidth
- the viewport width in screen coordinatesviewportHeight
- the viewport height in screen coordinatesfovyDegrees
- the vertical field of view in degreesnearDistance
- the near clip plane distance in model coordinatesjava.lang.IllegalArgumentException
- If either the width or the height is less than or equal to zero, if the field of
view is less than or equal to zero or greater than 180, if the near distance is
less than or equal to zeropublic Matrix4 setToPerspectiveProjection(double viewportWidth, double viewportHeight, double fovyDegrees, double nearDistance, double farDistance)
viewportWidth
- the viewport width in screen coordinatesviewportHeight
- the viewport height in screen coordinatesfovyDegrees
- the vertical field of view in degreesnearDistance
- the near clip plane distance in model coordinatesfarDistance
- the far clip plane distance in model coordinatesjava.lang.IllegalArgumentException
- If either the width or the height is less than or equal to zero, if the field of
view is less than or equal to zero or greater than 180, if the near and far
distances are equal, or if either the near or far distance are less than or
equal to zeropublic Matrix4 setToScreenProjection(double viewportWidth, double viewportHeight)
RenderContext.project
.viewportWidth
- the viewport width in screen coordinatesviewportHeight
- the viewport height in screen coordinatesjava.lang.IllegalArgumentException
- If either the width or the height is less than or equal to zeropublic Matrix4 setToCovarianceOfPoints(float[] array, int count, int stride)
C(x, x) C(x, y) C(x, z)
C(x, y) C(y, y) C(y, z)
C(x, z) C(y, z) C(z, z)
C(i, j) is the covariance of coordinates i and j, where i or j are a coordinate's dispersion about its mean
value. If any entry is zero, then there's no correlation between the two coordinates defining that entry. If the
returned matrix is diagonal, then all three coordinates are uncorrelated, and the specified point is distributed
evenly about its mean point.array
- the array of points to considercount
- the number of array elements to considerstride
- the number of coordinates between the first coordinate of adjacent points - must be at least 3java.lang.IllegalArgumentException
- If the array is null or empty, if the count is less than 0, or if the stride is
less than 3public Matrix4 multiplyByTranslation(double x, double y, double z)
x
- the X translation componenty
- the Y translation componentz
- the Z translation componentpublic Matrix4 multiplyByRotation(double x, double y, double z, double angleDegrees)
x
- the X component of the rotation axisy
- the Y component of the rotation axisz
- the Z component of the rotation axisangleDegrees
- the angle of rotation in degreespublic Matrix4 multiplyByScale(double xScale, double yScale, double zScale)
xScale
- the X scale componentyScale
- the Y scale componentzScale
- the Z scale componentpublic Matrix4 multiplyByMatrix(Matrix4 matrix)
matrix
- the matrix to multiply with this matrixjava.lang.IllegalArgumentException
- If the matrix is nullpublic Matrix4 multiplyByMatrix(double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44)
m11
- matrix element at row 1, column 1m12
- matrix element at row 1, column 2m13
- matrix element at row 1, column 3m14
- matrix element at row 1, column 4m21
- matrix element at row 2, column 1m22
- matrix element at row 2, column 2m23
- matrix element at row 2, column 3m24
- matrix element at row 2, column 4m31
- matrix element at row 3, column 1m32
- matrix element at row 3, column 2m33
- matrix element at row 3, column 3m34
- matrix element at row 3, column 4m41
- matrix element at row 4, column 1m42
- matrix element at row 4, column 2m43
- matrix element at row 4, column 3m44
- matrix element at row 4, column 4public Matrix4 transpose()
public Matrix4 transposeMatrix(Matrix4 matrix)
matrix
- the matrix whose transpose is to be computedjava.lang.IllegalArgumentException
- If the matrix in nullpublic float[] transposeToArray(float[] result, int offset)
result
- a pre-allocated array of length 16 in which to return the transposed componentspublic Matrix4 invert()
java.lang.IllegalArgumentException
- If this matrix cannot be invertedpublic Matrix4 invertMatrix(Matrix4 matrix)
matrix
- the matrix whose inverse is computedjava.lang.IllegalArgumentException
- If the matrix is null or cannot be invertedpublic Matrix4 invertOrthonormal()
public Matrix4 invertOrthonormalMatrix(Matrix4 matrix)
matrix
- the matrix whose inverse is computed. The matrix is assumed to represent an orthonormal transform
matrix.java.lang.IllegalArgumentException
- If the matrix is nullpublic Matrix4 offsetProjectionDepth(double depthOffset)
setToPerspectiveProjection
or setToScreenProjection
Depth offset may be applied to both perspective and screen projection matrices. The effect on each type is
outlined here:
Perspective Projection
The effect of depth offset on a perspective projection increases exponentially with distance from the eye. This
has the effect of adjusting the offset for the loss in depth precision with geometry drawn further from the eye.
Distant geometry requires a greater offset to differentiate itself from nearby geometry, while close geometry
does not.
Screen Projection
The effect of depth offset on an screen projection increases linearly with distance from the eye. While it is
reasonable to apply a depth offset to an screen projection, the effect is most appropriate when applied to the
projection used to draw the scene. For example, when an object's coordinates are projected by a perspective
projection into screen coordinates then drawn using a screen projection, it is best to apply the offset to the
original perspective projection. The method RenderContext.project
performs the correct behavior for
the projection type used to draw the scene.depthOffset
- the amount of offset to applypublic Vec3 extractEyePoint(Vec3 result)
result
- a pre-allocated Vec3
in which to return the extracted valuejava.lang.IllegalArgumentException
- If the result argument is nullpublic Vec3 extractForwardVector(Vec3 result)
result
- a pre-allocated Vec3
in which to return the extracted valuejava.lang.IllegalArgumentException
- If the result argument is nullpublic boolean extractEigenvectors(Vec3 result1, Vec3 result2, Vec3 result3)
result1
- a pre-allocated Vec3 in which to return the most prominent eigenvectorresult2
- a pre-allocated Vec3 in which to return the second most prominent eigenvectorresult3
- a pre-allocated Vec3 in which to return the least prominent eigenvectorjava.lang.IllegalArgumentException
- If any argument is null or if this matrix is not symmetricpublic boolean project(double x, double y, double z, Viewport viewport, Vec3 result)
x
- the Cartesian point's X componenty
- the Cartesian point's y componentz
- the Cartesian point's z componentviewport
- the viewport defining the screen point's coordinate systemresult
- a pre-allocated Vec3
in which to return the projected pointjava.lang.IllegalArgumentException
- If any argument is nullpublic boolean unProject(double x, double y, Viewport viewport, Vec3 nearResult, Vec3 farResult)
x
- the screen point's X componenty
- the screen point's Y componentviewport
- the viewport defining the screen point's coordinate systemnearResult
- a pre-allocated Vec3
in which to return the un-projected near clip plane pointfarResult
- a pre-allocated Vec3
in which to return the un-projected far clip plane pointjava.lang.IllegalArgumentException
- If any argument is null