Package limn.math

Class Mat4

java.lang.Object
limn.math.Mat4

public final class Mat4 extends Object
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
    Modifier and Type
    Field
    Description
    static final Mat4
    The identity matrix (immutable, so one shared instance serves everyone).
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    get(int row, int col)
    Element at (row, col).
    static Mat4
    The identity transform.
     
    static Mat4
    lookAt(Vec3 eye, Vec3 center, Vec3 up)
    A right-handed world-to-view matrix looking from eye at center.
    this · o.
    static void
    multiplyInto(Mat4 a, Mat4 b, float[] out)
    a · b written column-major into out (length ≥ 16).
    Normal matrix: transpose(inverse(upper-left 3×3)), for transforming normals.
    static void
    normalMatrixInto(Mat4 model, float[] out)
    The normal matrix of model, transpose(inverse(upper-left 3×3)), written column-major into out (length ≥ 9).
    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.
    static Mat4
    perspective(float fovyRadians, float aspect, float near, float far)
    Perspective projection; fovyRadians is the vertical field of view.
    static Mat4
    Rotation from a unit quaternion.
    static Mat4
    A pure non-uniform scale about the origin.
    float[]
    Column-major copy (length 16), for GPU upload.
    void
    toArray(float[] out)
    Column-major copy into out (length ≥ 16), the allocation-free upload path.
    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 Mat4
    A pure translation.
    The transpose: the inverse rotation, for a matrix that is purely a rotation.
    static Mat4
    trs(Vec3 t, Quat q, Vec3 s)
    Translate · Rotate · Scale, composed directly.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • IDENTITY

      public static final Mat4 IDENTITY
      The identity matrix (immutable, so one shared instance serves everyone).
  • Method Details

    • identity

      public static Mat4 identity()
      The identity transform.
    • translation

      public static Mat4 translation(Vec3 t)
      A pure translation.
    • scale

      public static Mat4 scale(Vec3 s)
      A pure non-uniform scale about the origin.
    • rotation

      public static Mat4 rotation(Quat q)
      Rotation from a unit quaternion.
    • trs

      public static Mat4 trs(Vec3 t, Quat q, Vec3 s)
      Translate · Rotate · Scale, composed directly.
    • perspective

      public static Mat4 perspective(float fovyRadians, float aspect, float near, float far)
      Perspective projection; fovyRadians is 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

      public static Mat4 lookAt(Vec3 eye, Vec3 center, Vec3 up)
      A right-handed world-to-view matrix looking from eye at center. up must 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

      public Mat4 multiply(Mat4 o)
      this · o.
    • transpose

      public Mat4 transpose()
      The transpose: the inverse rotation, for a matrix that is purely a rotation.
    • transform

      public Vec4 transform(Vec4 v)
      Transforms a homogeneous vector. No perspective divide: the caller does that.
    • transformPoint

      public Vec3 transformPoint(Vec3 p)
      Transforms a position (w=1) and applies the perspective divide.
    • transformDirection

      public Vec3 transformDirection(Vec3 d)
      Transforms a direction (w=0): no translation, no divide.
    • toMat3

      public Mat3 toMat3()
      Upper-left 3×3.
    • normalMatrix

      public Mat3 normalMatrix()
      Normal matrix: transpose(inverse(upper-left 3×3)), for transforming normals.
    • invert

      public Mat4 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 into out (length ≥ 16), the allocation-free upload path.
    • multiplyInto

      public static void multiplyInto(Mat4 a, Mat4 b, float[] out)
      a · b written column-major into out (length ≥ 16). Allocation-free.
    • normalMatrixInto

      public static void normalMatrixInto(Mat4 model, float[] out)
      The normal matrix of model, transpose(inverse(upper-left 3×3)), written column-major into out (length ≥ 9). Equals the cofactor matrix divided by the determinant, computed directly. Allocation-free.
      Throws:
      ArithmeticException - if the upper-left 3×3 is singular