public final class Matrix4

  1. Object
  2. Matrix4
Portable column-major 4x4 float matrix math used by the 3D API. Every operation works on plain float[16] arrays so it behaves identically on every platform without relying on native transform support. The layout matches OpenGL/Metal column-major convention: element m[c * 4 + r] is column c, row r.

Methods

public static float[] identity()Allocates a new identity matrix.
public static void setIdentity(float[] m)Resets the supplied matrix to the identity matrix.
public static void copy(float[] src, float[] dst)Copies the contents of src into dst.
public static void multiply(float[] a, float[] b, float[] dst)Multiplies a * b and stores the result in dst.
public static float[] perspective(float fovYRadians, float aspect, float near, float far)Builds a perspective projection matrix.
public static float[] ortho(float left, float right, float bottom, float top, float near, float far)Builds an orthographic projection matrix.
public static float[] lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)Builds a right-handed look-at view matrix from eye, target and up vectors.
public static float[] translation(float x, float y, float z)Returns a translation matrix.
public static float[] scaling(float x, float y, float z)Returns a scale matrix.
public static float[] rotation(float angleRadians, float x, float y, float z)Returns a rotation matrix around an arbitrary axis.
public static float[] normalMatrix(float[] m)Computes the transpose of the upper-left 3x3 of the inverse of m, expanded to a 4x4.
public static boolean invert(float[] m, float[] dst)Inverts m into dst.

Inherited methods

Method details

identity

public static float[] identity()
Allocates a new identity matrix.

setIdentity

public static void setIdentity(float[] m)
Resets the supplied matrix to the identity matrix.

copy

public static void copy(float[] src, float[] dst)
Copies the contents of src into dst. Both arrays must hold 16 floats.

multiply

public static void multiply(float[] a, float[] b, float[] dst)
Multiplies a * b and stores the result in dst. dst may not alias a or b.

perspective

public static float[] perspective(float fovYRadians, float aspect, float near, float far)
Builds a perspective projection matrix. fovYRadians is the vertical field of view in radians, aspect the width/height ratio.

ortho

public static float[] ortho(float left, float right, float bottom, float top, float near, float far)
Builds an orthographic projection matrix.

lookAt

public static float[] lookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Builds a right-handed look-at view matrix from eye, target and up vectors.

translation

public static float[] translation(float x, float y, float z)
Returns a translation matrix.

scaling

public static float[] scaling(float x, float y, float z)
Returns a scale matrix.

rotation

public static float[] rotation(float angleRadians, float x, float y, float z)
Returns a rotation matrix around an arbitrary axis. angleRadians is the rotation angle, (x, y, z) the rotation axis (need not be normalized).

normalMatrix

public static float[] normalMatrix(float[] m)
Computes the transpose of the upper-left 3x3 of the inverse of m, expanded to a 4x4. This is the correct matrix for transforming normals. Returns the identity when m is not invertible.

invert

public static boolean invert(float[] m, float[] dst)
Inverts m into dst. Returns false (leaving dst untouched) when the matrix is singular.