Show / Hide Table of Contents

Struct Matrix4d

Represents a 4x4 matrix containing 3D rotation, scale, transform, and projection with double-precision components.

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

Constructors

Matrix4d(Matrix3d)

Initializes a new instance of the Matrix4d struct.

Declaration
public Matrix4d(Matrix3d topLeft)
Parameters
Type Name Description
Matrix3d topLeft

The top left 3x3 of the matrix.

Matrix4d(Vector4d, Vector4d, Vector4d, Vector4d)

Initializes a new instance of the Matrix4d struct.

Declaration
public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
Parameters
Type Name Description
Vector4d row0

Top row of the matrix.

Vector4d row1

Second row of the matrix.

Vector4d row2

Third row of the matrix.

Vector4d row3

Bottom row of the matrix.

Matrix4d(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)

Initializes a new instance of the Matrix4d struct.

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

First item of the first row.

double m01

Second item of the first row.

double m02

Third item of the first row.

double m03

Fourth item of the first row.

double m10

First item of the second row.

double m11

Second item of the second row.

double m12

Third item of the second row.

double m13

Fourth item of the second row.

double m20

First item of the third row.

double m21

Second item of the third row.

double m22

Third item of the third row.

double m23

Fourth item of the third row.

double m30

First item of the fourth row.

double m31

Second item of the fourth row.

double m32

Third item of the fourth row.

double m33

Fourth item of the fourth row.

Fields

Identity

The identity matrix.

Declaration
public static readonly Matrix4d Identity
Field Value
Type Description
Matrix4d

Row0

Top row of the matrix.

Declaration
public Vector4d Row0
Field Value
Type Description
Vector4d

Row1

2nd row of the matrix.

Declaration
public Vector4d Row1
Field Value
Type Description
Vector4d

Row2

3rd row of the matrix.

Declaration
public Vector4d Row2
Field Value
Type Description
Vector4d

Row3

Bottom row of the matrix.

Declaration
public Vector4d Row3
Field Value
Type Description
Vector4d

Zero

The zero matrix.

Declaration
public static readonly Matrix4d Zero
Field Value
Type Description
Matrix4d

Properties

Column0

Gets or sets the first column of this matrix.

Declaration
public Vector4d Column0 { readonly get; set; }
Property Value
Type Description
Vector4d

Column1

Gets or sets the second column of this matrix.

Declaration
public Vector4d Column1 { readonly get; set; }
Property Value
Type Description
Vector4d

Column2

Gets or sets the third column of this matrix.

Declaration
public Vector4d Column2 { readonly get; set; }
Property Value
Type Description
Vector4d

Column3

Gets or sets the fourth column of this matrix.

Declaration
public Vector4d Column3 { readonly get; set; }
Property Value
Type Description
Vector4d

Determinant

Gets the determinant of this matrix.

Declaration
public readonly double Determinant { get; }
Property Value
Type Description
double

Diagonal

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

Declaration
public Vector4d Diagonal { readonly get; set; }
Property Value
Type Description
Vector4d

this[int, int]

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

Declaration
public double 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
double

The element at the given row and column index.

M11

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

Declaration
public double M11 { readonly get; set; }
Property Value
Type Description
double

M12

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

Declaration
public double M12 { readonly get; set; }
Property Value
Type Description
double

M13

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

Declaration
public double M13 { readonly get; set; }
Property Value
Type Description
double

M14

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

Declaration
public double M14 { readonly get; set; }
Property Value
Type Description
double

M21

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

Declaration
public double M21 { readonly get; set; }
Property Value
Type Description
double

M22

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

Declaration
public double M22 { readonly get; set; }
Property Value
Type Description
double

M23

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

Declaration
public double M23 { readonly get; set; }
Property Value
Type Description
double

M24

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

Declaration
public double M24 { readonly get; set; }
Property Value
Type Description
double

M31

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

Declaration
public double M31 { readonly get; set; }
Property Value
Type Description
double

M32

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

Declaration
public double M32 { readonly get; set; }
Property Value
Type Description
double

M33

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

Declaration
public double M33 { readonly get; set; }
Property Value
Type Description
double

M34

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

Declaration
public double M34 { readonly get; set; }
Property Value
Type Description
double

M41

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

Declaration
public double M41 { readonly get; set; }
Property Value
Type Description
double

M42

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

Declaration
public double M42 { readonly get; set; }
Property Value
Type Description
double

M43

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

Declaration
public double M43 { readonly get; set; }
Property Value
Type Description
double

M44

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

Declaration
public double M44 { readonly get; set; }
Property Value
Type Description
double

Trace

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

Declaration
public readonly double Trace { get; }
Property Value
Type Description
double

Methods

Add(Matrix4d, Matrix4d)

Adds two instances.

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

The left operand of the addition.

Matrix4d right

The right operand of the addition.

Returns
Type Description
Matrix4d

A new instance that is the result of the addition.

Add(in Matrix4d, in Matrix4d, out Matrix4d)

Adds two instances.

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

The left operand of the addition.

Matrix4d right

The right operand of the addition.

Matrix4d result

A new instance that is the result of the addition.

ClearProjection()

Returns a copy of this Matrix4d without projection.

Declaration
public readonly Matrix4d ClearProjection()
Returns
Type Description
Matrix4d

The matrix without projection.

ClearRotation()

Returns a copy of this Matrix4d without rotation.

Declaration
public readonly Matrix4d ClearRotation()
Returns
Type Description
Matrix4d

The matrix without rotation.

ClearScale()

Returns a copy of this Matrix4d without scale.

Declaration
public readonly Matrix4d ClearScale()
Returns
Type Description
Matrix4d

The matrix without scaling.

ClearTranslation()

Returns a copy of this Matrix4d without translation.

Declaration
public readonly Matrix4d ClearTranslation()
Returns
Type Description
Matrix4d

The matrix without translation.

CreateFromAxisAngle(Vector3d, double)

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

Declaration
[Pure]
public static Matrix4d CreateFromAxisAngle(Vector3d axis, double angle)
Parameters
Type Name Description
Vector3d axis

The axis to rotate about.

double angle

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

Returns
Type Description
Matrix4d

A matrix instance.

CreateFromAxisAngle(Vector3d, double, out Matrix4d)

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

Declaration
public static void CreateFromAxisAngle(Vector3d axis, double angle, out Matrix4d result)
Parameters
Type Name Description
Vector3d axis

The axis to rotate about.

double angle

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

Matrix4d result

A matrix instance.

CreateFromQuaternion(Quaterniond)

Builds a rotation matrix from a quaternion.

Declaration
[Pure]
public static Matrix4d CreateFromQuaternion(Quaterniond q)
Parameters
Type Name Description
Quaterniond q

The quaternion to rotate by.

Returns
Type Description
Matrix4d

A matrix instance.

CreateFromQuaternion(in Quaterniond, out Matrix4d)

Build a rotation matrix from the specified quaternion.

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

Quaternion to translate.

Matrix4d result

Matrix result.

CreateOrthographic(double, double, double, double)

Creates an orthographic projection matrix.

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

The width of the projection volume.

double height

The height of the projection volume.

double depthNear

The near edge of the projection volume.

double depthFar

The far edge of the projection volume.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateOrthographic(double, double, double, double, out Matrix4d)

Creates an orthographic projection matrix.

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

The width of the projection volume.

double height

The height of the projection volume.

double depthNear

The near edge of the projection volume.

double depthFar

The far edge of the projection volume.

Matrix4d result

The resulting Matrix4d instance.

CreateOrthographicOffCenter(double, double, double, double, double, double)

Creates an orthographic projection matrix.

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

The left edge of the projection volume.

double right

The right edge of the projection volume.

double bottom

The bottom edge of the projection volume.

double top

The top edge of the projection volume.

double depthNear

The near edge of the projection volume.

double depthFar

The far edge of the projection volume.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateOrthographicOffCenter(double, double, double, double, double, double, out Matrix4d)

Creates an orthographic projection matrix.

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

The left edge of the projection volume.

double right

The right edge of the projection volume.

double bottom

The bottom edge of the projection volume.

double top

The top edge of the projection volume.

double depthNear

The near edge of the projection volume.

double depthFar

The far edge of the projection volume.

Matrix4d result

The resulting Matrix4d instance.

CreatePerspectiveFieldOfView(double, double, double, double)

Creates a perspective projection matrix.

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

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

double aspect

Aspect ratio of the view (width / height).

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4d

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

CreatePerspectiveFieldOfView(double, double, double, double, out Matrix4d)

Creates a perspective projection matrix.

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

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

double aspect

Aspect ratio of the view (width / height).

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Matrix4d 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

CreatePerspectiveOffCenter(double, double, double, double, double, double)

Creates an perspective projection matrix.

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

Left edge of the view frustum.

double right

Right edge of the view frustum.

double bottom

Bottom edge of the view frustum.

double top

Top edge of the view frustum.

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4d

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

CreatePerspectiveOffCenter(double, double, double, double, double, double, out Matrix4d)

Creates an perspective projection matrix.

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

Left edge of the view frustum.

double right

Right edge of the view frustum.

double bottom

Bottom edge of the view frustum.

double top

Top edge of the view frustum.

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Matrix4d 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

CreateRotationX(double)

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

Declaration
[Pure]
public static Matrix4d CreateRotationX(double angle)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateRotationX(double, out Matrix4d)

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

Declaration
public static void CreateRotationX(double angle, out Matrix4d result)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Matrix4d result

The resulting Matrix4d instance.

CreateRotationY(double)

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

Declaration
[Pure]
public static Matrix4d CreateRotationY(double angle)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateRotationY(double, out Matrix4d)

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

Declaration
public static void CreateRotationY(double angle, out Matrix4d result)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Matrix4d result

The resulting Matrix4d instance.

CreateRotationZ(double)

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

Declaration
[Pure]
public static Matrix4d CreateRotationZ(double angle)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateRotationZ(double, out Matrix4d)

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

Declaration
public static void CreateRotationZ(double angle, out Matrix4d result)
Parameters
Type Name Description
double angle

The counter-clockwise angle in radians.

Matrix4d result

The resulting Matrix4d instance.

CreateScale(Vector3d)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix4d CreateScale(Vector3d scale)
Parameters
Type Name Description
Vector3d scale

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

Returns
Type Description
Matrix4d

A scale matrix.

CreateScale(in Vector3d, out Matrix4d)

Creates a scale matrix.

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

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

Matrix4d result

A scale matrix.

CreateScale(double)

Creates a scale matrix.

Declaration
[Pure]
public static Matrix4d CreateScale(double scale)
Parameters
Type Name Description
double scale

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

Returns
Type Description
Matrix4d

A scale matrix.

CreateScale(double, out Matrix4d)

Creates a scale matrix.

Declaration
public static void CreateScale(double scale, out Matrix4d result)
Parameters
Type Name Description
double scale

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

Matrix4d result

A scale matrix.

CreateScale(double, double, double)

Creates a scale matrix.

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

Scale factor for the x axis.

double y

Scale factor for the y axis.

double z

Scale factor for the z axis.

Returns
Type Description
Matrix4d

A scale matrix.

CreateScale(double, double, double, out Matrix4d)

Creates a scale matrix.

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

Scale factor for the x axis.

double y

Scale factor for the y axis.

double z

Scale factor for the z axis.

Matrix4d result

A scale matrix.

CreateSwizzle(int, int, int, int)

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

Declaration
public static Matrix4d 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
Matrix4d

The resulting swizzle matrix.

Remarks

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

CreateSwizzle(int, int, int, int, out Matrix4d)

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 Matrix4d 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.

Matrix4d result

The resulting swizzle matrix.

Remarks

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

CreateTranslation(Vector3d)

Creates a translation matrix.

Declaration
[Pure]
public static Matrix4d CreateTranslation(Vector3d vector)
Parameters
Type Name Description
Vector3d vector

The translation vector.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateTranslation(in Vector3d, out Matrix4d)

Creates a translation matrix.

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

The translation vector.

Matrix4d result

The resulting Matrix4d instance.

CreateTranslation(double, double, double)

Creates a translation matrix.

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

X translation.

double y

Y translation.

double z

Z translation.

Returns
Type Description
Matrix4d

The resulting Matrix4d instance.

CreateTranslation(double, double, double, out Matrix4d)

Creates a translation matrix.

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

X translation.

double y

Y translation.

double z

Z translation.

Matrix4d result

The resulting Matrix4d instance.

Equals(Matrix4d)

Indicates whether the current matrix is equal to another matrix.

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

A matrix to compare with this matrix.

Returns
Type Description
bool

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

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 to.

Returns
Type Description
bool

True if the instances are equal; false otherwise.

Overrides
ValueType.Equals(object)

ExtractProjection()

Returns the projection component of this instance.

Declaration
public readonly Vector4d ExtractProjection()
Returns
Type Description
Vector4d

The projection.

ExtractRotation(bool)

Returns the rotation component of this instance. Quite slow.

Declaration
[Pure]
public readonly Quaterniond 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
Quaterniond

The rotation.

ExtractScale()

Returns the scale component of this instance.

Declaration
public readonly Vector3d ExtractScale()
Returns
Type Description
Vector3d

The scale.

ExtractTranslation()

Returns the translation component of this instance.

Declaration
public readonly Vector3d ExtractTranslation()
Returns
Type Description
Vector3d

The translation.

Frustum(double, double, double, double, double, double)

Build a projection matrix.

Declaration
[Pure]
[Obsolete("Use CreatePerspectiveOffCenter instead.")]
public static Matrix4d Frustum(double left, double right, double bottom, double top, double depthNear, double depthFar)
Parameters
Type Name Description
double left

Left edge of the view frustum.

double right

Right edge of the view frustum.

double bottom

Bottom edge of the view frustum.

double top

Top edge of the view frustum.

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4d

A projection matrix that transforms camera space to raster space.

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()

Invert()

Converts this instance into its inverse.

Declaration
public void Invert()

Invert(in Matrix4d)

Calculate the inverse of the given matrix.

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

The matrix to invert.

Returns
Type Description
Matrix4d

The inverse of the given matrix.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix4d is singular.

Invert(in Matrix4d, out Matrix4d)

Calculate the inverse of the given matrix.

Declaration
[Pure]
public static void Invert(in Matrix4d mat, out Matrix4d result)
Parameters
Type Name Description
Matrix4d mat

The matrix to invert.

Matrix4d result

The inverted matrix.

Exceptions
Type Condition
InvalidOperationException

Thrown if the Matrix4d is singular.

Inverted()

Returns an inverted copy of this instance.

Declaration
public readonly Matrix4d Inverted()
Returns
Type Description
Matrix4d

The inverted copy.

Remarks

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

LookAt(Vector3d, Vector3d, Vector3d)

Build a world space to camera space matrix.

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

Eye (camera) position in world space.

Vector3d target

Target position in world space.

Vector3d up

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

Returns
Type Description
Matrix4d

A Matrix that transforms world space to camera space.

LookAt(double, double, double, double, double, double, double, double, double)

Build a world space to camera space matrix.

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

Eye (camera) X-position in world space.

double eyeY

Eye (camera) Y-position in world space.

double eyeZ

Eye (camera) Z-position in world space.

double targetX

Target X-position in world space.

double targetY

Target Y-position in world space.

double targetZ

Target Z-position in world space.

double upX

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

double upY

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

double upZ

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

Returns
Type Description
Matrix4d

A Matrix4 that transforms world space to camera space.

Mult(Matrix4d, Matrix4d)

Multiplies two instances.

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

The left operand of the multiplication.

Matrix4d right

The right operand of the multiplication.

Returns
Type Description
Matrix4d

A new instance that is the result of the multiplication.

Mult(Matrix4d, double)

Multiplies an instance by a scalar.

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

The left operand of the multiplication.

double right

The right operand of the multiplication.

Returns
Type Description
Matrix4d

A new instance that is the result of the multiplication.

Mult(in Matrix4d, in Matrix4d, out Matrix4d)

Multiplies two instances.

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

The left operand of the multiplication.

Matrix4d right

The right operand of the multiplication.

Matrix4d result

A new instance that is the result of the multiplication.

Mult(in Matrix4d, double, out Matrix4d)

Multiplies an instance by a scalar.

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

The left operand of the multiplication.

double right

The right operand of the multiplication.

Matrix4d result

A new instance that is the result of the multiplication.

Normalize()

Divides each element in the Matrix by the Determinant.

Declaration
public void Normalize()

Normalized()

Returns a normalized copy of this instance.

Declaration
public readonly Matrix4d Normalized()
Returns
Type Description
Matrix4d

The normalized copy.

Perspective(double, double, double, double)

Build a projection matrix.

Declaration
[Pure]
[Obsolete("Use CreatePerspectiveFieldOfView instead.")]
public static Matrix4d Perspective(double fovy, double aspect, double depthNear, double depthFar)
Parameters
Type Name Description
double fovy

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

double aspect

Aspect ratio of the view (width / height).

double depthNear

Distance to the near clip plane.

double depthFar

Distance to the far clip plane.

Returns
Type Description
Matrix4d

A projection matrix that transforms camera space to raster space.

Rotate(Quaterniond)

Build a rotation matrix from a quaternion.

Declaration
[Pure]
[Obsolete("Use CreateFromQuaternion instead.")]
public static Matrix4d Rotate(Quaterniond q)
Parameters
Type Name Description
Quaterniond q

The quaternion.

Returns
Type Description
Matrix4d

A rotation matrix.

Rotate(Vector3d, double)

Build a rotation matrix to rotate about the given axis.

Declaration
[Pure]
[Obsolete("Use CreateFromAxisAngle instead.")]
public static Matrix4d Rotate(Vector3d axis, double angle)
Parameters
Type Name Description
Vector3d axis

The axis to rotate about.

double angle

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

Returns
Type Description
Matrix4d

A rotation matrix.

RotateX(double)

Build a rotation matrix that rotates about the x-axis.

Declaration
[Pure]
[Obsolete("Use CreateRotationX instead.")]
public static Matrix4d RotateX(double angle)
Parameters
Type Name Description
double angle

The angle in radians to rotate counter-clockwise around the x-axis.

Returns
Type Description
Matrix4d

A rotation matrix.

RotateY(double)

Build a rotation matrix that rotates about the y-axis.

Declaration
[Pure]
[Obsolete("Use CreateRotationY instead.")]
public static Matrix4d RotateY(double angle)
Parameters
Type Name Description
double angle

The angle in radians to rotate counter-clockwise around the y-axis.

Returns
Type Description
Matrix4d

A rotation matrix.

RotateZ(double)

Build a rotation matrix that rotates about the z-axis.

Declaration
[Pure]
[Obsolete("Use CreateRotationZ instead.")]
public static Matrix4d RotateZ(double angle)
Parameters
Type Name Description
double angle

The angle in radians to rotate counter-clockwise around the z-axis.

Returns
Type Description
Matrix4d

A rotation matrix.

Scale(Vector3d)

Build a scaling matrix.

Declaration
[Pure]
[Obsolete("Use CreateScale instead.")]
public static Matrix4d Scale(Vector3d scale)
Parameters
Type Name Description
Vector3d scale

Scale factors for x,y and z axes.

Returns
Type Description
Matrix4d

A scaling matrix.

Scale(double)

Build a scaling matrix.

Declaration
[Pure]
[Obsolete("Use CreateScale instead.")]
public static Matrix4d Scale(double scale)
Parameters
Type Name Description
double scale

Single scale factor for x,y and z axes.

Returns
Type Description
Matrix4d

A scaling matrix.

Scale(double, double, double)

Build a scaling matrix.

Declaration
[Pure]
[Obsolete("Use CreateScale instead.")]
public static Matrix4d Scale(double x, double y, double z)
Parameters
Type Name Description
double x

Scale factor for x-axis.

double y

Scale factor for y-axis.

double z

Scale factor for z-axis.

Returns
Type Description
Matrix4d

A scaling matrix.

Subtract(Matrix4d, Matrix4d)

Subtracts one instance from another.

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

The left operand of the subraction.

Matrix4d right

The right operand of the subraction.

Returns
Type Description
Matrix4d

A new instance that is the result of the subraction.

Subtract(in Matrix4d, in Matrix4d, out Matrix4d)

Subtracts one instance from another.

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

The left operand of the subraction.

Matrix4d right

The right operand of the subraction.

Matrix4d result

A new instance that is the result of the subraction.

Swizzle(Matrix4d, int, int, int, int)

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

Declaration
public static Matrix4d Swizzle(Matrix4d mat, int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3)
Parameters
Type Name Description
Matrix4d 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
Matrix4d

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

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

Swizzle(in Matrix4d, int, int, int, int, out Matrix4d)

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

Declaration
public static void Swizzle(in Matrix4d mat, int rowForRow0, int rowForRow1, int rowForRow2, int rowForRow3, out Matrix4d result)
Parameters
Type Name Description
Matrix4d 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.

Matrix4d result

The swizzled matrix.

Exceptions
Type Condition
IndexOutOfRangeException

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

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.

Swizzled(int, int, int, int)

Returns a swizzled copy of this instance.

Declaration
public readonly Matrix4d 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
Matrix4d

The swizzled copy.

ToString()

Returns the fully qualified type name of this instance.

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

The fully qualified type name.

Overrides
ValueType.ToString()

ToString(IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
Type Name Description
IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string, IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

Transpose()

Converts this instance into its transpose.

Declaration
public void Transpose()

Transpose(Matrix4d)

Calculate the transpose of the given matrix.

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

The matrix to transpose.

Returns
Type Description
Matrix4d

The transpose of the given matrix.

Transpose(in Matrix4d, out Matrix4d)

Calculate the transpose of the given matrix.

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

The matrix to transpose.

Matrix4d result

The result of the calculation.

Transposed()

Returns a transposed copy of this instance.

Declaration
public readonly Matrix4d Transposed()
Returns
Type Description
Matrix4d

The transposed copy.

Operators

operator +(Matrix4d, Matrix4d)

Matrix addition.

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

left-hand operand.

Matrix4d right

right-hand operand.

Returns
Type Description
Matrix4d

A new Matrix4d which holds the result of the addition.

operator ==(Matrix4d, Matrix4d)

Compares two instances for equality.

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

The first instance.

Matrix4d right

The second instance.

Returns
Type Description
bool

True, if left equals right; false otherwise.

operator !=(Matrix4d, Matrix4d)

Compares two instances for inequality.

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

The first instance.

Matrix4d right

The second instance.

Returns
Type Description
bool

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

operator *(Matrix4d, Matrix4d)

Matrix multiplication.

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

left-hand operand.

Matrix4d right

right-hand operand.

Returns
Type Description
Matrix4d

A new Matrix4d which holds the result of the multiplication.

operator *(Matrix4d, double)

Matrix-scalar multiplication.

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

left-hand operand.

double right

right-hand operand.

Returns
Type Description
Matrix4d

A new Matrix4d which holds the result of the multiplication.

operator -(Matrix4d, Matrix4d)

Matrix subtraction.

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

left-hand operand.

Matrix4d right

right-hand operand.

Returns
Type Description
Matrix4d

A new Matrix4d which holds the result of the subtraction.

Implements

IEquatable<T>
IFormattable

See Also

Matrix4
In this article
Back to top Generated by DocFX