Struct Matrix4
A 4x4 matrix to describe 4D rotations
public struct Matrix4 : IEquatable<Matrix4>
Remarks
The matrix is represented in row major order. Most operation that available requires the matrix to be orthogonal. This should not be confused with Unity's Matrix4x4.
Constructors
Matrix4(Vector4)
Create a diagonal matrix with given scaling value.
public Matrix4(Vector4 scale)
Matrix4(Vector4, Vector4, Vector4, Vector4)
Create a matrix data with given individual values (in vector form).
public Matrix4(Vector4 x, Vector4 y, Vector4 z, Vector4 w)
Matrix4(Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single)
Create a matrix data with given individual values.
public Matrix4(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p)
Fields
ew
Fourth row of the matrix
public Vector4 ew
ex
First row of the matrix
public Vector4 ex
ey
Second row of the matrix
public Vector4 ey
ez
Third row of the matrix
public Vector4 ez
Properties
Column0
First column of the matrix
public Vector4 Column0 { get; set; }
Column1
Second column of the matrix
public Vector4 Column1 { get; set; }
Column2
Third column of the matrix
public Vector4 Column2 { get; set; }
Column3
Fourth column of the matrix
public Vector4 Column3 { get; set; }
Diagonal
Access the diagonal row of the matrix
public Vector4 Diagonal { get; }
identity
Get an identity matrix
public static Matrix4 identity { get; }
Item[Int32]
Get Nth-row of the matrix
public Vector4 this[int index] { get; set; }
Item[Int32, Int32]
Get a matrix element at given position
public float this[int row, int column] { get; set; }
zero
Get a zero matrix
public static Matrix4 zero { get; }
Methods
Abs(Matrix4)
Returns the absolute version of the matrix.
public static Matrix4 Abs(Matrix4 m)
Column(Int32)
Get Nth column by index
public Vector4 Column(int i)
Remarks
It's much better to use the getter property if the index is hard-coded
Column(Int32, Vector4)
Set Nth column by index
public void Column(int i, Vector4 value)
Remarks
It's much better to use the setter property if the index is hard-coded
Delta(Matrix4, Matrix4)
Create rotation matrix that rotates from matrix with to matrix
public static Matrix4 Delta(Matrix4 from, Matrix4 to)
Delta(Vector4, Vector4)
Create rotation matrix that rotates from direction with to direction
public static Matrix4 Delta(Vector4 from, Vector4 to)
Determinant(Matrix4)
Get the determinant of the matrix
public static float Determinant(Matrix4 m)
Euler(Euler4)
Convert degree euler to orthogonal matrix rotation.
public static Matrix4 Euler(Euler4 rot)
Euler(Int32, Single)
Convert given degree rotation in given axis to orthogonal matrix rotation.
public static Matrix4 Euler(int axis, float degree)
Remarks
This method is much optimized than Euler(new Euler4(axis, degree))
Euler(Single, Single, Single, Single, Single, Single)
Convert degree euler to orthogonal matrix rotation individually.
public static Matrix4 Euler(float x, float y, float z, float t, float u, float v)
Remarks
This creates a rotation matrix that rotates a point by Y, Z, X, T, U, then V. In that order.
LookAt(Vector4)
Get rotation matrix that rotates identity object to given overward axis
public static Matrix4 LookAt(Vector4 overward)
LookAt(Vector4, Vector4)
Get rotation matrix that rotates identity object to given overward and forward axis
public static Matrix4 LookAt(Vector4 overward, Vector4 forward)
LookAt(Vector4, Vector4, Vector4)
Get rotation matrix that rotates identity object to given overward and forward and upward axis
public static Matrix4 LookAt(Vector4 overward, Vector4 forward, Vector4 upward)
Remarks
Forward and upward is a support direction, meaning they'll change if they're not perpendicular with overward.
ToEuler()
Convert matrix into euler degree rotation
public Euler4 ToEuler()
Remarks
The method is not valid in 90 deg singularity (WIP). The method won't check for orthogonality.
Transform(Matrix4, Matrix4)
Perform a sandwich operation on B by A
public static Matrix4 Transform(Matrix4 a, Matrix4 b)
Remarks
The product is a rotation of B that oriented relative to A coordinate axes
Transpose(Matrix4)
Returns the transposed version of the matrix.
public static Matrix4 Transpose(Matrix4 m)
Remarks
When the matrix is orthogonal, it's equivalent as the inversed version of the matrix
Operators
Addition(Matrix4, Matrix4)
Element-wisely add two matrices.
public static Matrix4 operator +(Matrix4 lhs, Matrix4 rhs)
Remarks
This operation could make the matrix not orthogonal anymore
Division(Matrix4, Matrix4)
Inversely Multiply or combine rotations between two matrices.
public static Matrix4 operator /(Matrix4 q, Matrix4 r)
Remarks
B * A / B returns A
Division(Vector4, Matrix4)
Multiply or rotate a vector by the inversed version of this matrix
public static Vector4 operator /(Vector4 v, Matrix4 r)
Equality(Matrix4, Matrix4)
Check the equality between two matrices
public static bool operator ==(Matrix4 a, Matrix4 b)
Implicit(Matrix4 to Matrix4x4)
Implicit conversion to Unity's Matrix4x4
public static implicit operator Matrix4x4(Matrix4 v)
Implicit(Matrix4x4 to Matrix4)
Implicit conversion from Unity's Matrix4x4
public static implicit operator Matrix4(Matrix4x4 v)
Inequality(Matrix4, Matrix4)
Check the inequality between two matrices
public static bool operator !=(Matrix4 a, Matrix4 b)
Multiply(Matrix4, Matrix4)
Multiply or combine rotations between two matrices.
public static Matrix4 operator *(Matrix4 lhs, Matrix4 rhs)
Multiply(Matrix4, Vector4)
Multiply or rotate a vector by this matrix
public static Vector4 operator *(Matrix4 lhs, Vector4 rhs)
Multiply(Matrix4, Single)
Scales the matrix
public static Matrix4 operator *(Matrix4 lhs, float f)
Remarks
This operation could make the matrix not orthogonal anymore
Subtraction(Matrix4, Matrix4)
Element-wisely subtract two matrices.
public static Matrix4 operator -(Matrix4 lhs, Matrix4 rhs)
Remarks
This operation could make the matrix not orthogonal anymore