Package limn.math
Class MutMat4
java.lang.Object
limn.math.MutMat4
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatget(int row, int col) Element at (row, col).this = this · o(o applied first); seeMat4.multiply(limn.math.Mat4).this = this · o;o == thissquares the matrix.Copiessourceinto this matrix.Copiessourceinto this matrix (source == thisis a no-op).Resets to the identity matrix.setMultiply(Mat4 a, Mat4 b) this = a · b.setMultiply(Mat4 a, MutMat4 b) this = a · b.setMultiply(MutMat4 a, MutMat4 b) this = a · b; either argument may bethis.Sets this matrix to Translate · Rotate · Scale, the allocation-free equivalent ofMat4.trs(limn.math.Vec3, limn.math.Quat, limn.math.Vec3).voidtoArray(float[] out) Column-major copy intoout(length ≥ 16), the allocation-free upload path.toMat4()Immutable snapshot (allocates), for APIs that cacheMat4by identity.voidtransformDirection(float x, float y, float z, float[] out) Transforms direction (x,y,z, w=0) intoout(length ≥ 3); no translation, no divide.voidtransformPoint(float x, float y, float z, float[] out) Transforms position (x,y,z, w=1), applies the perspective divide and writes x/y/z intoout(length ≥ 3), the allocation-free equivalent ofMat4.transformPoint(limn.math.Vec3).
-
Constructor Details
-
MutMat4
public MutMat4()Starts at identity.
-
-
Method Details
-
get
public float get(int row, int col) Element at (row, col). -
setIdentity
Resets to the identity matrix. -
set
Copiessourceinto this matrix. -
set
Copiessourceinto this matrix (source == thisis a no-op). -
setTrs
Sets this matrix to Translate · Rotate · Scale, the allocation-free equivalent ofMat4.trs(limn.math.Vec3, limn.math.Quat, limn.math.Vec3).rotationmust be unit length. -
mul
this = this · o(o applied first); seeMat4.multiply(limn.math.Mat4). -
mul
this = this · o;o == thissquares the matrix. -
setMultiply
this = a · b; either argument may bethis. -
setMultiply
this = a · b. -
setMultiply
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 intoout(length ≥ 3), the allocation-free equivalent ofMat4.transformPoint(limn.math.Vec3). -
transformDirection
public void transformDirection(float x, float y, float z, float[] out) Transforms direction (x,y,z, w=0) intoout(length ≥ 3); no translation, no divide. -
toMat4
Immutable snapshot (allocates), for APIs that cacheMat4by identity. -
toArray
public void toArray(float[] out) Column-major copy intoout(length ≥ 16), the allocation-free upload path.
-