Struct Matrix4
Represents a 4x4 matrix containing 3D rotation, scale, transform, and projection.
Inherited Members
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. |
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. |
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. |
Fields
Identity
The identity matrix.
Declaration
public static readonly Matrix4 Identity
Field Value
Type | Description |
---|---|
Matrix4 |
Row0
Top row of the matrix.
Declaration
public Vector4 Row0
Field Value
Type | Description |
---|---|
Vector4 |
Row1
2nd row of the matrix.
Declaration
public Vector4 Row1
Field Value
Type | Description |
---|---|
Vector4 |
Row2
3rd row of the matrix.
Declaration
public Vector4 Row2
Field Value
Type | Description |
---|---|
Vector4 |
Row3
Bottom row of the matrix.
Declaration
public Vector4 Row3
Field Value
Type | Description |
---|---|
Vector4 |
Zero
The zero matrix.
Declaration
public static readonly Matrix4 Zero
Field Value
Type | Description |
---|---|
Matrix4 |
Properties
Column0
Gets or sets the first column of this matrix.
Declaration
public Vector4 Column0 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector4 |
Column1
Gets or sets the second column of this matrix.
Declaration
public Vector4 Column1 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector4 |
Column2
Gets or sets the third column of this matrix.
Declaration
public Vector4 Column2 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector4 |
Column3
Gets or sets the fourth column of this matrix.
Declaration
public Vector4 Column3 { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector4 |
Determinant
Gets the determinant of this matrix.
Declaration
public readonly float Determinant { get; }
Property Value
Type | Description |
---|---|
float |
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 |
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. |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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. |
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. |
ClearProjection()
Returns a copy of this Matrix4 without projection.
Declaration
public readonly Matrix4 ClearProjection()
Returns
Type | Description |
---|---|
Matrix4 | The matrix without projection. |
ClearRotation()
Returns a copy of this Matrix4 without rotation.
Declaration
public readonly Matrix4 ClearRotation()
Returns
Type | Description |
---|---|
Matrix4 | The matrix without rotation. |
ClearScale()
Returns a copy of this Matrix4 without scale.
Declaration
public readonly Matrix4 ClearScale()
Returns
Type | Description |
---|---|
Matrix4 | The matrix without scaling. |
ClearTranslation()
Returns a copy of this Matrix4 without translation.
Declaration
public readonly Matrix4 ClearTranslation()
Returns
Type | Description |
---|---|
Matrix4 | The matrix without translation. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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:
|
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:
|
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:
|
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:
|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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.
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.
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. |
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. |
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. |
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. |
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. |
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
ExtractProjection()
Returns the projection component of this instance.
Declaration
public readonly Vector4 ExtractProjection()
Returns
Type | Description |
---|---|
Vector4 | The projection. |
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. |
ExtractScale()
Returns the scale component of this instance.
Declaration
public readonly Vector3 ExtractScale()
Returns
Type | Description |
---|---|
Vector3 | The scale. |
ExtractTranslation()
Returns the translation component of this instance.
Declaration
public readonly Vector3 ExtractTranslation()
Returns
Type | Description |
---|---|
Vector3 | The translation. |
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
Invert()
Converts this instance into its inverse.
Declaration
public void Invert()
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. |
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. |
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.
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. |
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. |
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. |
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. |
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. |
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. |
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 Matrix4 Normalized()
Returns
Type | Description |
---|---|
Matrix4 | The normalized copy. |
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. |
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. |
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]. |
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]. |
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 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. |
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
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 ( |
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 ( |
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 ( |
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
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(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. |
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. |
Transposed()
Returns a transposed copy of this instance.
Declaration
public readonly Matrix4 Transposed()
Returns
Type | Description |
---|---|
Matrix4 | The transposed copy. |
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. |
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. |
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. |
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. |
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. |
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. |