Class Matrix4
java.lang.Object
com.codename1.gpu.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.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(float[] src, float[] dst) Copies the contents ofsrcintodst.static float[]identity()Allocates a new identity matrix.static booleaninvert(float[] m, float[] dst) Invertsmintodst.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.static voidmultiply(float[] a, float[] b, float[] dst) Multipliesa * band stores the result indst.static float[]normalMatrix(float[] m) Computes the transpose of the upper-left 3x3 of the inverse ofm, expanded to a 4x4.static float[]ortho(float left, float right, float bottom, float top, float near, float far) Builds an orthographic projection matrix.static float[]perspective(float fovYRadians, float aspect, float near, float far) Builds a perspective projection matrix.static float[]rotation(float angleRadians, float x, float y, float z) Returns a rotation matrix around an arbitrary axis.static float[]scaling(float x, float y, float z) Returns a scale matrix.static voidsetIdentity(float[] m) Resets the supplied matrix to the identity matrix.static float[]translation(float x, float y, float z) Returns a translation matrix.
-
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 ofsrcintodst. Both arrays must hold 16 floats. -
multiply
public static void multiply(float[] a, float[] b, float[] dst) Multipliesa * band stores the result indst.dstmay not aliasaorb. -
perspective
public static float[] perspective(float fovYRadians, float aspect, float near, float far) Builds a perspective projection matrix.fovYRadiansis the vertical field of view in radians,aspectthe 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.angleRadiansis 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 ofm, expanded to a 4x4. This is the correct matrix for transforming normals. Returns the identity whenmis not invertible. -
invert
public static boolean invert(float[] m, float[] dst) Invertsmintodst. Returns false (leavingdstuntouched) when the matrix is singular.
-