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 TypeMethodDescriptionstatic Mat4affine2D(float a, float b, float c, float d, float e, float f) The 2D affine mapx' = a·x + c·y + e,y' = b·x + d·y + fof the plane, as a matrix whose z row and column are the identity's: the six numbers in the order a 2D canvas's or a vector drawing's matrix lists them.floatget(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 Mat4perspectiveAt(float distance) A perspective seen from an eyedistancein front of the planez = 0, on the z axis, z running toward the viewer: a point is divided by1 − z / distance, so the plane itself is left where it is, a point nearer the eye is drawn larger and farther from the axis, and one at the eye or past it has no place in front of it (wnot above 0).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. -
affine2D
The 2D affine mapx' = a·x + c·y + e,y' = b·x + d·y + fof the plane, as a matrix whose z row and column are the identity's: the six numbers in the order a 2D canvas's or a vector drawing's matrix lists them. A skew along x by an angle θ isaffine2D(1, 0, tan θ, 1, 0, 0).- Parameters:
a- how far x moves along x per unit of xb- how far y moves per unit of xc- how far x moves per unit of yd- how far y moves per unit of ye- the translation along xf- the translation along y- Returns:
- the matrix
-
perspectiveAt
A perspective seen from an eyedistancein front of the planez = 0, on the z axis, z running toward the viewer: a point is divided by1 − z / distance, so the plane itself is left where it is, a point nearer the eye is drawn larger and farther from the axis, and one at the eye or past it has no place in front of it (wnot above 0). The vanishing point is the origin; a translation before this matrix moves it. Unlikeperspective(float, float, float, float), a camera's projection into clip space, it keeps the units it is given, which is what a picture turned in depth about a point of a window needs. An infinite distance is no perspective, the identity.- Parameters:
distance- how far the eye is from the plane, in the plane's own units- Returns:
- the perspective
- Throws:
IllegalArgumentException- ifdistanceis not above 0, or isNaN
-
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
-