Show / Hide Table of Contents

Struct Matrix4

Represents a 4x4 matrix containing 3D rotation, scale, transform, and projection.

Implements
IEquatable<Matrix4>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Matrix4 : IEquatable<Matrix4>, IFormattable

Constructors

Matrix4(Matrix3)

Initializes a new instance of the Matrix4 struct.

Declaration
public Matrix4(Matrix3 topLeft)
Parameters
Type Name Description
Matrix3 topLeft

The top left 3x3 of the matrix.

See Also
Matrix4d

Matrix4(Vector4, Vector4, Vector4, Vector4)

Initializes a new instance of the Matrix4 struct.

Declaration
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
Parameters
Type Name Description
Vector4 row0

Top row of the matrix.

Vector4 row1

Second row of the matrix.

Vector4 row2

Third row of the matrix.

Vector4 row3

Bottom row of the matrix.

See Also
Matrix4d

Matrix4(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)

Initializes a new instance of the Matrix4 struct.

Declaration
public Matrix4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Parameters
Type Name Description
float m00

First item of the first row of the matrix.

float m01

Second item of the first row of the matrix.

float m02

Third item of the first row of the matrix.

float m03

Fourth item of the first row of the matrix.

float m10

First item of the second row of the matrix.

float m11

Second item of the second row of the matrix.

float m12

Third item of the second row of the matrix.

float m13

Fourth item of the second row of the matrix.

float m20

First item of the third row of the matrix.

float m21

Second item of the third row of the matrix.

float m22

Third item of the third row of the matrix.

float m23

Fourth item of the third row of the matrix.

float m30

First item of the fourth row of the matrix.

float m31

Second item of the fourth row of the matrix.

float m32

Third item of the fourth row of the matrix.

float m33

Fourth item of the fourth row of the matrix.

See Also
Matrix4d

Fields

Identity

The identity matrix.

Declaration
public static readonly Matrix4 Identity
Field Value
Type Description
Matrix4
See Also
Matrix4d

Row0

Top row of the matrix.

Declaration
public Vector4 Row0
Field Value
Type Description
Vector4
See Also
Matrix4d

Row1

2nd row of the matrix.

Declaration
public Vector4 Row1
Field Value
Type Description
Vector4
See Also
Matrix4d

Row2

3rd row of the matrix.

Declaration
public Vector4 Row2
Field Value
Type Description
Vector4
See Also
Matrix4d

Row3

Bottom row of the matrix.

Declaration
public Vector4 Row3
Field Value
Type Description
Vector4
See Also
Matrix4d

Zero

The zero matrix.

Declaration
public static readonly Matrix4 Zero
Field Value
Type Description
Matrix4
See Also
Matrix4d

Properties

Column0

Gets or sets the first column of this matrix.

Declaration
public Vector4 Column0 { readonly get; set; }
Property Value
Type Description
Vector4
See Also
Matrix4d

Column1

Gets or sets the second column of this matrix.

Declaration
public Vector4 Column1 { readonly get; set; }
Property Value
Type Description
Vector4
See Also
Matrix4d

Column2

Gets or sets the third column of this matrix.

Declaration
public Vector4 Column2 { readonly get; set; }
Property Value
Type Description
Vector4
See Also
Matrix4d

Column3

Gets or sets the fourth column of this matrix.

Declaration
public Vector4 Column3 { readonly get; set; }
Property Value
Type Description
Vector4
See Also
Matrix4d

Determinant

Gets the determinant of this matrix.

Declaration
public readonly float Determinant { get; }
Property Value
Type Description
float
See Also
Matrix4d

Diagonal

Gets or sets the values along the main diagonal of the matrix.

Declaration
public Vector4 Diagonal { readonly get; set; }
Property Value
Type Description
Vector4
See Also
Matrix4d

this[int, int]

Gets or sets the value at a specified row and column.

Declaration
public float this[int rowIndex, int columnIndex] { readonly get; set; }
Parameters
Type Name Description
int rowIndex

The index of the row.

int columnIndex

The index of the column.

Property Value
Type Description
float

The element at the given row and column index.

See Also
Matrix4d

M11

Gets or sets the value at row 1, column 1 of this instance.

Declaration
public float M11 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M12

Gets or sets the value at row 1, column 2 of this instance.

Declaration
public float M12 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M13

Gets or sets the value at row 1, column 3 of this instance.

Declaration
public float M13 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M14

Gets or sets the value at row 1, column 4 of this instance.

Declaration
public float M14 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M21

Gets or sets the value at row 2, column 1 of this instance.

Declaration
public float M21 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M22

Gets or sets the value at row 2, column 2 of this instance.

Declaration
public float M22 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M23

Gets or sets the value at row 2, column 3 of this instance.

Declaration
public float M23 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M24

Gets or sets the value at row 2, column 4 of this instance.

Declaration
public float M24 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M31

Gets or sets the value at row 3, column 1 of this instance.

Declaration
public float M31 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M32

Gets or sets the value at row 3, column 2 of this instance.

Declaration
public float M32 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M33

Gets or sets the value at row 3, column 3 of this instance.

Declaration
public float M33 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M34

Gets or sets the value at row 3, column 4 of this instance.

Declaration
public float M34 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M41

Gets or sets the value at row 4, column 1 of this instance.

Declaration
public float M41 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M42

Gets or sets the value at row 4, column 2 of this instance.

Declaration
public float M42 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M43

Gets or sets the value at row 4, column 3 of this instance.

Declaration
public float M43 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

M44

Gets or sets the value at row 4, column 4 of this instance.

Declaration
public float M44 { readonly get; set; }
Property Value
Type Description
float
See Also
Matrix4d

Trace

Gets the trace of the matrix, the sum of the values along the diagonal.

Declaration
public readonly float Trace { get; }
Property Value
Type Description
float
See Also
Matrix4d

Methods

Add(Matrix4, Matrix4)

Adds two instances.

Declaration
[Pure]
public static Matrix4 Add(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

The left operand of the addition.

Matrix4 right

The right operand of the addition.

Returns
Type Description
Matrix4

A new instance that is the result of the addition.

See Also
Matrix4d

Add(in Matrix4, in Matrix4, out Matrix4)

Adds two instances.

Declaration
public static void Add(in Matrix4 left, in Matrix4 right, out Matrix4 result)
Parameters
Type Name Description
Matrix4 left

The left operand of the addition.

Matrix4 right

The right operand of the addition.

Matrix4 result

A new instance that is the result of the addition.

See Also
Matrix4d

ClearProjection()

Returns a copy of this Matrix4 without projection. (equivalent to setting Column3 = (0, 0, 0, 0)).

Declaration
[Obsolete("This function doesn't actually clear the projection of the matrix. This is equivalent of setting Column3 = (0, 0, 0, 0).")]
public readonly Matrix4 ClearProjection()
Returns
Type Description
Matrix4

The matrix without projection.

See Also
Matrix4d

ClearRotation()

Returns a copy of this Matrix4 without rotation.

Declaration
public readonly Matrix4 ClearRotation()
Returns
Type Description
Matrix4

The matrix without rotation.

See Also
Matrix4d

ClearScale()

Returns a copy of this Matrix4 without scale.

Declaration
public readonly Matrix4 ClearScale()
Returns
Type Description
Matrix4

The matrix without scaling.

See Also
Matrix4d

ClearTranslation()

Returns a copy of this Matrix4 without translation.

Declaration
public readonly Matrix4 ClearTranslation()
Returns
Type Description
Matrix4

The matrix without translation.

See Also
Matrix4d

CreateFromAxisAngle(Vector3, float, out Matrix4)

Build a rotation matrix from the specified axis/angle rotation.

Declaration
public static void CreateFromAxisAngle(Vector3 axis, float angle, out Matrix4 result)
Parameters
Type Name Description
Vector3 axis

The axis to rotate about.

float angle

Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).

Matrix4 result

A matrix instance.

See Also
Matrix4d

CreateFromAxisAngle(Vector3, float)

Build a rotation matrix from the specified axis/angle rotation.

Declaration
[Pure]
public static Matrix4 CreateFromAxisAngle(Vector3 axis, float angle)
Parameters
Type Name Description
Vector3 axis

The axis to rotate about.

float angle

Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).

Returns
Type Description
Matrix4

A matrix instance.

See Also
Matrix4d

CreateFromQuaternion(Quaternion)

Builds a rotation matrix from a quaternion.

Declaration
[Pure]
public static Matrix4 CreateFromQuaternion(Quaternion q)
Parameters
Type Name Description
Quaternion q

The quaternion to rotate by.

Returns
Type Description
Matrix4

A matrix instance.

See Also
Matrix4d

CreateFromQuaternion(in Quaternion, out Matrix4)

Builds a rotation matrix from a quaternion.

Declaration
public static void CreateFromQuaternion(in Quaternion q, out Matrix4 result)
Parameters
Type Name Description
Quaternion q

The quaternion to rotate by.

Matrix4 result

A matrix instance.

See Also
Matrix4d

CreateOrthographic(float, float, float, float, out Matrix4)

Creates an orthographic projection matrix.

Declaration
public static void CreateOrthographic(float width, float height, float depthNear, float depthFar, out Matrix4 result)
Parameters
Type Name Description
float width

The width of the projection volume.

float height

The height of the projection volume.

float depthNear

The near edge of the projection volume.

float depthFar

The far edge of the projection volume.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateOrthographic(float, float, float, float)

Creates an orthographic projection matrix.

Declaration
[Pure]
public static Matrix4 CreateOrthographic(float width, float height, float depthNear, float depthFar)
Parameters
Type Name Description
float width

The width of the projection volume.

float height

The height of the projection volume.

float depthNear

The near edge of the projection volume.

float depthFar

The far edge of the projection volume.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreateOrthographicOffCenter(float, float, float, float, float, float, out Matrix4)

Creates an orthographic projection matrix.

Declaration
public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, float depthNear, float depthFar, out Matrix4 result)
Parameters
Type Name Description
float left

The left edge of the projection volume.

float right

The right edge of the projection volume.

float bottom

The bottom edge of the projection volume.

float top

The top edge of the projection volume.

float depthNear

The near edge of the projection volume.

float depthFar

The far edge of the projection volume.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateOrthographicOffCenter(float, float, float, float, float, float)

Creates an orthographic projection matrix.

Declaration
[Pure]
public static Matrix4 CreateOrthographicOffCenter(float left, float right, float bottom, float top, float depthNear, float depthFar)
Parameters
Type Name Description
float left

The left edge of the projection volume.

float right

The right edge of the projection volume.

float bottom

The bottom edge of the projection volume.

float top

The top edge of the projection volume.

float depthNear

The near edge of the projection volume.

float depthFar

The far edge of the projection volume.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreatePerspectiveFieldOfView(float, float, float, float, out Matrix4)

Creates a perspective projection matrix.

Declaration
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float depthNear, float depthFar, out Matrix4 result)
Parameters
Type Name Description
float fovy

Angle of the field of view in the y direction (in radians).

float aspect

Aspect ratio of the view (width / height).

float depthNear

Distance to the near clip plane.

float depthFar

Distance to the far clip plane.

Matrix4 result

A projection matrix that transforms camera space to raster space.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown under the following conditions:

  • fovy is zero, less than zero or larger than Math.PI
  • aspect is negative or zero
  • depthNear is negative or zero
  • depthFar is negative or zero
  • depthNear is larger than depthFar
See Also
Matrix4d

CreatePerspectiveFieldOfView(float, float, float, float)

Creates a perspective projection matrix.

Declaration
[Pure]
public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float depthNear, float depthFar)
Parameters
Type Name Description
float fovy

Angle of the field of view in the y direction (in radians).

float aspect

Aspect ratio of the view (width / height).

float depthNear

Distance to the near clip plane.

float depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4

A projection matrix that transforms camera space to raster space.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown under the following conditions:

  • fovy is zero, less than zero or larger than Math.PI
  • aspect is negative or zero
  • depthNear is negative or zero
  • depthFar is negative or zero
  • depthNear is larger than depthFar
See Also
Matrix4d

CreatePerspectiveOffCenter(float, float, float, float, float, float, out Matrix4)

Creates an perspective projection matrix.

Declaration
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float depthNear, float depthFar, out Matrix4 result)
Parameters
Type Name Description
float left

Left edge of the view frustum.

float right

Right edge of the view frustum.

float bottom

Bottom edge of the view frustum.

float top

Top edge of the view frustum.

float depthNear

Distance to the near clip plane.

float depthFar

Distance to the far clip plane.

Matrix4 result

A projection matrix that transforms camera space to raster space.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown under the following conditions:

  • depthNear is negative or zero
  • depthFar is negative or zero
  • depthNear is larger than depthFar
See Also
Matrix4d

CreatePerspectiveOffCenter(float, float, float, float, float, float)

Creates an perspective projection matrix.

Declaration
[Pure]
public static Matrix4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float depthNear, float depthFar)
Parameters
Type Name Description
float left

Left edge of the view frustum.

float right

Right edge of the view frustum.

float bottom

Bottom edge of the view frustum.

float top

Top edge of the view frustum.

float depthNear

Distance to the near clip plane.

float depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4

A projection matrix that transforms camera space to raster space.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown under the following conditions:

  • depthNear is negative or zero
  • depthFar is negative or zero
  • depthNear is larger than depthFar
See Also
Matrix4d

CreateRotationX(float, out Matrix4)

Builds a rotation matrix for a rotation around the x-axis.

Declaration
public static void CreateRotationX(float angle, out Matrix4 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateRotationX(float)

Builds a rotation matrix for a rotation around the x-axis.

Declaration
[Pure]
public static Matrix4 CreateRotationX(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreateRotationY(float, out Matrix4)

Builds a rotation matrix for a rotation around the y-axis.

Declaration
public static void CreateRotationY(float angle, out Matrix4 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateRotationY(float)

Builds a rotation matrix for a rotation around the y-axis.

Declaration
[Pure]
public static Matrix4 CreateRotationY(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreateRotationZ(float, out Matrix4)

Builds a rotation matrix for a rotation around the z-axis.

Declaration
public static void CreateRotationZ(float angle, out Matrix4 result)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateRotationZ(float)

Builds a rotation matrix for a rotation around the z-axis.

Declaration
[Pure]
public static Matrix4 CreateRotationZ(float angle)
Parameters
Type Name Description
float angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreateScale(Vector3)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix4 CreateScale(Vector3 scale)
Parameters
Type Name Description
Vector3 scale

Scale factors for the x, y, and z axes.

Returns
Type Description
Matrix4

A scale matrix.

See Also
Matrix4d

CreateScale(in Vector3, out Matrix4)

Creates a scale matrix.

Declaration
public static void CreateScale(in Vector3 scale, out Matrix4 result)
Parameters
Type Name Description
Vector3 scale

Scale factors for the x, y, and z axes.

Matrix4 result

A scale matrix.

See Also
Matrix4d

CreateScale(float, out Matrix4)

Creates a scale matrix.

Declaration
public static void CreateScale(float scale, out Matrix4 result)
Parameters
Type Name Description
float scale

Single scale factor for the x, y, and z axes.

Matrix4 result

A scale matrix.

See Also
Matrix4d

CreateScale(float, float, float, out Matrix4)

Creates a scale matrix.

Declaration
public static void CreateScale(float x, float y, float z, out Matrix4 result)
Parameters
Type Name Description
float x

Scale factor for the x axis.

float y

Scale factor for the y axis.

float z

Scale factor for the z axis.

Matrix4 result

A scale matrix.

See Also
Matrix4d

CreateScale(float, float, float)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix4 CreateScale(float x, float y, float z)
Parameters
Type Name Description
float x

Scale factor for the x axis.

float y

Scale factor for the y axis.

float z

Scale factor for the z axis.

Returns
Type Description
Matrix4

A scale matrix.

See Also
Matrix4d

CreateScale(float)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix4 CreateScale(float scale)
Parameters
Type Name Description
float scale

Single scale factor for the x, y, and z axes.

Returns
Type Description
Matrix4

A scale matrix.

See Also
Matrix4d

CreateSwizzle(int, int, int, int, out Matrix4)

Create a swizzle matrix that can be used to change the row order of matrices.

Declaration
public static void CreateSwizzle(int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3, out Matrix4 result)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

Matrix4 result

The resulting swizzle matrix.

Remarks

If you are looking to swizzle vectors there are properties like Zyx that can do this more effectively.

See Also
Matrix4d

CreateSwizzle(int, int, int, int)

Create a swizzle matrix that can be used to change the row order of matrices.

Declaration
public static Matrix4 CreateSwizzle(int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

Returns
Type Description
Matrix4

The resulting swizzle matrix.

Remarks

If you are looking to swizzle vectors there are properties like Zyx that can do this more effectively.

See Also
Matrix4d

CreateTranslation(Vector3)

Creates a translation matrix.

Declaration
[Pure]
public static Matrix4 CreateTranslation(Vector3 vector)
Parameters
Type Name Description
Vector3 vector

The translation vector.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

CreateTranslation(in Vector3, out Matrix4)

Creates a translation matrix.

Declaration
public static void CreateTranslation(in Vector3 vector, out Matrix4 result)
Parameters
Type Name Description
Vector3 vector

The translation vector.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateTranslation(float, float, float, out Matrix4)

Creates a translation matrix.

Declaration
public static void CreateTranslation(float x, float y, float z, out Matrix4 result)
Parameters
Type Name Description
float x

X translation.

float y

Y translation.

float z

Z translation.

Matrix4 result

The resulting Matrix4 instance.

See Also
Matrix4d

CreateTranslation(float, float, float)

Creates a translation matrix.

Declaration
[Pure]
public static Matrix4 CreateTranslation(float x, float y, float z)
Parameters
Type Name Description
float x

X translation.

float y

Y translation.

float z

Z translation.

Returns
Type Description
Matrix4

The resulting Matrix4 instance.

See Also
Matrix4d

Equals(Matrix4)

Indicates whether the current matrix is equal to another matrix.

Declaration
[Pure]
public readonly bool Equals(Matrix4 other)
Parameters
Type Name Description
Matrix4 other

An matrix to compare with this matrix.

Returns
Type Description
bool

true if the current matrix is equal to the matrix parameter; otherwise, false.

See Also
Matrix4d

Equals(object)

Indicates whether this instance and a specified object are equal.

Declaration
[Pure]
public override readonly bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare tresult.

Returns
Type Description
bool

True if the instances are equal; false otherwise.

Overrides
ValueType.Equals(object)
See Also
Matrix4d

ExtractOrthographic(out float, out float, out float, out float)

Returns the orthographic projection parameters of this instance. This only works if the matrix was created using CreateOrthographic(float, float, float, float).

Declaration
public readonly void ExtractOrthographic(out float width, out float height, out float depthNear, out float depthFar)
Parameters
Type Name Description
float width

The width of the projection volume.

float height

The height of the projection volume.

float depthNear

The distance to the near clip plane.

float depthFar

The distance to the far clip plane.

See Also
Matrix4d

ExtractOrthographicOffCenter(out float, out float, out float, out float, out float, out float)

Returns the off-center orthographic projection parameters of this instance. This only works if the matrix was created using CreateOrthographicOffCenter(float, float, float, float, float, float).

Declaration
public readonly void ExtractOrthographicOffCenter(out float left, out float right, out float bottom, out float top, out float depthNear, out float depthFar)
Parameters
Type Name Description
float left

The left edge of the projection volume.

float right

The right edge of the projection volume.

float bottom

The bottom edge of the projection volume.

float top

The top edge of the projection volume.

float depthNear

The distance to the near clip plane.

float depthFar

The distance to the far clip plane.

See Also
Matrix4d

ExtractPerspectiveFieldOfView(out float, out float, out float, out float)

Returns the field of view projection parameters of this instance. This only works if the matrix was created using CreatePerspectiveFieldOfView(float, float, float, float).

Declaration
public readonly void ExtractPerspectiveFieldOfView(out float fovy, out float aspect, out float depthNear, out float depthFar)
Parameters
Type Name Description
float fovy

Angle of the field of view in the y direction (in radians).

float aspect

Aspect ratio of the view (width / height).

float depthNear

The distance to the near clip plane.

float depthFar

The distance to the far clip plane.

See Also
Matrix4d

ExtractPerspectiveOffCenter(out float, out float, out float, out float, out float, out float)

Returns the off-center projection parameters of this instance. This only works if the matrix was created using CreatePerspectiveOffCenter(float, float, float, float, float, float).

Declaration
public readonly void ExtractPerspectiveOffCenter(out float left, out float right, out float bottom, out float top, out float depthNear, out float depthFar)
Parameters
Type Name Description
float left

The left edge of the view frustum.

float right

The right edge of the view frustum.

float bottom

The bottom edge of the view frustum.

float top

The top edge of the view frustum.

float depthNear

The distance to the near clip plane.

float depthFar

The distance to the far clip plane.

See Also
Matrix4d

ExtractProjection()

Returns the projection component of this instance (equivalent to Column3).

Declaration
[Obsolete("Use Column3 if the old behaviour is needed, or use ExtractPerspective*() or ExtractOrthographic* instead.")]
public readonly Vector4 ExtractProjection()
Returns
Type Description
Vector4

The projection (Column3).

See Also
Matrix4d

ExtractRotation(bool)

Returns the rotation component of this instance. Quite slow.

Declaration
[Pure]
public readonly Quaternion ExtractRotation(bool rowNormalize = true)
Parameters
Type Name Description
bool rowNormalize

Whether the method should row-normalize (i.e. remove scale from) the Matrix. Pass false if you know it's already normalized.

Returns
Type Description
Quaternion

The rotation.

See Also
Matrix4d

ExtractScale()

Returns the scale component of this instance.

Declaration
public readonly Vector3 ExtractScale()
Returns
Type Description
Vector3

The scale.

See Also
Matrix4d

ExtractTranslation()

Returns the translation component of this instance.

Declaration
public readonly Vector3 ExtractTranslation()
Returns
Type Description
Vector3

The translation.

See Also
Matrix4d

GetHashCode()

Returns the hashcode for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int

A System.Int32 containing the unique hashcode for this instance.

Overrides
ValueType.GetHashCode()
See Also
Matrix4d

Invert()

Converts this instance into its inverse.

Declaration
public void Invert()
See Also
Matrix4d

Invert(Matrix4)

Calculate the inverse of the given matrix.

Declaration
[Pure]
public static Matrix4 Invert(Matrix4 mat)
Parameters
Type Name Description
Matrix4 mat

The matrix to invert.

Returns
Type Description
Matrix4

The inverse of the given matrix.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix4 is singular.

See Also
Matrix4d

Invert(in Matrix4, out Matrix4)

Calculate the inverse of the given matrix.

Declaration
public static void Invert(in Matrix4 mat, out Matrix4 result)
Parameters
Type Name Description
Matrix4 mat

The matrix to invert.

Matrix4 result

The inverse of the given matrix if it has one, or the input if it is singular.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix4 is singular.

See Also
Matrix4d

Inverted()

Returns an inverted copy of this instance.

Declaration
public readonly Matrix4 Inverted()
Returns
Type Description
Matrix4

The inverted copy.

Remarks

If the matrix is singular this function does not throw an exception, instead it returns the original un-inverted matrix.

See Also
Matrix4d

LookAt(Vector3, Vector3, Vector3)

Build a world space to camera space matrix.

Declaration
[Pure]
public static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
Parameters
Type Name Description
Vector3 eye

Eye (camera) position in world space.

Vector3 target

Target position in world space.

Vector3 up

Up vector in world space (should not be parallel to the camera direction, that is target - eye).

Returns
Type Description
Matrix4

A Matrix4 that transforms world space to camera space.

See Also
Matrix4d

LookAt(float, float, float, float, float, float, float, float, float)

Build a world space to camera space matrix.

Declaration
[Pure]
public static Matrix4 LookAt(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ)
Parameters
Type Name Description
float eyeX

Eye (camera) X-position in world space.

float eyeY

Eye (camera) Y-position in world space.

float eyeZ

Eye (camera) Z-position in world space.

float targetX

Target X-position in world space.

float targetY

Target Y-position in world space.

float targetZ

Target Z-position in world space.

float upX

X of the up vector in world space (should not be parallel to the camera direction, that is target - eye).

float upY

Y of the up vector in world space (should not be parallel to the camera direction, that is target - eye).

float upZ

Z of the up vector in world space (should not be parallel to the camera direction, that is target - eye).

Returns
Type Description
Matrix4

A Matrix4 that transforms world space to camera space.

See Also
Matrix4d

Mult(Matrix4, Matrix4)

Multiplies two instances.

Declaration
[Pure]
public static Matrix4 Mult(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

The left operand of the multiplication.

Matrix4 right

The right operand of the multiplication.

Returns
Type Description
Matrix4

A new instance that is the result of the multiplication.

See Also
Matrix4d

Mult(Matrix4, float)

Multiplies an instance by a scalar.

Declaration
[Pure]
public static Matrix4 Mult(Matrix4 left, float right)
Parameters
Type Name Description
Matrix4 left

The left operand of the multiplication.

float right

The right operand of the multiplication.

Returns
Type Description
Matrix4

A new instance that is the result of the multiplication.

See Also
Matrix4d

Mult(in Matrix4, in Matrix4, out Matrix4)

Multiplies two instances.

Declaration
public static void Mult(in Matrix4 left, in Matrix4 right, out Matrix4 result)
Parameters
Type Name Description
Matrix4 left

The left operand of the multiplication.

Matrix4 right

The right operand of the multiplication.

Matrix4 result

A new instance that is the result of the multiplication.

See Also
Matrix4d

Mult(in Matrix4, float, out Matrix4)

Multiplies an instance by a scalar.

Declaration
public static void Mult(in Matrix4 left, float right, out Matrix4 result)
Parameters
Type Name Description
Matrix4 left

The left operand of the multiplication.

float right

The right operand of the multiplication.

Matrix4 result

A new instance that is the result of the multiplication.

See Also
Matrix4d

Normalize()

Divides each element in the Matrix by the Determinant.

Declaration
public void Normalize()
See Also
Matrix4d

Normalized()

Returns a normalized copy of this instance.

Declaration
public readonly Matrix4 Normalized()
Returns
Type Description
Matrix4

The normalized copy.

See Also
Matrix4d

Subtract(Matrix4, Matrix4)

Subtracts one instance from another.

Declaration
[Pure]
public static Matrix4 Subtract(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

The left operand of the subraction.

Matrix4 right

The right operand of the subraction.

Returns
Type Description
Matrix4

A new instance that is the result of the subraction.

See Also
Matrix4d

Subtract(in Matrix4, in Matrix4, out Matrix4)

Subtracts one instance from another.

Declaration
public static void Subtract(in Matrix4 left, in Matrix4 right, out Matrix4 result)
Parameters
Type Name Description
Matrix4 left

The left operand of the subraction.

Matrix4 right

The right operand of the subraction.

Matrix4 result

A new instance that is the result of the subraction.

See Also
Matrix4d

Swizzle(Matrix4, int, int, int, int)

Swizzles a matrix, i.e. switches rows of the matrix.

Declaration
public static Matrix4 Swizzle(Matrix4 mat, int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3)
Parameters
Type Name Description
Matrix4 mat

The matrix to swizzle.

int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

Returns
Type Description
Matrix4

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

If any of the rows are outside of the range [0, 3].

See Also
Matrix4d

Swizzle(in Matrix4, int, int, int, int, out Matrix4)

Swizzles a matrix, i.e. switches rows of the matrix.

Declaration
public static void Swizzle(in Matrix4 mat, int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3, out Matrix4 result)
Parameters
Type Name Description
Matrix4 mat

The matrix to swizzle.

int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

Matrix4 result

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

If any of the rows are outside of the range [0, 3].

See Also
Matrix4d

Swizzle(int, int, int, int)

Swizzles this instance. Switches places of the rows of the matrix.

Declaration
public void Swizzle(int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

See Also
Matrix4d

Swizzled(int, int, int, int)

Returns a swizzled copy of this instance.

Declaration
public readonly Matrix4 Swizzled(int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3)
Parameters
Type Name Description
int rowForRow0

Which row to place in Row0.

int rowForRow1

Which row to place in Row1.

int rowForRow2

Which row to place in Row2.

int rowForRow3

Which row to place in Row3.

Returns
Type Description
Matrix4

The swizzled copy.

See Also
Matrix4d

ToString()

Returns a System.String that represents the current Matrix4.

Declaration
public override readonly string ToString()
Returns
Type Description
string

The string representation of the matrix.

Overrides
ValueType.ToString()
See Also
Matrix4d

ToString(IFormatProvider)

Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
Type Name Description
IFormatProvider formatProvider
Returns
Type Description
string
See Also
Matrix4d

ToString(string, IFormatProvider)

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format
IFormatProvider formatProvider
Returns
Type Description
string
See Also
Matrix4d

ToString(string)

Declaration
public readonly string ToString(string format)
Parameters
Type Name Description
string format
Returns
Type Description
string
See Also
Matrix4d

Transpose()

Converts this instance into its transpose.

Declaration
public void Transpose()
See Also
Matrix4d

Transpose(Matrix4)

Calculate the transpose of the given matrix.

Declaration
[Pure]
public static Matrix4 Transpose(Matrix4 mat)
Parameters
Type Name Description
Matrix4 mat

The matrix to transpose.

Returns
Type Description
Matrix4

The transpose of the given matrix.

See Also
Matrix4d

Transpose(in Matrix4, out Matrix4)

Calculate the transpose of the given matrix.

Declaration
public static void Transpose(in Matrix4 mat, out Matrix4 result)
Parameters
Type Name Description
Matrix4 mat

The matrix to transpose.

Matrix4 result

The result of the calculation.

See Also
Matrix4d

Transposed()

Returns a transposed copy of this instance.

Declaration
public readonly Matrix4 Transposed()
Returns
Type Description
Matrix4

The transposed copy.

See Also
Matrix4d

Operators

operator +(Matrix4, Matrix4)

Matrix addition.

Declaration
[Pure]
public static Matrix4 operator +(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

left-hand operand.

Matrix4 right

right-hand operand.

Returns
Type Description
Matrix4

A new Matrix4 which holds the result of the addition.

See Also
Matrix4d

operator ==(Matrix4, Matrix4)

Compares two instances for equality.

Declaration
[Pure]
public static bool operator ==(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

The first instance.

Matrix4 right

The second instance.

Returns
Type Description
bool

True, if left equals right; false otherwise.

See Also
Matrix4d

explicit operator Matrix4x4(Matrix4)

Converts Matrix4 to Matrix4x4.

Declaration
[Pure]
public static explicit operator Matrix4x4(Matrix4 mat)
Parameters
Type Name Description
Matrix4 mat

The Matrix4 to cast.

Returns
Type Description
Matrix4x4
See Also
Matrix4d

explicit operator Matrix4(Matrix4x4)

Converts Matrix4x4 to Matrix4.

Declaration
[Pure]
public static explicit operator Matrix4(Matrix4x4 mat)
Parameters
Type Name Description
Matrix4x4 mat

The Matrix4 to cast.

Returns
Type Description
Matrix4
See Also
Matrix4d

operator !=(Matrix4, Matrix4)

Compares two instances for inequality.

Declaration
[Pure]
public static bool operator !=(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

The first instance.

Matrix4 right

The second instance.

Returns
Type Description
bool

True, if left does not equal right; false otherwise.

See Also
Matrix4d

operator *(Matrix4, Matrix4)

Matrix multiplication.

Declaration
[Pure]
public static Matrix4 operator *(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

left-hand operand.

Matrix4 right

right-hand operand.

Returns
Type Description
Matrix4

A new Matrix4 which holds the result of the multiplication.

See Also
Matrix4d

operator *(Matrix4, float)

Matrix-scalar multiplication.

Declaration
[Pure]
public static Matrix4 operator *(Matrix4 left, float right)
Parameters
Type Name Description
Matrix4 left

left-hand operand.

float right

right-hand operand.

Returns
Type Description
Matrix4

A new Matrix4 which holds the result of the multiplication.

See Also
Matrix4d

operator -(Matrix4, Matrix4)

Matrix subtraction.

Declaration
[Pure]
public static Matrix4 operator -(Matrix4 left, Matrix4 right)
Parameters
Type Name Description
Matrix4 left

left-hand operand.

Matrix4 right

right-hand operand.

Returns
Type Description
Matrix4

A new Matrix4 which holds the result of the subtraction.

See Also
Matrix4d

Implements

IEquatable<T>
IFormattable

See Also

Matrix4d
In This Article
Back to top Generated by DocFX