Matrix4 — Aspose.3D FOSS for Java

Overview

Matrix4 is a 4x4 double-precision matrix used for affine transformations in 3D space. It is returned by Transform.getTransformMatrix() and GlobalTransform.getTransformMatrix(), and can be constructed from translation, rotation, and scale (TRS) decompositions.

Package: com.aspose.threed

import com.aspose.threed.*;

Constructor

SignatureDescription
Matrix4()Constructs an identity matrix
Matrix4(double m00, double m01, ... double m33)Constructs from 16 individual elements (row-major)

Static Fields

FieldTypeDescription
IDENTITYMatrix4The 4x4 identity matrix

Public Fields (Element Access)

Matrix4 uses public fields for element access: m00, m01, … m33 (16 fields total, row-major layout).

Field patternTypeDescription
m00m33doubleIndividual matrix elements as public fields. Access as mat.m00, mat.m01, etc.

Translation components are in the last column: m03 (X), m13 (Y), m23 (Z).

Methods

MethodReturn TypeDescription
multiply(Matrix4 other)Matrix4Matrix multiplication; returns a new matrix
inverse()Matrix4Returns the inverse matrix
transpose()Matrix4Returns the transposed matrix
decompose(Vector3 translation, Vector3 scaling, Quaternion rotation)booleanStub: always returns false. Intended to decompose the matrix into TRS components, but not yet implemented.
determinant()doubleReturns the determinant of the matrix
transformPoint(Vector3 point)Vector3Transforms a point (applies full translation + rotation + scale)
transformDirection(Vector3 direction)Vector3Transforms a direction vector (applies rotation + scale, ignores translation)

Static Methods

MethodReturn TypeDescription
Matrix4.translate(Vector3 t)Matrix4Creates a translation matrix
Matrix4.translate(double x, double y, double z)Matrix4Creates a translation matrix from components
Matrix4.scale(Vector3 s)Matrix4Creates a scale matrix
Matrix4.scale(double x, double y, double z)Matrix4Creates a scale matrix from components
Matrix4.rotateFromQuaternion(Quaternion q)Matrix4Creates a rotation matrix from a quaternion

Example

import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
node.getTransform().setTranslation(1.0, 2.0, 3.0);
node.getTransform().setEulerAngles(0.0, 45.0, 0.0);

// Read the transform matrix
Matrix4 m = node.getTransform().getTransformMatrix();
System.out.println("Translation X: " + m.m03);   // 1.0

// Matrix multiplication
Matrix4 translate = Matrix4.translate(5.0, 0.0, 0.0);
Matrix4 scale = Matrix4.scale(2.0, 2.0, 2.0);
Matrix4 combined = translate.multiply(scale);

// Inverse
Matrix4 inv = m.inverse();

// Transform a point
Vector3 point = new Vector3(1.0, 0.0, 0.0);
Vector3 transformed = m.transformPoint(point);
System.out.println(transformed);

See Also