-
Notifications
You must be signed in to change notification settings - Fork 0
Matrix Types
ExodusCoder9 edited this page Jun 20, 2026
·
1 revision
Matrices are mutable classes with fluent return this setters for performance.
| Type | Size | Precision |
|---|---|---|
Matrix2d / Matrix2f
|
2×2 | double / float |
Matrix3d / Matrix3f
|
3×3 | double / float |
Matrix4d / Matrix4f
|
4×4 | double / float |
Matrix4x3d / Matrix4x3f
|
4×3 (affine) | double / float |
Matrix4f m = new Matrix4f(); // identity
Matrix4f m = new Matrix4f(src); // copy
Matrix4f m = new Matrix4f(float[] arr); // from array
Matrix4f m = new Matrix4f(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
); // from components
Transformations
m.identity();
m.translate(1, 2, 3);
m.rotateX((float) Math.PI / 4);
m.rotateY((float) Math.PI / 4);
m.rotateZ((float) Math.PI / 4);
m.scale(2, 2, 2);
m.rotate(q); // from quaternion
m.rotateXYZ(x, y, z); // Euler angles
m.rotateZYX(z, y, x); // Euler angles (ZYX order)
Projection / View
// Perspective (OpenGL)
m.perspective(fovY, aspect, zNear, zFar);
// Perspective (Vulkan — z=[0,1])
m.perspectiveVulkan(fovY, aspect, zNear, zFar);
// Orthographic (OpenGL)
m.ortho(left, right, bottom, top, zNear, zFar);
// Orthographic (Vulkan)
m.orthoVulkan(left, right, bottom, top, zNear, zFar);
// View matrix
m.lookAt(eye, center, up);
m.lookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
Multiply / Invert / Transpose
m.multiply(other);
m.mulAffine(other); // optimized for affine matrices
m.invert();
m.invertAffine(); // optimized for affine matrices
m.transpose();
m.transpose3x3();
m.adjugate();
Transform Vectors
Vector4f v4 = m.transform(v); // full 4-component
Vector3f pos = m.transformPosition(v); // w=1
Vector3f dir = m.transformDirection(v); // w=0
Vector3f proj = m.transformProject(v); // divide by w
Local-space Operations
m.translateLocal(x, y, z);
m.rotateLocalX(angle);
m.rotateLocalY(angle);
m.rotateLocalZ(angle);
m.scaleLocal(x, y, z);
Specialized Matrices (4×4)
m.billboard(objPos, target, up); // billboard towards camera
m.shadow(light, nx, ny, nz, d); // shadow projection
m.reflection(nx, ny, nz, d); // reflection plane
m.reflect(nx, ny, nz); // reflect current matrix
Static Factory Methods
Matrix4f.translation(x, y, z);
Matrix4f.rotationX(angle);
Matrix4f.rotationY(angle);
Matrix4f.rotationZ(angle);
Matrix4f.scaling(x, y, z);
Component Access
m.get(col, row);
m.set(col, row, value);
m.row(0); // returns Vector4f
m.column(0); // returns Vector4f
m.setRow(0, v);
m.setColumn(0, v);
m.getTranslation(); // returns Vector3f
m.getScale(); // returns Vector3f
m.getEulerAnglesZYX(); // returns Vector3f
m.positiveX(); // right vector
m.positiveY(); // up vector
m.positiveZ(); // forward vector
// Direct field access
m.m00(); m.m01(); ... m.m33();
m.m00(v); m.m01(v); ... m.m33(v); // fluent setters
Properties
m.determinant();
m.determinant3x3();
m.trace();
m.isIdentity();
m.isIdentity(epsilon);
m.isAffine();
m.isFinite();
Memory I/O
// NIO Buffer
FloatBuffer buf = FloatBuffer.allocate(16);
m.writeToBuffer(buf);
buf.flip();
Matrix4f back = Matrix4f.fromBuffer(buf);
// MemorySegment
m.get(segment, 0);
m.set(segment, 0);
Static Getter Methods
For reading individual matrix elements there are accessor methods:
double m00 = matrix.m00();
double m01 = matrix.m01();
double m10 = matrix.m10();
double m11 = matrix.m11();
// ... etc
And fluent setter methods:
matrix.m00(1.0f).m01(0.0f).m10(0.0f).m11(1.0f);