Generated by DocFX

Struct Matrix4x4

A structure representing 4x4 matrix.

Namespace: ISynergy.Framework.Mathematics
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public struct Matrix4x4
Remarks

The structure incapsulates elements of a 4x4 matrix and provides some operations with it.

Fields

View Source

V00

Row 0 column 0 element of the matrix.

Declaration
public float V00
Field Value
Type Description
System.Single
View Source

V01

Row 0 column 1 element of the matrix.

Declaration
public float V01
Field Value
Type Description
System.Single
View Source

V02

Row 0 column 2 element of the matrix.

Declaration
public float V02
Field Value
Type Description
System.Single
View Source

V03

Row 0 column 3 element of the matrix.

Declaration
public float V03
Field Value
Type Description
System.Single
View Source

V10

Row 1 column 0 element of the matrix.

Declaration
public float V10
Field Value
Type Description
System.Single
View Source

V11

Row 1 column 1 element of the matrix.

Declaration
public float V11
Field Value
Type Description
System.Single
View Source

V12

Row 1 column 2 element of the matrix.

Declaration
public float V12
Field Value
Type Description
System.Single
View Source

V13

Row 1 column 3 element of the matrix.

Declaration
public float V13
Field Value
Type Description
System.Single
View Source

V20

Row 2 column 0 element of the matrix.

Declaration
public float V20
Field Value
Type Description
System.Single
View Source

V21

Row 2 column 1 element of the matrix.

Declaration
public float V21
Field Value
Type Description
System.Single
View Source

V22

Row 2 column 2 element of the matrix.

Declaration
public float V22
Field Value
Type Description
System.Single
View Source

V23

Row 2 column 3 element of the matrix.

Declaration
public float V23
Field Value
Type Description
System.Single
View Source

V30

Row 3 column 0 element of the matrix.

Declaration
public float V30
Field Value
Type Description
System.Single
View Source

V31

Row 3 column 1 element of the matrix.

Declaration
public float V31
Field Value
Type Description
System.Single
View Source

V32

Row 3 column 2 element of the matrix.

Declaration
public float V32
Field Value
Type Description
System.Single
View Source

V33

Row 3 column 3 element of the matrix.

Declaration
public float V33
Field Value
Type Description
System.Single

Properties

View Source

Identity

Provides an identity matrix with all diagonal elements set to 1.

Declaration
public static readonly Matrix4x4 Identity { get; }
Property Value
Type Description
Matrix4x4

Methods

View Source

Add(Matrix4x4, Matrix4x4)

Adds corresponding components of two matrices.

Declaration
public static Matrix4x4 Add(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The matrix to add to.

Matrix4x4 matrix2

The matrix to add to the first matrix.

Returns
Type Description
Matrix4x4

Returns a matrix which components are equal to sum of corresponding components of the two specified matrices.

View Source

CreateDiagonal(Vector4)

Creates a diagonal matrix using the specified vector as diagonal elements.

Declaration
public static Matrix4x4 CreateDiagonal(Vector4 vector)
Parameters
Type Name Description
Vector4 vector

Vector to use for diagonal elements of the matrix.

Returns
Type Description
Matrix4x4

Returns a diagonal matrix.

View Source

CreateFromColumns(Vector4, Vector4, Vector4, Vector4)

Creates a matrix from 4 columns specified as vectors.

Declaration
public static Matrix4x4 CreateFromColumns(Vector4 column0, Vector4 column1, Vector4 column2, Vector4 column3)
Parameters
Type Name Description
Vector4 column0

First column of the matrix to create.

Vector4 column1

Second column of the matrix to create.

Vector4 column2

Third column of the matrix to create.

Vector4 column3

Fourth column of the matrix to create.

Returns
Type Description
Matrix4x4

Returns a matrix from specified columns.

View Source

CreateFromRotation(Matrix3x3)

Creates 4x4 tranformation matrix from 3x3 rotation matrix.

Declaration
public static Matrix4x4 CreateFromRotation(Matrix3x3 rotationMatrix)
Parameters
Type Name Description
Matrix3x3 rotationMatrix

Source 3x3 rotation matrix.

Returns
Type Description
Matrix4x4

Returns 4x4 rotation matrix.

Remarks

The source 3x3 rotation matrix is copied into the top left corner of the result 4x4 matrix, i.e. it represents 0th, 1st and 2nd row/column. The V33 element is set to 1 and the rest elements of 3rd row and 3rd column are set to zeros.

View Source

CreateFromRows(Vector4, Vector4, Vector4, Vector4)

Creates a matrix from 4 rows specified as vectors.

Declaration
public static Matrix4x4 CreateFromRows(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
Parameters
Type Name Description
Vector4 row0

First row of the matrix to create.

Vector4 row1

Second row of the matrix to create.

Vector4 row2

Third row of the matrix to create.

Vector4 row3

Fourth row of the matrix to create.

Returns
Type Description
Matrix4x4

Returns a matrix from specified rows.

View Source

CreateFromYawPitchRoll(Single, Single, Single)

Creates rotation matrix to rotate an object around X, Y and Z axes.

Declaration
public static Matrix4x4 CreateFromYawPitchRoll(float yaw, float pitch, float roll)
Parameters
Type Name Description
System.Single yaw

Rotation angle around Y axis in radians.

System.Single pitch

Rotation angle around X axis in radians.

System.Single roll

Rotation angle around Z axis in radians.

Returns
Type Description
Matrix4x4

Returns rotation matrix to rotate an object around all 3 axes.

Remarks

note

The routine assumes roll-pitch-yaw rotation order, when creating rotation matrix, i.e. an object is first rotated around Z axis, then around X axis and finally around Y axis.

View Source

CreateLookAt(Vector3, Vector3)

Creates a view matrix for the specified camera position and target point.

Declaration
public static Matrix4x4 CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget)
Parameters
Type Name Description
Vector3 cameraPosition

Position of camera.

Vector3 cameraTarget

Target point towards which camera is pointing.

Returns
Type Description
Matrix4x4

Returns a view matrix.

Remarks

Camera's "up" vector is supposed to be (0, 1, 0).

View Source

CreatePerspective(Single, Single, Single, Single)

Creates a perspective projection matrix.

Declaration
public static Matrix4x4 CreatePerspective(float width, float height, float nearPlaneDistance, float farPlaneDistance)
Parameters
Type Name Description
System.Single width

Width of the view volume at the near view plane.

System.Single height

Height of the view volume at the near view plane.

System.Single nearPlaneDistance

Distance to the near view plane.

System.Single farPlaneDistance

Distance to the far view plane.

Returns
Type Description
Matrix4x4

Return a perspective projection matrix.

View Source

CreateRotationX(Single)

Creates rotation matrix around X axis.

Declaration
public static Matrix4x4 CreateRotationX(float radians)
Parameters
Type Name Description
System.Single radians

Rotation angle around X axis in radians.

Returns
Type Description
Matrix4x4

Returns rotation matrix to rotate an object around X axis.

View Source

CreateRotationY(Single)

Creates rotation matrix around Y axis.

Declaration
public static Matrix4x4 CreateRotationY(float radians)
Parameters
Type Name Description
System.Single radians

Rotation angle around Y axis in radians.

Returns
Type Description
Matrix4x4

Returns rotation matrix to rotate an object around Y axis.

View Source

CreateRotationZ(Single)

Creates rotation matrix around Z axis.

Declaration
public static Matrix4x4 CreateRotationZ(float radians)
Parameters
Type Name Description
System.Single radians

Rotation angle around Z axis in radians.

Returns
Type Description
Matrix4x4

Returns rotation matrix to rotate an object around Z axis.

View Source

CreateTranslation(Vector3)

Creates translation matrix for the specified movement amount.

Declaration
public static Matrix4x4 CreateTranslation(Vector3 position)
Parameters
Type Name Description
Vector3 position

Vector which set direction and amount of movement.

Returns
Type Description
Matrix4x4

Returns translation matrix.

Remarks

The specified vector is copied to the 3rd column of the result matrix. All diagonal elements are set to 1. The rest of matrix is initialized with zeros.

View Source

Equals(Matrix4x4)

Tests whether the matrix equals to the specified one.

Declaration
public bool Equals(Matrix4x4 matrix)
Parameters
Type Name Description
Matrix4x4 matrix

The matrix to test equality with.

Returns
Type Description
System.Boolean

Returns true if the two matrices are equal or false otherwise.

View Source

Equals(Object)

Tests whether the matrix equals to the specified object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The object to test equality with.

Returns
Type Description
System.Boolean

Returns true if the matrix equals to the specified object or false otherwise.

View Source

ExtractYawPitchRoll(out Single, out Single, out Single)

Extract rotation angles from the rotation matrix.

Declaration
public void ExtractYawPitchRoll(out float yaw, out float pitch, out float roll)
Parameters
Type Name Description
System.Single yaw

Extracted rotation angle around Y axis in radians.

System.Single pitch

Extracted rotation angle around X axis in radians.

System.Single roll

Extracted rotation angle around Z axis in radians.

Remarks

note

The routine assumes roll-pitch-yaw rotation order when extracting rotation angle. Using extracted angles with the CreateFromYawPitchRoll(Single, Single, Single) should provide same rotation matrix.

note

The method assumes the provided matrix represent valid rotation matrix.

Sample usage:

// assume we have a rotation matrix created like this
float yaw   = 10.0f / 180 * Math.PI;
float pitch = 30.0f / 180 * Math.PI;
float roll  = 45.0f / 180 * Math.PI;

Matrix4x4 rotationMatrix = Matrix3x3.CreateFromYawPitchRoll( yaw, pitch, roll ); // ...

// now somewhere in the code you may want to get rotation // angles back from a matrix assuming same rotation order float extractedYaw; float extractedPitch; float extractedRoll;

rotation.ExtractYawPitchRoll( out extractedYaw, out extractedPitch, out extractedRoll );

View Source

GetColumn(Int32)

Get column of the matrix.

Declaration
public Vector4 GetColumn(int index)
Parameters
Type Name Description
System.Int32 index

Column index to get, [0, 3].

Returns
Type Description
Vector4

Returns specified column of the matrix as a vector.

View Source

GetHashCode()

Returns the hashcode for this instance.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A 32-bit signed integer hash code.

View Source

GetRow(Int32)

Get row of the matrix.

Declaration
public Vector4 GetRow(int index)
Parameters
Type Name Description
System.Int32 index

Row index to get, [0, 3].

Returns
Type Description
Vector4

Returns specified row of the matrix as a vector.

View Source

Multiply(Matrix4x4, Matrix4x4)

Multiplies two specified matrices.

Declaration
public static Matrix4x4 Multiply(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

Matrix to multiply.

Matrix4x4 matrix2

Matrix to multiply by.

Returns
Type Description
Matrix4x4

Return new matrix, which the result of multiplication of the two specified matrices.

View Source

Multiply(Matrix4x4, Vector4)

Multiplies specified matrix by the specified vector.

Declaration
public static Vector4 Multiply(Matrix4x4 matrix, Vector4 vector)
Parameters
Type Name Description
Matrix4x4 matrix

Matrix to multiply by vector.

Vector4 vector

Vector to multiply matrix by.

Returns
Type Description
Vector4

Returns new vector which is the result of multiplication of the specified matrix by the specified vector.

View Source

Subtract(Matrix4x4, Matrix4x4)

Subtracts corresponding components of two matrices.

Declaration
public static Matrix4x4 Subtract(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The matrix to subtract from.

Matrix4x4 matrix2

The matrix to subtract from the first matrix.

Returns
Type Description
Matrix4x4

Returns a matrix which components are equal to difference of corresponding components of the two specified matrices.

View Source

ToArray()

Returns array representation of the matrix.

Declaration
public float[] ToArray()
Returns
Type Description
System.Single[]

Returns array which contains all elements of the matrix in the row-major order.

Operators

View Source

Addition(Matrix4x4, Matrix4x4)

Adds corresponding components of two matrices.

Declaration
public static Matrix4x4 operator +(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The matrix to add to.

Matrix4x4 matrix2

The matrix to add to the first matrix.

Returns
Type Description
Matrix4x4

Returns a matrix which components are equal to sum of corresponding components of the two specified matrices.

View Source

Equality(Matrix4x4, Matrix4x4)

Tests whether two specified matrices are equal.

Declaration
public static bool operator ==(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The left-hand matrix.

Matrix4x4 matrix2

The right-hand matrix.

Returns
Type Description
System.Boolean

Returns true if the two matrices are equal or false otherwise.

View Source

Inequality(Matrix4x4, Matrix4x4)

Tests whether two specified matrices are not equal.

Declaration
public static bool operator !=(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The left-hand matrix.

Matrix4x4 matrix2

The right-hand matrix.

Returns
Type Description
System.Boolean

Returns true if the two matrices are not equal or false otherwise.

View Source

Multiply(Matrix4x4, Matrix4x4)

Multiplies two specified matrices.

Declaration
public static Matrix4x4 operator *(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

Matrix to multiply.

Matrix4x4 matrix2

Matrix to multiply by.

Returns
Type Description
Matrix4x4

Return new matrix, which the result of multiplication of the two specified matrices.

View Source

Multiply(Matrix4x4, Vector4)

Multiplies specified matrix by the specified vector.

Declaration
public static Vector4 operator *(Matrix4x4 matrix, Vector4 vector)
Parameters
Type Name Description
Matrix4x4 matrix

Matrix to multiply by vector.

Vector4 vector

Vector to multiply matrix by.

Returns
Type Description
Vector4

Returns new vector which is the result of multiplication of the specified matrix by the specified vector.

View Source

Subtraction(Matrix4x4, Matrix4x4)

Subtracts corresponding components of two matrices.

Declaration
public static Matrix4x4 operator -(Matrix4x4 matrix1, Matrix4x4 matrix2)
Parameters
Type Name Description
Matrix4x4 matrix1

The matrix to subtract from.

Matrix4x4 matrix2

The matrix to subtract from the first matrix.

Returns
Type Description
Matrix4x4

Returns a matrix which components are equal to difference of corresponding components of the two specified matrices.

Extension Methods

EnumExtensions.GetSymbol<T>(T)
ArrayExtensions.Concatenate<T>(T, T[])
CollectionExtensions.FromHierarchy<TSource>(TSource, Func<TSource, TSource>, Func<TSource, Boolean>)
ObjectExtensions.Clone<T>(T)
ObjectExtensions.AddressOf<T>(T)
ObjectExtensions.ToByteArray<T>(T)
ReflectionExtensions.GetPropertyInfo<T, TValue>(T, Expression<Func<T, TValue>>)