Class Matrix4F
java.lang.Object
com.blackrook.gloop.opengl.math.Matrix4F
This is a 4x4 Matrix object that stores floats.
Indices are in column-major order.
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
- Author:
- Matthew Tropiano
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static float[]Identity Matrix in column-major form. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar) Multiplies an aspect-corrected orthographic projection matrix into this one.copy()voidCopies this Matrix into another.frustum(float left, float right, float bottom, float top, float zNear, float zFar) Multiplies a frustum projection matrix into this one.float[]getArray()voidgetFloats(float[] out) Returns the floats that make up this matrix into a float array.voidgetFloats(float[] out, int offset) Returns the floats that make up this matrix into a float array.lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) Multiplies a "look at" perspective matrix into this one.voidmultiplyLeft(Matrix4F matrix) Multiplies this matrix with another.voidmultiplyRight(Matrix4F matrix) Multiplies this matrix with another.static Matrix4Fortho(float left, float right, float bottom, float top, float zNear, float zFar) Multiplies a orthographic projection matrix into this one.perspective(float fov, float aspect, float zNear, float zFar) Multiplies a perspective projection matrix into this one.reset()Resets this matrix to the identity matrix.rotateX(float degrees) Multiplies a X-axis rotation matrix into this one.rotateY(float degrees) Multiplies a Y-axis rotation matrix into this one.rotateZ(float degrees) Multiplies a Z-axis rotation matrix into this one.scale(float scalar) Multiplies a scaling matrix into this one.scale(float scaleX, float scaleY, float scaleZ) Multiplies a scaling matrix into this one.voidset(float[] values) Sets all positions in this matrix to a set of values.voidset(int index, float value) Sets a matrix index (column major index) to a value.voidset(int row, int col, float val) Sets a position in this matrix to a value.voidSets all positions in this matrix to a set of values from another.voidsetAspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as an aspect-corrected projection matrix, orthographic projection.voidsetFrustum(float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as a projection matrix, frustum projection.voidSets this matrix to the identity matrix.voidsetLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) Sets this matrix's values up as a "look at" perspective matrix.voidsetOrtho(float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as a projection matrix, orthographic projection.voidsetPerspective(float fov, float aspect, float zNear, float zFar) Sets this matrix's values up as a projection matrix, perspective arguments.voidsetRotateX(float degrees) Sets this matrix to a x-rotation matrix.voidsetRotateY(float degrees) Sets this matrix to a y-rotation matrix.voidsetRotateZ(float degrees) Sets this matrix to a z-rotation matrix.voidsetRotation(float degX, float degY, float degZ) Sets this matrix to a rotation matrix.voidsetScale(float scalar) Sets this matrix to a scaling matrix, scaling all axes equally.voidsetScale(float scaleX, float scaleY, float scaleZ) Sets this matrix to a scaling matrix.voidsetShear(float shear) Sets this matrix to a shearing matrix.voidsetTranslation(float x, float y, float z) Sets this matrix to a translation matrix.shear(float shear) Multiplies a shearing matrix into this one.translate(float x, float y, float z) Multiplies a translation matrix into this one.
-
Field Details
-
IDENTITY
protected static float[] IDENTITYIdentity Matrix in column-major form.
-
-
Constructor Details
-
Matrix4F
public Matrix4F()Constructs a new, blank 4x4 matrix.
-
-
Method Details
-
newIdentity
- Returns:
- a new 4x4 Identity Matrix.
-
setIdentity
public void setIdentity()Sets this matrix to the identity matrix. -
setTranslation
public void setTranslation(float x, float y, float z) Sets this matrix to a translation matrix.- Parameters:
x- the x-axis translation.y- the y-axis translation.z- the z-axis translation.
-
setRotateX
public void setRotateX(float degrees) Sets this matrix to a x-rotation matrix.- Parameters:
degrees- degrees to rotate.
-
setRotateY
public void setRotateY(float degrees) Sets this matrix to a y-rotation matrix.- Parameters:
degrees- degrees to rotate.
-
setRotateZ
public void setRotateZ(float degrees) Sets this matrix to a z-rotation matrix.- Parameters:
degrees- degrees to rotate.
-
setRotation
public void setRotation(float degX, float degY, float degZ) Sets this matrix to a rotation matrix.- Parameters:
degX- degrees to rotate around the X axis.degY- degrees to rotate around the Y axis.degZ- degrees to rotate around the Z axis.
-
setScale
public void setScale(float scaleX, float scaleY, float scaleZ) Sets this matrix to a scaling matrix.- Parameters:
scaleX- amount to scale along the X axis.scaleY- amount to scale along the Y axis.scaleZ- amount to scale along the Z axis.
-
setScale
public void setScale(float scalar) Sets this matrix to a scaling matrix, scaling all axes equally.- Parameters:
scalar- amount to scale along the all axes.
-
setShear
public void setShear(float shear) Sets this matrix to a shearing matrix.- Parameters:
shear- amount to shear.
-
setLookAt
public void setLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) Sets this matrix's values up as a "look at" perspective matrix.- Parameters:
eyeX- the eye vector, x-component.eyeY- the eye vector, y-component.eyeZ- the eye vector, z-component.centerX- the centerpoint, x-component.centerY- the centerpoint, y-component.centerZ- the centerpoint, z-component.upX- the upward vector, x-component.upY- the upward vector, y-component.upZ- the upward vector, z-component.
-
setPerspective
public void setPerspective(float fov, float aspect, float zNear, float zFar) Sets this matrix's values up as a projection matrix, perspective arguments.- Parameters:
fov- front of view angle in degrees.aspect- the aspect ratio, usually view width over view height.zNear- the near clipping plane on the Z-Axis.zFar- the far clipping plane on the Z-Axis.
-
setFrustum
public void setFrustum(float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as a projection matrix, frustum projection.- Parameters:
left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.
-
setOrtho
public void setOrtho(float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as a projection matrix, orthographic projection.- Parameters:
left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.
-
setAspectOrtho
public void setAspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar) Sets this matrix's values up as an aspect-corrected projection matrix, orthographic projection.- Parameters:
aspect- the target aspect.left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.
-
set
public void set(int row, int col, float val) Sets a position in this matrix to a value.- Parameters:
row- the desired matrix row.col- the desired matrix column.val- the new value to set.
-
set
Sets all positions in this matrix to a set of values from another.- Parameters:
matrix- the matrix to copy from.
-
set
public void set(float[] values) Sets all positions in this matrix to a set of values. Please note that the values must be in column-major order. The amount of values copied is values.length or 16, whichever's smaller.- Parameters:
values- new array of values.
-
set
public void set(int index, float value) Sets a matrix index (column major index) to a value.- Parameters:
index- the column-major-wise index.value- the value to set.
-
reset
Resets this matrix to the identity matrix.- Returns:
- itself, to chain commands.
-
translate
Multiplies a translation matrix into this one.- Parameters:
x- the x-axis translation.y- the y-axis translation.z- the z-axis translation.- Returns:
- itself, to chain commands.
-
rotateX
Multiplies a X-axis rotation matrix into this one.- Parameters:
degrees- degrees to rotate.- Returns:
- itself, to chain commands.
-
rotateY
Multiplies a Y-axis rotation matrix into this one.- Parameters:
degrees- degrees to rotate.- Returns:
- itself, to chain commands.
-
rotateZ
Multiplies a Z-axis rotation matrix into this one.- Parameters:
degrees- degrees to rotate.- Returns:
- itself, to chain commands.
-
scale
Multiplies a scaling matrix into this one.- Parameters:
scaleX- amount to scale along the X axis.scaleY- amount to scale along the Y axis.scaleZ- amount to scale along the Z axis.- Returns:
- itself, to chain commands.
-
scale
Multiplies a scaling matrix into this one.- Parameters:
scalar- amount to scale along the all axes.- Returns:
- itself, to chain commands.
-
shear
Multiplies a shearing matrix into this one.- Parameters:
shear- amount to shear.- Returns:
- itself, to chain commands.
-
lookAt
public Matrix4F lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) Multiplies a "look at" perspective matrix into this one.- Parameters:
eyeX- the eye vector, x-component.eyeY- the eye vector, y-component.eyeZ- the eye vector, z-component.centerX- the centerpoint, x-component.centerY- the centerpoint, y-component.centerZ- the centerpoint, z-component.upX- the upward vector, x-component.upY- the upward vector, y-component.upZ- the upward vector, z-component.- Returns:
- itself, to chain commands.
-
perspective
Multiplies a perspective projection matrix into this one.- Parameters:
fov- front of view angle in degrees.aspect- the aspect ratio, usually view width over view height.zNear- the near clipping plane on the Z-Axis.zFar- the far clipping plane on the Z-Axis.- Returns:
- itself, to chain commands.
-
frustum
Multiplies a frustum projection matrix into this one.- Parameters:
left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.- Returns:
- itself, to chain commands.
-
ortho
Multiplies a orthographic projection matrix into this one.- Parameters:
left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.- Returns:
- itself, to chain commands.
-
aspectOrtho
public Matrix4F aspectOrtho(float aspect, float left, float right, float bottom, float top, float zNear, float zFar) Multiplies an aspect-corrected orthographic projection matrix into this one.- Parameters:
aspect- the target aspect.left- the left clipping plane on the X axis.right- the right clipping plane on the X axis.bottom- the bottom clipping plane on the Y axis.top- the upper clipping plane on the Y axis.zNear- the near clipping plane on the Z axis.zFar- the far clipping plane on the Z axis.- Returns:
- itself, to chain commands.
-
multiplyRight
Multiplies this matrix with another.this x m
- Parameters:
matrix- the multiplicand matrix.
-
multiplyLeft
Multiplies this matrix with another.m x this
- Parameters:
matrix- the multiplicand matrix.
-
getArray
public float[] getArray()- Returns:
- a reference to the float array that makes up this matrix.
-
getFloats
public void getFloats(float[] out) Returns the floats that make up this matrix into a float array. Equivalent togetFloats(out, 0)Values are in column-major order.- Parameters:
out- the output array.- Throws:
ArrayIndexOutOfBoundsException- ifout.length < 16.
-
getFloats
public void getFloats(float[] out, int offset) Returns the floats that make up this matrix into a float array. Values are in column-major order.- Parameters:
out- the output array.offset- the starting offset array.- Throws:
ArrayIndexOutOfBoundsException- ifoffset + 16 >= out.length.
-
copyTo
Copies this Matrix into another.- Parameters:
target- the target matrix to copy into.
-
copy
- Returns:
- a new copy of this Matrix.
-