Package limn.math
Class Mat4
java.lang.Object
limn.math.Mat4
An immutable column-major 4×4 matrix (
m[col*4 + row], OpenGL
convention), single precision. Composition is a.multiply(b) = apply
b first, then a. Right-handed; clip-space z in [-1, 1].-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionfloatget(int row, int col) Element at (row, col).static Mat4identity()The identity transform.invert()static Mat4A right-handed world-to-view matrix looking fromeyeatcenter.this · o.static voidmultiplyInto(Mat4 a, Mat4 b, float[] out) a · bwritten column-major intoout(length ≥ 16).Normal matrix:transpose(inverse(upper-left 3×3)), for transforming normals.static voidnormalMatrixInto(Mat4 model, float[] out) The normal matrix ofmodel,transpose(inverse(upper-left 3×3)), written column-major intoout(length ≥ 9).static Mat4orthographic(float left, float right, float bottom, float top, float near, float far) An orthographic projection mapping the box to clip space with depth in[-1, 1]: the GL convention, not the[0, 1]one.static Mat4perspective(float fovyRadians, float aspect, float near, float far) Perspective projection;fovyRadiansis the vertical field of view.static Mat4Rotation from a unit quaternion.static Mat4A pure non-uniform scale about the origin.float[]toArray()Column-major copy (length 16), for GPU upload.voidtoArray(float[] out) Column-major copy intoout(length ≥ 16), the allocation-free upload path.toMat3()Upper-left 3×3.Transforms a homogeneous vector.Transforms a direction (w=0): no translation, no divide.Transforms a position (w=1) and applies the perspective divide.static Mat4translation(Vec3 t) A pure translation.The transpose: the inverse rotation, for a matrix that is purely a rotation.static Mat4Translate · Rotate · Scale, composed directly.
-
Field Details
-
IDENTITY
The identity matrix (immutable, so one shared instance serves everyone).
-
-
Method Details
-
identity
The identity transform. -
translation
A pure translation. -
scale
A pure non-uniform scale about the origin. -
rotation
Rotation from a unit quaternion. -
trs
Translate · Rotate · Scale, composed directly. -
perspective
Perspective projection;fovyRadiansis the vertical field of view. -
orthographic
public static Mat4 orthographic(float left, float right, float bottom, float top, float near, float far) An orthographic projection mapping the box to clip space with depth in[-1, 1]: the GL convention, not the[0, 1]one. -
lookAt
A right-handed world-to-view matrix looking fromeyeatcenter.upmust not be parallel to the view direction, which would leave the basis degenerate. -
get
public float get(int row, int col) Element at (row, col). -
multiply
this · o. -
transpose
The transpose: the inverse rotation, for a matrix that is purely a rotation. -
transform
Transforms a homogeneous vector. No perspective divide: the caller does that. -
transformPoint
Transforms a position (w=1) and applies the perspective divide. -
transformDirection
Transforms a direction (w=0): no translation, no divide. -
toMat3
Upper-left 3×3. -
normalMatrix
Normal matrix:transpose(inverse(upper-left 3×3)), for transforming normals. -
invert
- Throws:
ArithmeticException- if the matrix is singular. Gauss–Jordan with partial pivot.
-
toArray
public float[] toArray()Column-major copy (length 16), for GPU upload. -
toArray
public void toArray(float[] out) Column-major copy intoout(length ≥ 16), the allocation-free upload path. -
multiplyInto
a · bwritten column-major intoout(length ≥ 16). Allocation-free. -
normalMatrixInto
The normal matrix ofmodel,transpose(inverse(upper-left 3×3)), written column-major intoout(length ≥ 9). Equals the cofactor matrix divided by the determinant, computed directly. Allocation-free.- Throws:
ArithmeticException- if the upper-left 3×3 is singular
-