Class Matrix4f
java.lang.Object
de.arstwo.twotil.math.Matrix4f
- All Implemented Interfaces:
Cloneable
A 3D Matrix implementation for Quaternions using floats.
Calculations are done in place, so no additional memory is allocated by operations.
This is compatible with OpenGL and other implementations, which use a column-major approach instead of the row-major that is intuitively used. This is only relevant if accessing the data directly. It's underlying FloatBuffer can therefore be directly inserted into OpenGL. You can use the constants below to access specific data points directly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FloatBufferstatic final intprotected final float[]protected static final Matrix4fstatic final intstatic final intstatic final intstatic final intstatic final intMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, wwstatic final intstatic final intstatic final intstatic final intMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, wwstatic final intstatic final intstatic final intstatic final intMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, wwstatic final intstatic final intstatic final intstatic final intMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, wwstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPerforms a matrix addition of this and other.buffer()Returns the internal float buffer for direct access.clone()booleanbooleanChecks if this is equal to other within the given delta for precisionbooleanstatic Matrix4fReturns a new identity matrix.inthashCode()Performs a matrix multiplication of this and other.rotate(float radians, float axisX, float axisY, float axisZ) Rotates this matrix around a given axis.Rotates this matrix around a given axis.Copy constructor.setColumnMajor(float[] data) Sets the data of this matrix to the given external data represented in that array.Sets this matrix to identity values.setLook(float positionX, float positionY, float positionZ, float rightX, float rightY, float rightZ, float upX, float upY, float upZ, float lookX, float lookY, float lookZ) Sets this matrix to a look matrix (an imaginary camera in 3D space looking into a specific direction) with the given float values.Sets this matrix to a look matrix (an imaginary camera in 3D space looking into a specific direction) with the given Vector4f values.Sets this matrix to be an orthogonal (2D) projection.setProjection(float fovY, float aspectRatio, float zNear, float zFar) Sets this matrix to be a projection matrix with the given values.setRotation(float radians, float axisX, float axisY, float axisZ) Sets this matrix to be a fixed rotation around a given axis.setRotation(float radians, Vector4f axis) Sets this matrix to be a fixed rotation around a given axis.setRowMajor(float[] data) Sets the data of this matrix to the given external data represented in that array, that is in a row-major format.setTranslate(float x, float y, float z) Sets the translation components of this matrix with the given values.Transposes this matrix (flips it diagonally).protected Matrix4fsetUnchecked(float[] data) Internal function to setColumnMajor the data of this matrix without checking it.setZero()Sets the content of this matrix to all 0.Performs a matrix subtraction of this and other.toString()translate(float x, float y, float z) Translates this matrix by the given values.Translates this matrix by the given other matrix.Translates this matrix by the given Vector4f.translateX(float x) Translates this matrix by the given x values.translateY(float y) Translates this matrix by the given y values.translateZ(float z) Translates this matrix by the given z values.
-
Field Details
-
ROWS
public static final int ROWS- See Also:
-
COLS
public static final int COLS- See Also:
-
LENGTH
public static final int LENGTH- See Also:
-
SIZE_BYTE
public static final int SIZE_BYTE- See Also:
-
IDENTITY
-
XX
public static final int XXMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, ww- See Also:
-
YX
public static final int YXMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, ww- See Also:
-
ZX
public static final int ZXMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, ww- See Also:
-
WX
public static final int WXMatrix constants for easier access: | xx xy xz xw | | yx yy yz yw | | zx zy zz zw | | wx wy wz ww | Note that OpenGL expects the matrix in format xy, yx, ..., zw, ww- See Also:
-
XY
public static final int XY- See Also:
-
YY
public static final int YY- See Also:
-
ZY
public static final int ZY- See Also:
-
WY
public static final int WY- See Also:
-
XZ
public static final int XZ- See Also:
-
YZ
public static final int YZ- See Also:
-
ZZ
public static final int ZZ- See Also:
-
WZ
public static final int WZ- See Also:
-
XW
public static final int XW- See Also:
-
YW
public static final int YW- See Also:
-
ZW
public static final int ZW- See Also:
-
WW
public static final int WW- See Also:
-
buffer
-
data
protected final float[] data
-
-
Constructor Details
-
Matrix4f
public Matrix4f()Creats a new Matrix4f with all values setColumnMajor to 0.
-
-
Method Details
-
getIdentityMatrix
Returns a new identity matrix.- Returns:
- a new identity matrix.
-
set
-
setColumnMajor
Sets the data of this matrix to the given external data represented in that array.The expected format is column-major (xx yx zx wx...)
- Parameters:
data- any compatible float array that holds data flattened by column then by row.- Returns:
-
setRowMajor
Sets the data of this matrix to the given external data represented in that array, that is in a row-major format.The internal format is column-major (xx yx zx wx...), while the input data is row-major (xx, xy, xz, xw, ...).
- Parameters:
data- any compatible float array that holds data flattened by row then by column.- Returns:
-
setZero
Sets the content of this matrix to all 0.- Returns:
- this matrix, with all content set to 0.
-
setUnchecked
Internal function to setColumnMajor the data of this matrix without checking it.- Parameters:
data- any array of exactly 16 floats.- Returns:
- this matrix, with all data setColumnMajor to the new values.
-
setIdentity
-
setTranspose
-
setOrthogonalProjection
Sets this matrix to be an orthogonal (2D) projection.- Returns:
- this matrix.
-
setProjection
Sets this matrix to be a projection matrix with the given values.- Parameters:
fovY- Field of viewaspectRatio- the aspect ratio of the planezNear- near clipping rangezFar- far clipping range- Returns:
- this matrix.
-
setLook
Sets this matrix to a look matrix (an imaginary camera in 3D space looking into a specific direction) with the given Vector4f values.- Parameters:
position- the position of the cameraright- what is considered the direction 'right' of the cameraup- what is considered the direction 'up' of the cameralook- what is considered the direction that the camera is 'looking' at- Returns:
- this matrix.
-
setLook
public Matrix4f setLook(float positionX, float positionY, float positionZ, float rightX, float rightY, float rightZ, float upX, float upY, float upZ, float lookX, float lookY, float lookZ) Sets this matrix to a look matrix (an imaginary camera in 3D space looking into a specific direction) with the given float values.- Returns:
- this matrix.
- See Also:
-
add
-
sub
-
multiply
-
setTranslate
Sets the translation components of this matrix with the given values.Note that all other values are kept as they were. If you want a pure translation matrix you need to setIdentity first.
- Parameters:
x- any floaty- any floatz- any float- Returns:
- this matrix.
-
translate
-
translate
Translates this matrix by the given values.- Parameters:
x- any floaty- any floatz- any float- Returns:
- this matrix.
-
translate
-
translateX
Translates this matrix by the given x values.- Parameters:
x- any float- Returns:
- this matrix.
-
translateY
Translates this matrix by the given y values.- Parameters:
y- any float- Returns:
- this matrix.
-
translateZ
Translates this matrix by the given z values.- Parameters:
z- any float- Returns:
- this matrix.
-
rotate
-
rotate
Rotates this matrix around a given axis.- Parameters:
radians- radians to rotate around the axisaxisX- the x part of the axis to rotate aroundaxisY- the y part of the axis to rotate aroundaxisZ- the z part of the axis to rotate around- Returns:
- this matrix.
-
setRotation
-
setRotation
Sets this matrix to be a fixed rotation around a given axis.- Parameters:
radians- radians to rotate around the axisaxisX- the x part of the axis to rotate aroundaxisY- the y part of the axis to rotate aroundaxisZ- the z part of the axis to rotate around- Returns:
- this matrix
-
buffer
Returns the internal float buffer for direct access.- Returns:
- the internal float buffer for direct access.
-
hashCode
-
equals
-
equals
-
equals
Checks if this is equal to other within the given delta for precision- Parameters:
other- any other Matrix4fdelta- acceptable distance between two floats to count as equal- Returns:
- true if those are equal within the given delta, false otherwise
-
clone
-
toString
-