Matrix4x4

csharp
public struct Matrix4x4 : IEquatable<Matrix4x4>, IFormattable

Namespace NodeWorld.Flux.

A 4x4 matrix, mRC = row R, column C, stored column after column (as Unity's). Points are column vectors: M * p.

Fields

m00

csharp
public float m00

The value at row 0, column 0.

m10

csharp
public float m10

The value at row 1, column 0.

m20

csharp
public float m20

The value at row 2, column 0.

m30

csharp
public float m30

The value at row 3, column 0.

m01

csharp
public float m01

The value at row 0, column 1.

m11

csharp
public float m11

The value at row 1, column 1.

m21

csharp
public float m21

The value at row 2, column 1.

m31

csharp
public float m31

The value at row 3, column 1.

m02

csharp
public float m02

The value at row 0, column 2.

m12

csharp
public float m12

The value at row 1, column 2.

m22

csharp
public float m22

The value at row 2, column 2.

m32

csharp
public float m32

The value at row 3, column 2.

m03

csharp
public float m03

The value at row 0, column 3.

m13

csharp
public float m13

The value at row 1, column 3.

m23

csharp
public float m23

The value at row 2, column 3.

m33

csharp
public float m33

The value at row 3, column 3.

Constructors

Matrix4x4

csharp
public Matrix4x4(Vector4 column0, Vector4 column1, Vector4 column2, Vector4 column3)

The matrix of these four columns.

Properties

this[]

csharp
public float this[int row, int column] { get; set; }

The value at row and column (0 to 3).

csharp
public float this[int index] { get; set; }

The value at index 0 to 15, column after column (index = row + column * 4).

zero

csharp
public static Matrix4x4 zero { get; }

Every value 0.

identity

csharp
public static Matrix4x4 identity { get; }

The identity matrix: 1 on the diagonal.

isIdentity

csharp
public bool isIdentity { get; }

The matrix is the identity.

transpose

csharp
public Matrix4x4 transpose { get; }

The matrix with rows and columns swapped.

determinant

csharp
public float determinant { get; }

The determinant.

inverse

csharp
public Matrix4x4 inverse { get; }

The inverse (cofactors / determinant); the zero matrix if the matrix is singular.

rotation

csharp
public Quaternion rotation { get; }

The rotation part (the upper 3x3 without its scale).

lossyScale

csharp
public Vector3 lossyScale { get; }

The scale of the upper 3x3 (length of its columns, negative if the matrix mirrors).

Methods

GetColumn

csharp
public Vector4 GetColumn(int index)

The column index (0 to 3).

GetRow

csharp
public Vector4 GetRow(int index)

The row index (0 to 3).

SetColumn

csharp
public void SetColumn(int index, Vector4 column)

Sets the column index (0 to 3).

SetRow

csharp
public void SetRow(int index, Vector4 row)

Sets the row index (0 to 3).

GetPosition

csharp
public Vector3 GetPosition()

The translation part: m03, m13, m23.

MultiplyPoint

csharp
public Vector3 MultiplyPoint(Vector3 point)

Transforms a point, with the projective divide.

MultiplyPoint3x4

csharp
public Vector3 MultiplyPoint3x4(Vector3 point)

Transforms a point by an affine matrix (no projective divide).

MultiplyVector

csharp
public Vector3 MultiplyVector(Vector3 vector)

Transforms a direction (rotation and scale only).

Transpose

csharp
public static Matrix4x4 Transpose(Matrix4x4 m)

m with rows and columns swapped.

Determinant

csharp
public static float Determinant(Matrix4x4 m)

The determinant of m.

Inverse

csharp
public static Matrix4x4 Inverse(Matrix4x4 m)

The inverse of m; the zero matrix if m is singular.

TRS

csharp
public static Matrix4x4 TRS(Vector3 pos, Quaternion q, Vector3 s)

Translation, rotation and scale: T * R * S.

SetTRS

csharp
public void SetTRS(Vector3 pos, Quaternion q, Vector3 s)

Makes it TRS(pos, q, s).

Translate

csharp
public static Matrix4x4 Translate(Vector3 vector)

A translation matrix.

Rotate

csharp
public static Matrix4x4 Rotate(Quaternion q)

A rotation matrix.

Scale

csharp
public static Matrix4x4 Scale(Vector3 vector)

A scale matrix.

Perspective

csharp
public static Matrix4x4 Perspective(float fov, float aspect, float zNear, float zFar)

Perspective projection (clip space z from -1 to 1, as OpenGL and Unity's matrices).

Ortho

csharp
public static Matrix4x4 Ortho(float left, float right, float bottom, float top, float zNear, float zFar)

Orthographic projection (clip space z from -1 to 1, as Perspective).

LookAt

csharp
public static Matrix4x4 LookAt(Vector3 from, Vector3 to, Vector3 up)

A matrix placing an object at "from", its forward (z) towards "to".

Equals

csharp
public bool Equals(Matrix4x4 other)

The sixteen values are exactly equal.

csharp
public override bool Equals(object other)

other is a matrix with exactly the same values.

GetHashCode

csharp
public override int GetHashCode()

A hash of the values.

ToString

csharp
public override string ToString()

The four rows, values separated by tabs, with 5 decimals.

csharp
public string ToString(string format)

The same text with the numbers in format.

csharp
public string ToString(string format, IFormatProvider formatProvider)

The same text with the numbers in format (F5 when empty) and formatProvider (the invariant culture when null).

Operators

operator *

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

The product lhs * rhs: rhs applies first.

csharp
public static Vector4 operator *(Matrix4x4 lhs, Vector4 v)

The matrix times the column vector v.

operator ==

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

Every column equal (as Vector4's ==).

operator !=

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

The matrices differ (see ==).