Class Matrix4f
- java.lang.Object
-
- com.jogamp.opengl.math.Matrix4f
-
public class Matrix4f extends Object
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).Implementation covers
FloatUtil
matrix functionality, exposed in an object oriented manner.Unlike
PMVMatrix
, this class only represents one single matrix without a completeGLMatrixFunc
implementation.For array operations the layout is expected in column-major order matching OpenGL's implementation, illustration:
Row-Major Column-Major (OpenGL): | 0 1 2 tx | | | | 4 5 6 ty | M = | | | 8 9 10 tz | | | | 12 13 14 15 | R C R C m[0*4+3] = tx; m[0+4*3] = tx; m[1*4+3] = ty; m[1+4*3] = ty; m[2*4+3] = tz; m[2+4*3] = tz; RC (std subscript order) RC (std subscript order) m03 = tx; m03 = tx; m13 = ty; m13 = ty; m23 = tz; m23 = tz;
Implementation utilizes unrolling of small vertices and matrices wherever possible while trying to access memory in a linear fashion for performance reasons, see:
-
-
Constructor Summary
Constructors Constructor Description Matrix4f()
Creates a new identity matrix.Matrix4f(float[] m)
Creates a new matrix based on given float[4*4] column major order.Matrix4f(float[] m, int m_off)
Creates a new matrix based on given float[4*4] column major order.Matrix4f(Matrix4f src)
Creates a new matrix copying the values of the givensrc
matrix.Matrix4f(FloatBuffer m)
Creates a new matrix based on givenFloatBuffer
4x4 column major order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description float
determinant()
Returns the determinant of this matrixboolean
equals(Object o)
float[]
get(float[] dst)
Get this matrix into the given float[16] array in column major order.float[]
get(float[] dst, int dst_off)
Get this matrix into the given float[16] array atdst_off
in column major order.float
get(int i)
Gets thei
th component, 0 <= i < 16FloatBuffer
get(FloatBuffer dst)
Get this matrix into the givenFloatBuffer
in column major order.Vec3f
getColumn(int column, Vec3f v_out)
Get the named column of the given column-major matrix to v_out.Vec4f
getColumn(int column, Vec4f v_out)
Get the named column of the given column-major matrix to v_out.Quaternion
getRotation(Quaternion res)
Returns the rotation [m00 ..Vec3f
getRow(int row, Vec3f v_out)
Get the named row of the given column-major matrix to v_out.Vec4f
getRow(int row, Vec4f v_out)
Get the named row of the given column-major matrix to v_out.boolean
invert()
Invert this matrix.boolean
invert(Matrix4f src)
Invert thesrc
matrix values into this matrixboolean
isEqual(Matrix4f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isEqual(Matrix4f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Matrix4f
load(float[] src)
Load the values of the given matrixsrc
to this matrix.Matrix4f
load(float[] src, int src_off)
Load the values of the given matrixsrc
to this matrix.Matrix4f
load(Matrix4f src)
Load the values of the given matrixb
to this matrix.Matrix4f
load(FloatBuffer src)
Load the values of the given matrixsrc
to this matrix.Matrix4f
loadIdentity()
Set this matrix to identity.static boolean
mapObjToWin(Vec3f obj, Matrix4f mMv, Matrix4f mP, Recti viewport, Vec3f winPos)
Map object coordinates to window coordinates.static boolean
mapObjToWin(Vec3f obj, Matrix4f mPMv, Recti viewport, Vec3f winPos)
Map object coordinates to window coordinates.static boolean
mapWinToObj(float winx, float winy, float winz1, float winz2, Matrix4f invPMv, Recti viewport, Vec3f objPos1, Vec3f objPos2)
Map two window coordinates to two object coordinates, distinguished by their z component.static boolean
mapWinToObj(float winx, float winy, float winz, Matrix4f mMv, Matrix4f mP, Recti viewport, Vec3f objPos, Matrix4f mat4Tmp)
Map window coordinates to object coordinates.static boolean
mapWinToObj(float winx, float winy, float winz, Matrix4f invPMv, Recti viewport, Vec3f objPos)
Map window coordinates to object coordinates.static boolean
mapWinToObj4(float winx, float winy, float winz, float clipw, Matrix4f mMv, Matrix4f mP, Recti viewport, float near, float far, Vec4f objPos, Matrix4f mat4Tmp)
Map window coordinates to object coordinates.static boolean
mapWinToObj4(float winx, float winy, float winz, float clipw, Matrix4f invPMv, Recti viewport, float near, float far, Vec4f objPos)
Map window coordinates to object coordinates.static boolean
mapWinToRay(float winx, float winy, float winz0, float winz1, Matrix4f mMv, Matrix4f mP, Recti viewport, Ray ray, Matrix4f mat4Tmp1, Matrix4f mat4Tmp2)
Map two window coordinates w/ shared X/Y and distinctive Z to aRay
.static boolean
mapWinToRay(float winx, float winy, float winz0, float winz1, Matrix4f invPMv, Recti viewport, Ray ray)
Map two window coordinates w/ shared X/Y and distinctive Z to aRay
.Matrix4f
mul(Matrix4f b)
Multiply matrix: [this] = [this] x [b]Matrix4f
mul(Matrix4f a, Matrix4f b)
Multiply matrix: [this] = [a] x [b]Vec3f
mulVec3f(Vec3f v_inout)
Affine 3f-vector transformation by 4x4 matrix 4x4 matrix multiplication with 3-component vector, using1
for forv_inout.w()
and droppingv_inout.w()
, which shall be1
.Vec3f
mulVec3f(Vec3f v_in, Vec3f v_out)
Affine 3f-vector transformation by 4x4 matrix 4x4 matrix multiplication with 3-component vector, using1
for forv_in.w()
and droppingv_out.w()
, which shall be1
.Vec4f
mulVec4f(Vec4f v_inout)
Vec4f
mulVec4f(Vec4f v_in, Vec4f v_out)
void
pop()
Pop the current matrix from it's stack, replacing this matrix values.void
push()
Push the matrix to it's stack, while preserving this matrix values.Matrix4f
rotate(float ang_rad, float x, float y, float z, Matrix4f tmp)
Rotate this matrix about give axis and angle in radians, i.e.Matrix4f
rotate(float ang_rad, Vec3f axis, Matrix4f tmp)
Rotate this matrix about give axis and angle in radians, i.e.Matrix4f
rotate(Quaternion quat, Matrix4f tmp)
Rotate this matrix with the givenQuaternion
, i.e.Matrix4f
scale(float x, float y, float z, Matrix4f tmp)
Scale this matrix, i.e.Matrix4f
scale(float s, Matrix4f tmp)
Scale this matrix, i.e.void
set(int i, float v)
Sets thei
th component with floatv
0 <= i < 16Matrix4f
setToFrustum(float left, float right, float bottom, float top, float zNear, float zFar)
Set this matrix to frustum.Matrix4f
setToLookAt(Vec3f eye, Vec3f center, Vec3f up, Matrix4f tmp)
Set this matrix to the look-at matrix based on given parameters.Matrix4f
setToOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
Set this matrix to orthogonal projection.Matrix4f
setToPerspective(float fovy_rad, float aspect, float zNear, float zFar)
Set this matrix to perspectivefrustum
projection.Matrix4f
setToPerspective(FovHVHalves fovhv, float zNear, float zFar)
Set this matrix to perspectivefrustum
projection.Matrix4f
setToPick(float x, float y, float deltaX, float deltaY, Recti viewport, Matrix4f mat4Tmp)
Set this matrix to the pick matrix based on given parameters.Matrix4f
setToRotation(Quaternion q)
Set this matrix to rotation using the given Quaternion.Matrix4f
setToRotationAxis(float ang_rad, float x, float y, float z)
Set this matrix to rotation from the given axis and angle in radians.Matrix4f
setToRotationAxis(float ang_rad, Vec3f axis)
Set this matrix to rotation from the given axis and angle in radians.Matrix4f
setToRotationEuler(float bankX, float headingY, float attitudeZ)
Set this matrix to rotation from the given Euler rotation angles in radians.Matrix4f
setToRotationEuler(Vec3f angradXYZ)
Set this matrix to rotation from the given Euler rotation angles in radians.Matrix4f
setToScale(float x, float y, float z)
Set this matrix to scale.Matrix4f
setToScale(Vec3f s)
Set this matrix to scale.Matrix4f
setToTranslation(float x, float y, float z)
Set this matrix to translation.Matrix4f
setToTranslation(Vec3f t)
Set this matrix to translation.String
toString()
StringBuilder
toString(StringBuilder sb, String rowPrefix, String f)
Matrix4f
translate(float x, float y, float z, Matrix4f tmp)
Translate this matrix, i.e.Matrix4f
translate(Vec3f t, Matrix4f tmp)
Translate this matrix, i.e.Matrix4f
transpose()
Transpose this matrix.Matrix4f
transpose(Matrix4f src)
Transpose the givensrc
matrix into this matrix.void
updateFrustumPlanes(Frustum frustum)
Calculate the frustum planes in world coordinates using this premultiplied P*MV (column major order) matrix.
-
-
-
Constructor Detail
-
Matrix4f
public Matrix4f()
Creates a new identity matrix.
-
Matrix4f
public Matrix4f(Matrix4f src)
Creates a new matrix copying the values of the givensrc
matrix.
-
Matrix4f
public Matrix4f(float[] m)
Creates a new matrix based on given float[4*4] column major order.- Parameters:
m
- 4x4 matrix in column-major order
-
Matrix4f
public Matrix4f(float[] m, int m_off)
Creates a new matrix based on given float[4*4] column major order.- Parameters:
m
- 4x4 matrix in column-major orderm_off
- offset for matrixm
-
Matrix4f
public Matrix4f(FloatBuffer m)
Creates a new matrix based on givenFloatBuffer
4x4 column major order.- Parameters:
m
- 4x4 matrix in column-major order
-
-
Method Detail
-
set
public void set(int i, float v)
Sets thei
th component with floatv
0 <= i < 16
-
loadIdentity
public final Matrix4f loadIdentity()
Set this matrix to identity.Translation matrix (Column Order): 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
- Returns:
- this matrix for chaining
-
load
public Matrix4f load(Matrix4f src)
Load the values of the given matrixb
to this matrix.- Parameters:
src
- the source values- Returns:
- this matrix for chaining
-
load
public Matrix4f load(float[] src)
Load the values of the given matrixsrc
to this matrix.- Parameters:
src
- 4x4 matrix float[16] in column-major order- Returns:
- this matrix for chaining
-
load
public Matrix4f load(float[] src, int src_off)
Load the values of the given matrixsrc
to this matrix.- Parameters:
src
- 4x4 matrix float[16] in column-major ordersrc_off
- offset for matrixsrc
- Returns:
- this matrix for chaining
-
load
public Matrix4f load(FloatBuffer src)
Load the values of the given matrixsrc
to this matrix.Implementation uses relative
FloatBuffer.get()
, hence caller may want to issueFloatBuffer.reset()
thereafter.- Parameters:
src
- 4x4 matrixFloatBuffer
in column-major order- Returns:
- this matrix for chaining
-
get
public float get(int i)
Gets thei
th component, 0 <= i < 16
-
getColumn
public Vec4f getColumn(int column, Vec4f v_out)
Get the named column of the given column-major matrix to v_out.- Parameters:
column
- named column to copyv_out
- the column-vector storage- Returns:
- given result vector v_out for chaining
-
getColumn
public Vec3f getColumn(int column, Vec3f v_out)
Get the named column of the given column-major matrix to v_out.- Parameters:
column
- named column to copyv_out
- the column-vector storage- Returns:
- given result vector v_out for chaining
-
getRow
public Vec4f getRow(int row, Vec4f v_out)
Get the named row of the given column-major matrix to v_out.- Parameters:
row
- named row to copyv_out
- the row-vector storage- Returns:
- given result vector v_out for chaining
-
getRow
public Vec3f getRow(int row, Vec3f v_out)
Get the named row of the given column-major matrix to v_out.- Parameters:
row
- named row to copyv_out
- the row-vector storage- Returns:
- given result vector v_out for chaining
-
get
public float[] get(float[] dst, int dst_off)
Get this matrix into the given float[16] array atdst_off
in column major order.- Parameters:
dst
- float[16] array storage in column major orderdst_off
- offset- Returns:
dst
for chaining
-
get
public float[] get(float[] dst)
Get this matrix into the given float[16] array in column major order.- Parameters:
dst
- float[16] array storage in column major order- Returns:
dst
for chaining
-
get
public FloatBuffer get(FloatBuffer dst)
Get this matrix into the givenFloatBuffer
in column major order.Implementation uses relative
FloatBuffer.put(float)
, hence caller may want to issueFloatBuffer.reset()
thereafter.- Parameters:
dst
-FloatBuffer
array storage in column major order- Returns:
dst
for chaining
-
determinant
public float determinant()
Returns the determinant of this matrix- Returns:
- the matrix determinant
-
transpose
public final Matrix4f transpose()
Transpose this matrix.- Returns:
- this matrix for chaining
-
transpose
public final Matrix4f transpose(Matrix4f src)
Transpose the givensrc
matrix into this matrix.- Parameters:
src
- source 4x4 matrix- Returns:
- this matrix (result) for chaining
-
invert
public boolean invert()
Invert this matrix.- Returns:
- false if this matrix is singular and inversion not possible, otherwise true
-
invert
public boolean invert(Matrix4f src)
Invert thesrc
matrix values into this matrix- Parameters:
src
- the source matrix, which values are to be inverted- Returns:
- false if
src
matrix is singular and inversion not possible, otherwise true
-
mul
public final Matrix4f mul(Matrix4f b)
Multiply matrix: [this] = [this] x [b]- Parameters:
b
- 4x4 matrix- Returns:
- this matrix for chaining
- See Also:
mul(Matrix4f, Matrix4f)
-
mul
public final Matrix4f mul(Matrix4f a, Matrix4f b)
Multiply matrix: [this] = [a] x [b]- Parameters:
a
- 4x4 matrix, can't be this matrixb
- 4x4 matrix, can't be this matrix- Returns:
- this matrix for chaining
- See Also:
mul(Matrix4f)
-
mulVec4f
public final Vec4f mulVec4f(Vec4f v_in, Vec4f v_out)
- Parameters:
v_in
- 4-component column-vector, can be v_out for in-place transformationv_out
- this * v_in
-
mulVec4f
public final Vec4f mulVec4f(Vec4f v_inout)
- Parameters:
v_inout
- 4-component column-vector input and output, i.e. in-place transformation
-
mulVec3f
public final Vec3f mulVec3f(Vec3f v_in, Vec3f v_out)
Affine 3f-vector transformation by 4x4 matrix 4x4 matrix multiplication with 3-component vector, using1
for forv_in.w()
and droppingv_out.w()
, which shall be1
.
-
mulVec3f
public final Vec3f mulVec3f(Vec3f v_inout)
Affine 3f-vector transformation by 4x4 matrix 4x4 matrix multiplication with 3-component vector, using1
for forv_inout.w()
and droppingv_inout.w()
, which shall be1
.- Parameters:
v_inout
- 3-component column-vectorVec3f
input and output, i.e. in-place transformation
-
setToTranslation
public final Matrix4f setToTranslation(float x, float y, float z)
Set this matrix to translation.Translation matrix (Column Order): 1 0 0 0 0 1 0 0 0 0 1 0 x y z 1
- Parameters:
x
- x-axis translatey
- y-axis translatez
- z-axis translate- Returns:
- this matrix for chaining
-
setToTranslation
public final Matrix4f setToTranslation(Vec3f t)
Set this matrix to translation.Translation matrix (Column Order): 1 0 0 0 0 1 0 0 0 0 1 0 x y z 1
- Parameters:
t
- translate Vec3f- Returns:
- this matrix for chaining
-
setToScale
public final Matrix4f setToScale(float x, float y, float z)
Set this matrix to scale.Scale matrix (Any Order): x 0 0 0 0 y 0 0 0 0 z 0 0 0 0 1
- Parameters:
x
- x-axis scaley
- y-axis scalez
- z-axis scale- Returns:
- this matrix for chaining
-
setToScale
public final Matrix4f setToScale(Vec3f s)
Set this matrix to scale.Scale matrix (Any Order): x 0 0 0 0 y 0 0 0 0 z 0 0 0 0 1
- Parameters:
s
- scale Vec3f- Returns:
- this matrix for chaining
-
setToRotationAxis
public final Matrix4f setToRotationAxis(float ang_rad, float x, float y, float z)
Set this matrix to rotation from the given axis and angle in radians.Rotation matrix (Column Order): xx(1-c)+c xy(1-c)+zs xz(1-c)-ys 0 xy(1-c)-zs yy(1-c)+c yz(1-c)+xs 0 xz(1-c)+ys yz(1-c)-xs zz(1-c)+c 0 0 0 0 1
- Parameters:
ang_rad
- angle in radiansx
- x of rotation axisy
- y of rotation axisz
- z of rotation axis- Returns:
- this matrix for chaining
- See Also:
- Matrix-FAQ Q38
-
setToRotationAxis
public final Matrix4f setToRotationAxis(float ang_rad, Vec3f axis)
Set this matrix to rotation from the given axis and angle in radians.Rotation matrix (Column Order): xx(1-c)+c xy(1-c)+zs xz(1-c)-ys 0 xy(1-c)-zs yy(1-c)+c yz(1-c)+xs 0 xz(1-c)+ys yz(1-c)-xs zz(1-c)+c 0 0 0 0 1
- Parameters:
ang_rad
- angle in radiansaxis
- rotation axis- Returns:
- this matrix for chaining
- See Also:
- Matrix-FAQ Q38
-
setToRotationEuler
public Matrix4f setToRotationEuler(float bankX, float headingY, float attitudeZ)
Set this matrix to rotation from the given Euler rotation angles in radians.The rotations are applied in the given order:
- y - heading
- z - attitude
- x - bank
- Parameters:
bankX
- the Euler pitch angle in radians. (rotation about the X axis)headingY
- the Euler yaw angle in radians. (rotation about the Y axis)attitudeZ
- the Euler roll angle in radians. (rotation about the Z axis)- Returns:
- this matrix for chaining
Implementation does not use Quaternion and hence is exposed to Gimbal-Lock, consider using
setToRotation(Quaternion)
. - See Also:
- Matrix-FAQ Q36,
euclideanspace.com-eulerToMatrix,
setToRotation(Quaternion)
-
setToRotationEuler
public Matrix4f setToRotationEuler(Vec3f angradXYZ)
Set this matrix to rotation from the given Euler rotation angles in radians.The rotations are applied in the given order:
- y - heading
- z - attitude
- x - bank
- Parameters:
angradXYZ
- euler angle vector in radians holding x-bank, y-heading and z-attitude- Returns:
- this quaternion for chaining.
Implementation does not use Quaternion and hence is exposed to Gimbal-Lock, consider using
setToRotation(Quaternion)
. - See Also:
- Matrix-FAQ Q36,
euclideanspace.com-eulerToMatrix,
setToRotation(Quaternion)
-
setToRotation
public final Matrix4f setToRotation(Quaternion q)
Set this matrix to rotation using the given Quaternion.Implementation Details:
- Parameters:
q
- the Quaternion representing the rotation- Returns:
- this matrix for chaining
- See Also:
- Matrix-FAQ Q54,
Quaternion.toMatrix(float[])
,#getRotation()
-
getRotation
public final Quaternion getRotation(Quaternion res)
Returns the rotation [m00 .. m22] fields converted to a Quaternion.- Parameters:
res
- resulting Quaternion- Returns:
- the resulting Quaternion for chaining.
- See Also:
Quaternion.setFromMatrix(float, float, float, float, float, float, float, float, float)
,setToRotation(Quaternion)
-
setToOrtho
public Matrix4f setToOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
Set this matrix to orthogonal projection.Ortho matrix (Column Order): 2/dx 0 0 0 0 2/dy 0 0 0 0 2/dz 0 tx ty tz 1
- Parameters:
left
-right
-bottom
-top
-zNear
-zFar
-- Returns:
- this matrix for chaining
-
setToFrustum
public Matrix4f setToFrustum(float left, float right, float bottom, float top, float zNear, float zFar) throws IllegalArgumentException
Set this matrix to frustum.Frustum matrix (Column Order): 2*zNear/dx 0 0 0 0 2*zNear/dy 0 0 A B C -1 0 0 D 0
- Parameters:
left
-right
-bottom
-top
-zNear
-zFar
-- Returns:
- this matrix for chaining
- Throws:
IllegalArgumentException
- ifzNear <= 0
orzFar <= zNear
orleft == right
, orbottom == top
.
-
setToPerspective
public Matrix4f setToPerspective(float fovy_rad, float aspect, float zNear, float zFar) throws IllegalArgumentException
Set this matrix to perspectivefrustum
projection.- Parameters:
fovy_rad
- angle in radiansaspect
- aspect ratio width / heightzNear
-zFar
-- Returns:
- this matrix for chaining
- Throws:
IllegalArgumentException
- ifzNear <= 0
orzFar <= zNear
- See Also:
setToFrustum(float, float, float, float, float, float)
-
setToPerspective
public Matrix4f setToPerspective(FovHVHalves fovhv, float zNear, float zFar) throws IllegalArgumentException
Set this matrix to perspectivefrustum
projection.- Parameters:
fovhv
-FovHVHalves
field of view in both directions, may not be centered, either in radians or tangentzNear
-zFar
-- Returns:
- this matrix for chaining
- Throws:
IllegalArgumentException
- ifzNear <= 0
orzFar <= zNear
- See Also:
setToFrustum(float, float, float, float, float, float)
,Frustum.updateByFovDesc(Matrix4f, com.jogamp.opengl.math.geom.Frustum.FovDesc)
-
updateFrustumPlanes
public void updateFrustumPlanes(Frustum frustum)
Calculate the frustum planes in world coordinates using this premultiplied P*MV (column major order) matrix.Frustum plane's normals will point to the inside of the viewing frustum, as required by this class.
Usually called by
Frustum.updateFrustumPlanes(Matrix4f)
.
-
setToLookAt
public Matrix4f setToLookAt(Vec3f eye, Vec3f center, Vec3f up, Matrix4f tmp)
Set this matrix to the look-at matrix based on given parameters.Consist out of two matrix multiplications:
R = L x T, with L for look-at matrix and T for eye translation. Result R can be utilized for projection or modelview multiplication, i.e. M = M x R, with M being the projection or modelview matrix.
- Parameters:
eye
- 3 component eye vectorcenter
- 3 component center vectorup
- 3 component up vectortmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
setToPick
public Matrix4f setToPick(float x, float y, float deltaX, float deltaY, Recti viewport, Matrix4f mat4Tmp)
Set this matrix to the pick matrix based on given parameters.Traditional
gluPickMatrix
implementation.Consist out of two matrix multiplications:
R = T x S, with T for viewport translation matrix and S for viewport scale matrix. Result R can be utilized for projection multiplication, i.e. P = P x R, with P being the projection matrix.
To effectively use the generated pick matrix for picking, call
setToPick(..)
and multiply acustom perspective matrix
by this pick matrix. Then you may load the result onto the perspective matrix stack.- Parameters:
x
- the center x-component of a picking region in window coordinatesy
- the center y-component of a picking region in window coordinatesdeltaX
- the width of the picking region in window coordinates.deltaY
- the height of the picking region in window coordinates.viewport
- Rect4i viewportmat4Tmp
- temp storage- Returns:
- this matrix for chaining or
null
if either delta value is <= zero.
-
rotate
public final Matrix4f rotate(float ang_rad, float x, float y, float z, Matrix4f tmp)
Rotate this matrix about give axis and angle in radians, i.e. multiply byaxis-rotation matrix
.- Parameters:
angrad
- angle in radiansx
- x of rotation axisy
- y of rotation axisz
- z of rotation axistmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
- See Also:
- Matrix-FAQ Q38
-
rotate
public final Matrix4f rotate(float ang_rad, Vec3f axis, Matrix4f tmp)
Rotate this matrix about give axis and angle in radians, i.e. multiply byaxis-rotation matrix
.- Parameters:
angrad
- angle in radiansaxis
- rotation axistmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
- See Also:
- Matrix-FAQ Q38
-
rotate
public final Matrix4f rotate(Quaternion quat, Matrix4f tmp)
Rotate this matrix with the givenQuaternion
, i.e. multiply byQuaternion's rotation matrix
.- Parameters:
tmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
translate
public final Matrix4f translate(float x, float y, float z, Matrix4f tmp)
Translate this matrix, i.e. multiply bytranslation matrix
.- Parameters:
x
- x translationy
- y translationz
- z translationtmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
translate
public final Matrix4f translate(Vec3f t, Matrix4f tmp)
Translate this matrix, i.e. multiply bytranslation matrix
.- Parameters:
t
- translation Vec3ftmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
scale
public final Matrix4f scale(float x, float y, float z, Matrix4f tmp)
Scale this matrix, i.e. multiply byscale matrix
.- Parameters:
x
- x scaley
- y scalez
- z scaletmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
scale
public final Matrix4f scale(float s, Matrix4f tmp)
Scale this matrix, i.e. multiply byscale matrix
.- Parameters:
s
- scale for x-, y- and z-axistmp
- temporary Matrix4f used for multiplication- Returns:
- this matrix for chaining
-
push
public final void push()
Push the matrix to it's stack, while preserving this matrix values.- See Also:
pop()
-
pop
public final void pop()
Pop the current matrix from it's stack, replacing this matrix values.- See Also:
push()
-
isEqual
public boolean isEqual(Matrix4f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison valueepsilon
- consider usingFloatUtil.EPSILON
- Returns:
- true if all components differ less than
epsilon
, otherwise false.
-
isEqual
public boolean isEqual(Matrix4f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison value- Returns:
- true if all components differ less than
FloatUtil.EPSILON
, otherwise false.
-
mapObjToWin
public static boolean mapObjToWin(Vec3f obj, Matrix4f mMv, Matrix4f mP, Recti viewport, Vec3f winPos)
Map object coordinates to window coordinates.Traditional
gluProject
implementation.- Parameters:
obj
- object position, 3 component vectormMv
- modelview matrixmP
- projection matrixviewport
- Rect4i viewportwinPos
- 3 component window coordinate, the result- Returns:
- true if successful, otherwise false (z is 1)
-
mapObjToWin
public static boolean mapObjToWin(Vec3f obj, Matrix4f mPMv, Recti viewport, Vec3f winPos)
Map object coordinates to window coordinates.Traditional
gluProject
implementation.- Parameters:
obj
- object position, 3 component vectormPMv
- [projection] x [modelview] matrix, i.e. P x Mvviewport
- Rect4i viewportwinPos
- 3 component window coordinate, the result- Returns:
- true if successful, otherwise false (z is 1)
-
mapWinToObj
public static boolean mapWinToObj(float winx, float winy, float winz, Matrix4f mMv, Matrix4f mP, Recti viewport, Vec3f objPos, Matrix4f mat4Tmp)
Map window coordinates to object coordinates.Traditional
gluUnProject
implementation.- Parameters:
winx
-winy
-winz
-mMv
- 4x4 modelview matrixmP
- 4x4 projection matrixviewport
- Rect4i viewportobjPos
- 3 component object coordinate, the resultmat4Tmp
- 16 component matrix for temp storage- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
-
mapWinToObj
public static boolean mapWinToObj(float winx, float winy, float winz, Matrix4f invPMv, Recti viewport, Vec3f objPos)
Map window coordinates to object coordinates.Traditional
gluUnProject
implementation.- Parameters:
winx
-winy
-winz
-invPMv
- inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv), if null method returns falseviewport
- Rect4i viewportobjPos
- 3 component object coordinate, the result- Returns:
- true if successful, otherwise false (null invert matrix, or becomes infinity due to zero z)
-
mapWinToObj
public static boolean mapWinToObj(float winx, float winy, float winz1, float winz2, Matrix4f invPMv, Recti viewport, Vec3f objPos1, Vec3f objPos2)
Map two window coordinates to two object coordinates, distinguished by their z component.Traditional
gluUnProject
implementation.- Parameters:
winx
-winy
-winz1
-winz2
-invPMv
- inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv), if null method returns falseviewport
- Rect4i viewport vectorobjPos1
- 3 component object coordinate, the result- Returns:
- true if successful, otherwise false (null invert matrix, or becomes infinity due to zero z)
-
mapWinToObj4
public static boolean mapWinToObj4(float winx, float winy, float winz, float clipw, Matrix4f mMv, Matrix4f mP, Recti viewport, float near, float far, Vec4f objPos, Matrix4f mat4Tmp)
Map window coordinates to object coordinates.Traditional
gluUnProject4
implementation.- Parameters:
winx
-winy
-winz
-clipw
-mMv
- 4x4 modelview matrixmP
- 4x4 projection matrixviewport
- Rect4i viewport vectornear
-far
-obj_pos
- 4 component object coordinate, the resultmat4Tmp
- 16 component matrix for temp storage- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
-
mapWinToObj4
public static boolean mapWinToObj4(float winx, float winy, float winz, float clipw, Matrix4f invPMv, Recti viewport, float near, float far, Vec4f objPos)
Map window coordinates to object coordinates.Traditional
gluUnProject4
implementation.- Parameters:
winx
-winy
-winz
-clipw
-invPMv
- inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv), if null method returns falseviewport
- Rect4i viewport vectornear
-far
-obj_pos
- 4 component object coordinate, the result- Returns:
- true if successful, otherwise false (null invert matrix, or becomes infinity due to zero z)
-
mapWinToRay
public static boolean mapWinToRay(float winx, float winy, float winz0, float winz1, Matrix4f mMv, Matrix4f mP, Recti viewport, Ray ray, Matrix4f mat4Tmp1, Matrix4f mat4Tmp2)
Map two window coordinates w/ shared X/Y and distinctive Z to aRay
. The resultingRay
maybe used for picking using aAABBox.getRayIntersection(Vec3f, Ray, float, boolean)
.Notes for picking winz0 and winz1:
- Parameters:
winx
-winy
-winz0
-winz1
-mMv
- 4x4 modelview matrixmP
- 4x4 projection matrixviewport
- Rect4i viewportray
- storage for the resultingRay
mat4Tmp1
- 16 component matrix for temp storagemat4Tmp2
- 16 component matrix for temp storage- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
-
mapWinToRay
public static boolean mapWinToRay(float winx, float winy, float winz0, float winz1, Matrix4f invPMv, Recti viewport, Ray ray)
Map two window coordinates w/ shared X/Y and distinctive Z to aRay
. The resultingRay
maybe used for picking using aAABBox.getRayIntersection(Vec3f, Ray, float, boolean)
.Notes for picking winz0 and winz1:
- Parameters:
winx
-winy
-winz0
-winz1
-invPMv
- inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv), if null method returns falseviewport
- Rect4i viewportray
- storage for the resultingRay
- Returns:
- true if successful, otherwise false (null invert matrix, or becomes z is infinity)
-
toString
public StringBuilder toString(StringBuilder sb, String rowPrefix, String f)
- Parameters:
sb
- optional passed StringBuilder instance to be usedrowPrefix
- optional prefix for each rowf
- the format string of one floating point, i.e. "%10.5f", seeFormatter
- Returns:
- matrix string representation
-
-