Package limn.math

Class MutMat4

java.lang.Object
limn.math.MutMat4

public final class MutMat4 extends Object
A mutable column-major 4×4 matrix (m[col*4 + row], same conventions as Mat4) for allocation-free transform composition in hot loops.

Mat4 stays the API currency (immutable, safe to cache and share), and its per-operation allocation is fine at UI scale. At game scale (recomposing thousands of entity transforms at 60 fps) those temporaries become GC pressure; a MutMat4 is reused across frames and every operation writes in place:


 MutMat4 world = new MutMat4();            // once, outside the loop
 world.set(parentWorld).mul(local);        // per entity, zero allocation
 world.toArray(scratch);                   // upload, zero allocation
 

toMat4() snapshots into an immutable Mat4 (one allocation) for hand-off to APIs that cache by instance identity. Not thread-safe; confine an instance to one thread (in practice: the UI thread).

  • Constructor Details

    • MutMat4

      public MutMat4()
      Starts at identity.
  • Method Details

    • get

      public float get(int row, int col)
      Element at (row, col).
    • setIdentity

      public MutMat4 setIdentity()
      Resets to the identity matrix.
    • set

      public MutMat4 set(Mat4 source)
      Copies source into this matrix.
    • set

      public MutMat4 set(MutMat4 source)
      Copies source into this matrix (source == this is a no-op).
    • setTrs

      public MutMat4 setTrs(Vec3 translation, Quat rotation, Vec3 scale)
      Sets this matrix to Translate · Rotate · Scale, the allocation-free equivalent of Mat4.trs(limn.math.Vec3, limn.math.Quat, limn.math.Vec3). rotation must be unit length.
    • mul

      public MutMat4 mul(Mat4 o)
      this = this · o (o applied first); see Mat4.multiply(limn.math.Mat4).
    • mul

      public MutMat4 mul(MutMat4 o)
      this = this · o; o == this squares the matrix.
    • setMultiply

      public MutMat4 setMultiply(MutMat4 a, MutMat4 b)
      this = a · b; either argument may be this.
    • setMultiply

      public MutMat4 setMultiply(Mat4 a, Mat4 b)
      this = a · b.
    • setMultiply

      public MutMat4 setMultiply(Mat4 a, MutMat4 b)
      this = a · b.
    • transformPoint

      public void transformPoint(float x, float y, float z, float[] out)
      Transforms position (x, y, z, w=1), applies the perspective divide and writes x/y/z into out (length ≥ 3), the allocation-free equivalent of Mat4.transformPoint(limn.math.Vec3).
    • transformDirection

      public void transformDirection(float x, float y, float z, float[] out)
      Transforms direction (x, y, z, w=0) into out (length ≥ 3); no translation, no divide.
    • toMat4

      public Mat4 toMat4()
      Immutable snapshot (allocates), for APIs that cache Mat4 by identity.
    • toArray

      public void toArray(float[] out)
      Column-major copy into out (length ≥ 16), the allocation-free upload path.