Struct Matrix4
Represents a 4x4 matrix containing 3D rotation, scale, transform, and projection.
Implements
Inherited Members
Namespace: OpenTK
Assembly: cs.temp.dll.dll
Syntax
[Serializable]
public struct Matrix4 : IEquatable<Matrix4>
Constructors
Matrix4(Matrix3)
Constructs a new instance.
Declaration
public Matrix4(Matrix3 topLeft)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix3 | topLeft | The top left 3x3 of the matrix. |
Matrix4(Vector4, Vector4, Vector4, Vector4)
Constructs a new instance.
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(Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single)
Constructs a new instance.
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 |
|---|---|---|
| System.Single | m00 | First item of the first row of the matrix. |
| System.Single | m01 | Second item of the first row of the matrix. |
| System.Single | m02 | Third item of the first row of the matrix. |
| System.Single | m03 | Fourth item of the first row of the matrix. |
| System.Single | m10 | First item of the second row of the matrix. |
| System.Single | m11 | Second item of the second row of the matrix. |
| System.Single | m12 | Third item of the second row of the matrix. |
| System.Single | m13 | Fourth item of the second row of the matrix. |
| System.Single | m20 | First item of the third row of the matrix. |
| System.Single | m21 | Second item of the third row of the matrix. |
| System.Single | m22 | Third item of the third row of the matrix. |
| System.Single | m23 | First item of the third row of the matrix. |
| System.Single | m30 | Fourth item of the fourth row of the matrix. |
| System.Single | m31 | Second item of the fourth row of the matrix. |
| System.Single | m32 | Third item of the fourth row of the matrix. |
| System.Single | 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 the first column of this matrix.
Declaration
public Vector4 Column0 { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Column1
Gets the second column of this matrix.
Declaration
public Vector4 Column1 { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Column2
Gets the third column of this matrix.
Declaration
public Vector4 Column2 { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Column3
Gets the fourth column of this matrix.
Declaration
public Vector4 Column3 { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Determinant
Gets the determinant of this matrix.
Declaration
public float Determinant { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Diagonal
Gets or sets the values along the main diagonal of the matrix.
Declaration
public Vector4 Diagonal { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
Item[Int32, Int32]
Gets or sets the value at a specified row and column.
Declaration
public float this[int rowIndex, int columnIndex] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowIndex | |
| System.Int32 | columnIndex |
Property Value
| Type | Description |
|---|---|
| System.Single |
M11
Gets or sets the value at row 1, column 1 of this instance.
Declaration
public float M11 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M12
Gets or sets the value at row 1, column 2 of this instance.
Declaration
public float M12 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M13
Gets or sets the value at row 1, column 3 of this instance.
Declaration
public float M13 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M14
Gets or sets the value at row 1, column 4 of this instance.
Declaration
public float M14 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M21
Gets or sets the value at row 2, column 1 of this instance.
Declaration
public float M21 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M22
Gets or sets the value at row 2, column 2 of this instance.
Declaration
public float M22 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M23
Gets or sets the value at row 2, column 3 of this instance.
Declaration
public float M23 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M24
Gets or sets the value at row 2, column 4 of this instance.
Declaration
public float M24 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M31
Gets or sets the value at row 3, column 1 of this instance.
Declaration
public float M31 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M32
Gets or sets the value at row 3, column 2 of this instance.
Declaration
public float M32 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M33
Gets or sets the value at row 3, column 3 of this instance.
Declaration
public float M33 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M34
Gets or sets the value at row 3, column 4 of this instance.
Declaration
public float M34 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M41
Gets or sets the value at row 4, column 1 of this instance.
Declaration
public float M41 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M42
Gets or sets the value at row 4, column 2 of this instance.
Declaration
public float M42 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M43
Gets or sets the value at row 4, column 3 of this instance.
Declaration
public float M43 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
M44
Gets or sets the value at row 4, column 4 of this instance.
Declaration
public float M44 { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Trace
Gets the trace of the matrix, the sum of the values along the diagonal.
Declaration
public float Trace { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Methods
Add(Matrix4, Matrix4)
Adds two instances.
Declaration
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(ref Matrix4, ref Matrix4, out Matrix4)
Adds two instances.
Declaration
public static void Add(ref Matrix4 left, ref 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 Matrix4 ClearProjection()
Returns
| Type | Description |
|---|---|
| Matrix4 |
ClearRotation()
Returns a copy of this Matrix4 without rotation.
Declaration
public Matrix4 ClearRotation()
Returns
| Type | Description |
|---|---|
| Matrix4 |
ClearScale()
Returns a copy of this Matrix4 without scale.
Declaration
public Matrix4 ClearScale()
Returns
| Type | Description |
|---|---|
| Matrix4 |
ClearTranslation()
Returns a copy of this Matrix4 without translation.
Declaration
public Matrix4 ClearTranslation()
Returns
| Type | Description |
|---|---|
| Matrix4 |
CreateFromAxisAngle(Vector3, Single)
Build a rotation matrix from the specified axis/angle rotation.
Declaration
public static Matrix4 CreateFromAxisAngle(Vector3 axis, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | The axis to rotate about. |
| System.Single | 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, Single, 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. |
| System.Single | 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
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(ref Quaternion, out Matrix4)
Builds a rotation matrix from a quaternion.
Declaration
public static void CreateFromQuaternion(ref Quaternion q, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | q | The quaternion to rotate by. |
| Matrix4 | result | A matrix instance. |
CreateOrthographic(Single, Single, Single, Single)
Creates an orthographic projection matrix.
Declaration
public static Matrix4 CreateOrthographic(float width, float height, float zNear, float zFar)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | width | The width of the projection volume. |
| System.Single | height | The height of the projection volume. |
| System.Single | zNear | The near edge of the projection volume. |
| System.Single | zFar | The far edge of the projection volume. |
Returns
| Type | Description |
|---|---|
| Matrix4 |
CreateOrthographic(Single, Single, Single, Single, out Matrix4)
Creates an orthographic projection matrix.
Declaration
public static void CreateOrthographic(float width, float height, float zNear, float zFar, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | width | The width of the projection volume. |
| System.Single | height | The height of the projection volume. |
| System.Single | zNear | The near edge of the projection volume. |
| System.Single | zFar | The far edge of the projection volume. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreateOrthographicOffCenter(Single, Single, Single, Single, Single, Single)
Creates an orthographic projection matrix.
Declaration
public static Matrix4 CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNear, float zFar)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | left | The left edge of the projection volume. |
| System.Single | right | The right edge of the projection volume. |
| System.Single | bottom | The bottom edge of the projection volume. |
| System.Single | top | The top edge of the projection volume. |
| System.Single | zNear | The near edge of the projection volume. |
| System.Single | zFar | The far edge of the projection volume. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateOrthographicOffCenter(Single, Single, Single, Single, Single, Single, out Matrix4)
Creates an orthographic projection matrix.
Declaration
public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | left | The left edge of the projection volume. |
| System.Single | right | The right edge of the projection volume. |
| System.Single | bottom | The bottom edge of the projection volume. |
| System.Single | top | The top edge of the projection volume. |
| System.Single | zNear | The near edge of the projection volume. |
| System.Single | zFar | The far edge of the projection volume. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreatePerspectiveFieldOfView(Single, Single, Single, Single)
Creates a perspective projection matrix.
Declaration
public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | fovy | Angle of the field of view in the y direction (in radians) |
| System.Single | aspect | Aspect ratio of the view (width / height) |
| System.Single | zNear | Distance to the near clip plane |
| System.Single | zFar | Distance to the far clip plane |
Returns
| Type | Description |
|---|---|
| Matrix4 | A projection matrix that transforms camera space to raster space |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentOutOfRangeException | Thrown under the following conditions: |
CreatePerspectiveFieldOfView(Single, Single, Single, Single, out Matrix4)
Creates a perspective projection matrix.
Declaration
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | fovy | Angle of the field of view in the y direction (in radians) |
| System.Single | aspect | Aspect ratio of the view (width / height) |
| System.Single | zNear | Distance to the near clip plane |
| System.Single | zFar | Distance to the far clip plane |
| Matrix4 | result | A projection matrix that transforms camera space to raster space |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentOutOfRangeException | Thrown under the following conditions: |
CreatePerspectiveOffCenter(Single, Single, Single, Single, Single, Single)
Creates an perspective projection matrix.
Declaration
public static Matrix4 CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | left | Left edge of the view frustum |
| System.Single | right | Right edge of the view frustum |
| System.Single | bottom | Bottom edge of the view frustum |
| System.Single | top | Top edge of the view frustum |
| System.Single | zNear | Distance to the near clip plane |
| System.Single | zFar | Distance to the far clip plane |
Returns
| Type | Description |
|---|---|
| Matrix4 | A projection matrix that transforms camera space to raster space |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentOutOfRangeException | Thrown under the following conditions: |
CreatePerspectiveOffCenter(Single, Single, Single, Single, Single, Single, out Matrix4)
Creates an perspective projection matrix.
Declaration
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | left | Left edge of the view frustum |
| System.Single | right | Right edge of the view frustum |
| System.Single | bottom | Bottom edge of the view frustum |
| System.Single | top | Top edge of the view frustum |
| System.Single | zNear | Distance to the near clip plane |
| System.Single | zFar | Distance to the far clip plane |
| Matrix4 | result | A projection matrix that transforms camera space to raster space |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentOutOfRangeException | Thrown under the following conditions: |
CreateRotationX(Single)
Builds a rotation matrix for a rotation around the x-axis.
Declaration
public static Matrix4 CreateRotationX(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateRotationX(Single, 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 |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreateRotationY(Single)
Builds a rotation matrix for a rotation around the y-axis.
Declaration
public static Matrix4 CreateRotationY(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateRotationY(Single, 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 |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreateRotationZ(Single)
Builds a rotation matrix for a rotation around the z-axis.
Declaration
public static Matrix4 CreateRotationZ(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateRotationZ(Single, 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 |
|---|---|---|
| System.Single | angle | The counter-clockwise angle in radians. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreateScale(Vector3)
Creates a scale matrix.
Declaration
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(ref Vector3, out Matrix4)
Creates a scale matrix.
Declaration
public static void CreateScale(ref 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(Single)
Creates a scale matrix.
Declaration
public static Matrix4 CreateScale(float scale)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | scale | Single scale factor for the x, y, and z axes. |
Returns
| Type | Description |
|---|---|
| Matrix4 | A scale matrix. |
CreateScale(Single, out Matrix4)
Creates a scale matrix.
Declaration
public static void CreateScale(float scale, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | scale | Single scale factor for the x, y, and z axes. |
| Matrix4 | result | A scale matrix. |
CreateScale(Single, Single, Single)
Creates a scale matrix.
Declaration
public static Matrix4 CreateScale(float x, float y, float z)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | Scale factor for the x axis. |
| System.Single | y | Scale factor for the y axis. |
| System.Single | z | Scale factor for the z axis. |
Returns
| Type | Description |
|---|---|
| Matrix4 | A scale matrix. |
CreateScale(Single, Single, Single, out Matrix4)
Creates a scale matrix.
Declaration
public static void CreateScale(float x, float y, float z, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | Scale factor for the x axis. |
| System.Single | y | Scale factor for the y axis. |
| System.Single | z | Scale factor for the z axis. |
| Matrix4 | result | A scale matrix. |
CreateTranslation(Vector3)
Creates a translation matrix.
Declaration
public static Matrix4 CreateTranslation(Vector3 vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vector | The translation vector. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateTranslation(ref Vector3, out Matrix4)
Creates a translation matrix.
Declaration
public static void CreateTranslation(ref Vector3 vector, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vector | The translation vector. |
| Matrix4 | result | The resulting Matrix4 instance. |
CreateTranslation(Single, Single, Single)
Creates a translation matrix.
Declaration
public static Matrix4 CreateTranslation(float x, float y, float z)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | X translation. |
| System.Single | y | Y translation. |
| System.Single | z | Z translation. |
Returns
| Type | Description |
|---|---|
| Matrix4 | The resulting Matrix4 instance. |
CreateTranslation(Single, Single, Single, out Matrix4)
Creates a translation matrix.
Declaration
public static void CreateTranslation(float x, float y, float z, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | X translation. |
| System.Single | y | Y translation. |
| System.Single | z | Z translation. |
| Matrix4 | result | The resulting Matrix4 instance. |
Equals(Matrix4)
Indicates whether the current matrix is equal to another matrix.
Declaration
public bool Equals(Matrix4 other)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | other | An matrix to compare with this matrix. |
Returns
| Type | Description |
|---|---|
| System.Boolean | 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
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The object to compare tresult. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the instances are equal; false otherwise. |
Overrides
ExtractProjection()
Returns the projection component of this instance.
Declaration
public Vector4 ExtractProjection()
Returns
| Type | Description |
|---|---|
| Vector4 |
ExtractRotation(Boolean)
Returns the rotation component of this instance. Quite slow.
Declaration
public Quaternion ExtractRotation(bool row_normalise = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | row_normalise | Whether the method should row-normalise (i.e. remove scale from) the Matrix. Pass false if you know it's already normalised. |
Returns
| Type | Description |
|---|---|
| Quaternion |
ExtractScale()
Returns the scale component of this instance.
Declaration
public Vector3 ExtractScale()
Returns
| Type | Description |
|---|---|
| Vector3 |
ExtractTranslation()
Returns the translation component of this instance.
Declaration
public Vector3 ExtractTranslation()
Returns
| Type | Description |
|---|---|
| Vector3 |
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | 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
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 if it has one, or the input if it is singular |
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | Thrown if the Matrix4 is singular. |
Invert(ref Matrix4, out Matrix4)
Calculate the inverse of the given matrix
Declaration
public static void Invert(ref 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 |
|---|---|
| System.InvalidOperationException | Thrown if the Matrix4 is singular. |
Inverted()
Returns an inverted copy of this instance.
Declaration
public Matrix4 Inverted()
Returns
| Type | Description |
|---|---|
| Matrix4 |
LookAt(Vector3, Vector3, Vector3)
Build a world space to camera space matrix
Declaration
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(Single, Single, Single, Single, Single, Single, Single, Single, Single)
Build a world space to camera space matrix
Declaration
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 |
|---|---|---|
| System.Single | eyeX | Eye (camera) position in world space |
| System.Single | eyeY | Eye (camera) position in world space |
| System.Single | eyeZ | Eye (camera) position in world space |
| System.Single | targetX | Target position in world space |
| System.Single | targetY | Target position in world space |
| System.Single | targetZ | Target position in world space |
| System.Single | upX | Up vector in world space (should not be parallel to the camera direction, that is target - eye) |
| System.Single | upY | Up vector in world space (should not be parallel to the camera direction, that is target - eye) |
| System.Single | upZ | 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
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, Single)
Multiplies an instance by a scalar.
Declaration
public static Matrix4 Mult(Matrix4 left, float right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | left | The left operand of the multiplication. |
| System.Single | right | The right operand of the multiplication. |
Returns
| Type | Description |
|---|---|
| Matrix4 | A new instance that is the result of the multiplication |
Mult(ref Matrix4, ref Matrix4, out Matrix4)
Multiplies two instances.
Declaration
public static void Mult(ref Matrix4 left, ref 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(ref Matrix4, Single, out Matrix4)
Multiplies an instance by a scalar.
Declaration
public static void Mult(ref Matrix4 left, float right, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | left | The left operand of the multiplication. |
| System.Single | 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 normalised copy of this instance.
Declaration
public Matrix4 Normalized()
Returns
| Type | Description |
|---|---|
| Matrix4 |
Subtract(Matrix4, Matrix4)
Subtracts one instance from another.
Declaration
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(ref Matrix4, ref Matrix4, out Matrix4)
Subtracts one instance from another.
Declaration
public static void Subtract(ref Matrix4 left, ref 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. |
ToString()
Returns a System.String that represents the current Matrix4.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | The string representation of the matrix. |
Overrides
Transpose()
Converts this instance into its transpose.
Declaration
public void Transpose()
Transpose(Matrix4)
Calculate the transpose of the given matrix
Declaration
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(ref Matrix4, out Matrix4)
Calculate the transpose of the given matrix
Declaration
public static void Transpose(ref Matrix4 mat, out Matrix4 result)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | mat | The matrix to transpose |
| Matrix4 | result | The result of the calculation |
Operators
Addition(Matrix4, Matrix4)
Matrix addition
Declaration
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 |
Equality(Matrix4, Matrix4)
Compares two instances for equality.
Declaration
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 |
|---|---|
| System.Boolean | True, if left equals right; false otherwise. |
Inequality(Matrix4, Matrix4)
Compares two instances for inequality.
Declaration
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 |
|---|---|
| System.Boolean | True, if left does not equal right; false otherwise. |
Multiply(Matrix4, Matrix4)
Matrix multiplication
Declaration
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 |
Multiply(Matrix4, Single)
Matrix-scalar multiplication
Declaration
public static Matrix4 operator *(Matrix4 left, float right)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | left | left-hand operand |
| System.Single | right | right-hand operand |
Returns
| Type | Description |
|---|---|
| Matrix4 | A new Matrix4 which holds the result of the multiplication |
Subtraction(Matrix4, Matrix4)
Matrix subtraction
Declaration
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 |