Table of Contents

Struct Matrix4x4

Namespace
Xui.Core.Math3D
Assembly
Xui.Core.dll

Represents a 4×4 column-major transformation matrix for 3D geometry.

public struct Matrix4x4
Inherited Members

Remarks

Vectors and points are treated as column vectors and transformed by pre-multiplication: v' = M * v. Translation is stored in the last column (M14, M24, M34).

The matrix is stored in row-major memory order (M_row_col) as 16 sequential floats (64 bytes), fitting exactly into four 128-bit SIMD registers.

To interoperate with Matrix4x4 (which uses row-vector convention) use the explicit cast operators, which perform the necessary transpose.

Constructors

Matrix4x4(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)

Initializes a new Matrix4x4 with the specified row-ordered coefficients.

public Matrix4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)

Parameters

m11 float
m12 float
m13 float
m14 float
m21 float
m22 float
m23 float
m24 float
m31 float
m32 float
m33 float
m34 float
m41 float
m42 float
m43 float
m44 float

Fields

Identity

The identity matrix.

public static readonly Matrix4x4 Identity

Field Value

Matrix4x4

M11

Row 1, Column 1 — X basis X component (scale X for pure-scale matrices).

public float M11

Field Value

float

M12

Row 1, Column 2 — X basis Y shear.

public float M12

Field Value

float

M13

Row 1, Column 3 — X basis Z shear.

public float M13

Field Value

float

M14

Row 1, Column 4 — Translation along X.

public float M14

Field Value

float

M21

Row 2, Column 1 — Y basis X shear.

public float M21

Field Value

float

M22

Row 2, Column 2 — Y basis Y component (scale Y for pure-scale matrices).

public float M22

Field Value

float

M23

Row 2, Column 3 — Y basis Z shear.

public float M23

Field Value

float

M24

Row 2, Column 4 — Translation along Y.

public float M24

Field Value

float

M31

Row 3, Column 1 — Z basis X shear.

public float M31

Field Value

float

M32

Row 3, Column 2 — Z basis Y shear.

public float M32

Field Value

float

M33

Row 3, Column 3 — Z basis Z component (scale Z for pure-scale matrices).

public float M33

Field Value

float

M34

Row 3, Column 4 — Translation along Z.

public float M34

Field Value

float

M41

Row 4, Column 1 — Perspective X component (0 for affine transforms).

public float M41

Field Value

float

M42

Row 4, Column 2 — Perspective Y component (0 for affine transforms).

public float M42

Field Value

float

M43

Row 4, Column 3 — Perspective Z component (0 for affine transforms).

public float M43

Field Value

float

M44

Row 4, Column 4 — Homogeneous W scale (1 for affine transforms).

public float M44

Field Value

float

Properties

Determinant

Returns the determinant of the matrix. A determinant of zero means the matrix is not invertible.

public float Determinant { get; }

Property Value

float

Inverse

Returns the inverse of this matrix.

public Matrix4x4 Inverse { get; }

Property Value

Matrix4x4

Remarks

For rotation-only or TRS (translation-rotation-scale) matrices, consider computing the inverse analytically for better performance. Throws a division-by-zero style error if the matrix is singular (determinant ≈ 0).

IsIdentity

Returns true when this matrix equals the identity matrix.

public bool IsIdentity { get; }

Property Value

bool

Transposed

Returns the transpose of this matrix (swaps rows and columns).

public Matrix4x4 Transposed { get; }

Property Value

Matrix4x4

Methods

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(Matrix4x4)

Returns true if this matrix equals another Matrix4x4.

public bool Equals(Matrix4x4 other)

Parameters

other Matrix4x4

Returns

bool

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

LookAt(Point3, Point3, Vector3)

Creates a look-at view matrix (right-handed coordinate system).

public static Matrix4x4 LookAt(Point3 eye, Point3 target, Vector3 up)

Parameters

eye Point3

The position of the camera.

target Point3

The position the camera is looking at.

up Vector3

The world up direction (typically Up).

Returns

Matrix4x4

Orthographic(float, float, float, float)

Creates a symmetric orthographic projection matrix (right-handed, depth range [-1, 1]).

public static Matrix4x4 Orthographic(float width, float height, float near, float far)

Parameters

width float

The width of the view volume.

height float

The height of the view volume.

near float

Distance to the near clipping plane.

far float

Distance to the far clipping plane.

Returns

Matrix4x4

Perspective(float, float, float, float)

Creates a symmetric perspective projection matrix (right-handed, depth range [-1, 1]).

public static Matrix4x4 Perspective(float fovY, float aspect, float near, float far)

Parameters

fovY float

Vertical field of view in radians.

aspect float

Aspect ratio (width / height).

near float

Distance to the near clipping plane (must be positive).

far float

Distance to the far clipping plane (must be greater than near).

Returns

Matrix4x4

Rotate(Quaternion)

Creates a rotation matrix from a unit quaternion.

public static Matrix4x4 Rotate(Quaternion q)

Parameters

q Quaternion

Returns

Matrix4x4

RotateX(float)

Creates a rotation matrix around the X axis by the given angle in radians.

public static Matrix4x4 RotateX(float angle)

Parameters

angle float

Returns

Matrix4x4

RotateY(float)

Creates a rotation matrix around the Y axis by the given angle in radians.

public static Matrix4x4 RotateY(float angle)

Parameters

angle float

Returns

Matrix4x4

RotateZ(float)

Creates a rotation matrix around the Z axis by the given angle in radians.

public static Matrix4x4 RotateZ(float angle)

Parameters

angle float

Returns

Matrix4x4

Scale(float)

Creates a uniform scale matrix.

public static Matrix4x4 Scale(float s)

Parameters

s float

Returns

Matrix4x4

Scale(Vector3)

Creates a non-uniform scale matrix.

public static Matrix4x4 Scale(Vector3 v)

Parameters

v Vector3

Returns

Matrix4x4

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Translate(Vector3)

Creates a translation matrix that moves a point by the given vector.

public static Matrix4x4 Translate(Vector3 v)

Parameters

v Vector3

Returns

Matrix4x4

Operators

operator ==(Matrix4x4, Matrix4x4)

Returns true if two matrices have equal coefficients.

public static bool operator ==(Matrix4x4 lhs, Matrix4x4 rhs)

Parameters

lhs Matrix4x4
rhs Matrix4x4

Returns

bool

explicit operator Matrix4x4(Matrix4x4)

Explicitly converts from a Matrix4x4.

public static explicit operator Matrix4x4(Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Matrix4x4

Remarks

Matrix4x4 uses row-vector convention. This conversion transposes the input matrix so that it works correctly with the column-vector convention used by this type.

explicit operator Matrix4x4(Matrix4x4)

Explicitly converts to a Matrix4x4.

public static explicit operator Matrix4x4(Matrix4x4 m)

Parameters

m Matrix4x4

Returns

Matrix4x4

Remarks

Matrix4x4 uses row-vector convention, which is the transpose of the column-vector convention used by this type. The conversion transposes the matrix so that row-vector math on the result produces the same geometric transformation.

operator !=(Matrix4x4, Matrix4x4)

Returns true if any coefficient of two matrices differs.

public static bool operator !=(Matrix4x4 lhs, Matrix4x4 rhs)

Parameters

lhs Matrix4x4
rhs Matrix4x4

Returns

bool

operator *(Matrix4x4, Matrix4x4)

Composes two transformation matrices. The result applies rhs first, then lhs.

public static Matrix4x4 operator *(Matrix4x4 lhs, Matrix4x4 rhs)

Parameters

lhs Matrix4x4
rhs Matrix4x4

Returns

Matrix4x4

operator *(Matrix4x4, Point3)

Transforms a Point3 by this matrix, including the translation component. Use this for positions.

public static Point3 operator *(Matrix4x4 m, Point3 p)

Parameters

m Matrix4x4
p Point3

Returns

Point3

operator *(Matrix4x4, Vector3)

Transforms a Vector3 by this matrix, ignoring the translation component. Use this for directions and normals.

public static Vector3 operator *(Matrix4x4 m, Vector3 v)

Parameters

m Matrix4x4
v Vector3

Returns

Vector3