There are two implementations for matrices that are offered. A 3x3 column major matrix Mat3 and a 4x4 column major matrix Mat4.
Unlike vectors, these matrices are mutable by default and do not offer any immutable versions.
Conventions
- Matrices are column-major and use column vectors:
M * v. Translation lives in the last column (m03,m13,m23). - Basis axes are the columns.
Mat4.set(xAxis, yAxis, zAxis, pos)writes them as columns. setToWorld(position, forward, up)builds a world transform whose-Zfacesforward.scaleX,scaleY,scaleZandgetScale(Mat4andMat3) are column lengths, so they hold forT * R * Swith non-uniform scale.Mat4.getRotation(MutableQuaternion)ignores scale.
Euler angles use YXZ order everywhere: roll (Z) first, then pitch (X), then yaw (Y). Pitch is about X, yaw about Y, roll about Z. These all give the same rotation:
Mat4.setFromEulerAngles(pitch, yaw, roll)Mat4.rotate(eulerX, eulerY, eulerZ)Mat3.setFromEulerAngles(eulerX, eulerY, eulerZ)(degrees)MutableQuaternion.setEuler(pitch, yaw, roll)Node3D.rotate(x, y, z)
val a = Mat4().setFromEulerAngles(30.degrees, 45.degrees, 10.degrees)
val b = Mat4().setToRotation(MutableQuaternion().setEuler(30.degrees, 45.degrees, 10.degrees))
// a == b
Functions
The matrices implementations offer the standard matrix functions one would expect:
translate: translates a matrix by its translation componentrotate: rotates a matrix by its rotation componentmul: post-multiplies a matrix with another matrixmulLeft: pre-multiplies a matrix with another matrixsetToIdentity: sets the matrix to an identity matrixsetToOrthographic: sets the matrix to an orthographic projectionsetToPerspective: sets the matrix to a perspective projectionsetToTranslate: resets the matrix to an identity matrix and sets the translation componentsetToTranslateAndScaling: resets the matrix to an identity matrix and sets the translation and scaling componentssetToRotation: resets the matrix to an identity and sets the rotation componentsetToLookAt: sets the matrix to look at the given position and targetscale: scales the matrixinvert: inverts the matrixtoBuffer: dumps the matrix data into aFloatBuffertoList: dumps the matrix data into aList<Float>
PREVIOUSVectors
NEXTMath Extensions