Struct Matrix
Defines a 4x4 matrix.
Implements
Inherited Members
Namespace: GTA.Math
Assembly: ScriptHookVDotNet3.dll
Syntax
[Serializable]
public struct Matrix : IEquatable<Matrix>
Constructors
| Improve this Doc View SourceMatrix(Single[])
Initializes a new instance of the Matrix structure.
Declaration
public Matrix(float[] values)
Parameters
Type | Name | Description |
---|---|---|
Single[] | values | The values to assign to the components of the matrix. This must be an array with sixteen elements. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when |
ArgumentOutOfRangeException | Thrown when |
Fields
| Improve this Doc View SourceM11
Gets or sets the element of the matrix that exists in the first row and first column.
Declaration
public float M11
Field Value
Type | Description |
---|---|
Single |
M12
Gets or sets the element of the matrix that exists in the first row and second column.
Declaration
public float M12
Field Value
Type | Description |
---|---|
Single |
M13
Gets or sets the element of the matrix that exists in the first row and third column.
Declaration
public float M13
Field Value
Type | Description |
---|---|
Single |
M14
Gets or sets the element of the matrix that exists in the first row and fourth column.
Declaration
public float M14
Field Value
Type | Description |
---|---|
Single |
M21
Gets or sets the element of the matrix that exists in the second row and first column.
Declaration
public float M21
Field Value
Type | Description |
---|---|
Single |
M22
Gets or sets the element of the matrix that exists in the second row and second column.
Declaration
public float M22
Field Value
Type | Description |
---|---|
Single |
M23
Gets or sets the element of the matrix that exists in the second row and third column.
Declaration
public float M23
Field Value
Type | Description |
---|---|
Single |
M24
Gets or sets the element of the matrix that exists in the second row and fourth column.
Declaration
public float M24
Field Value
Type | Description |
---|---|
Single |
M31
Gets or sets the element of the matrix that exists in the third row and first column.
Declaration
public float M31
Field Value
Type | Description |
---|---|
Single |
M32
Gets or sets the element of the matrix that exists in the third row and second column.
Declaration
public float M32
Field Value
Type | Description |
---|---|
Single |
M33
Gets or sets the element of the matrix that exists in the third row and third column.
Declaration
public float M33
Field Value
Type | Description |
---|---|
Single |
M34
Gets or sets the element of the matrix that exists in the third row and fourth column.
Declaration
public float M34
Field Value
Type | Description |
---|---|
Single |
M41
Gets or sets the element of the matrix that exists in the fourth row and first column.
Declaration
public float M41
Field Value
Type | Description |
---|---|
Single |
M42
Gets or sets the element of the matrix that exists in the fourth row and second column.
Declaration
public float M42
Field Value
Type | Description |
---|---|
Single |
M43
Gets or sets the element of the matrix that exists in the fourth row and third column.
Declaration
public float M43
Field Value
Type | Description |
---|---|
Single |
M44
Gets or sets the element of the matrix that exists in the fourth row and fourth column.
Declaration
public float M44
Field Value
Type | Description |
---|---|
Single |
Properties
| Improve this Doc View SourceHasInverse
Gets a value indicating whether this instance has an inverse matrix.
Declaration
public readonly bool HasInverse { get; }
Property Value
Type | Description |
---|---|
Boolean |
Identity
The identity Matrix.
Declaration
public static readonly Matrix Identity { get; }
Property Value
Type | Description |
---|---|
Matrix |
IsIdentity
Gets a value indicating whether this instance is an identity matrix.
Declaration
public readonly bool IsIdentity { get; }
Property Value
Type | Description |
---|---|
Boolean | true if this instance is an identity matrix; otherwise, false. |
Item[Int32]
Gets or sets the component at the specified index.
Declaration
public float this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The zero-based index of the component to access. |
Property Value
Type | Description |
---|---|
Single | The value of the matrix component, depending on the index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the |
Item[Int32, Int32]
Gets or sets the component at the specified index.
Declaration
public float this[int row, int column] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | row | The row of the matrix to access. |
Int32 | column | The column of the matrix to access. |
Property Value
Type | Description |
---|---|
Single | The value of the matrix component, depending on the index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the |
Zero
A Matrix with all of its components set to zero.
Declaration
public static readonly Matrix Zero { get; }
Property Value
Type | Description |
---|---|
Matrix |
Methods
| Improve this Doc View SourceAdd(Matrix, Matrix)
Determines the sum of two matrices.
Declaration
public static Matrix Add(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to add. |
Matrix | right | The second matrix to add. |
Returns
Type | Description |
---|---|
Matrix | The sum of the two matrices. |
Determinant()
Calculates the determinant of the matrix.
Declaration
public float Determinant()
Returns
Type | Description |
---|---|
Single | The determinant of the matrix. |
Divide(Matrix, Matrix)
Determines the quotient of two matrices.
Declaration
public static Matrix Divide(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to divide. |
Matrix | right | The second matrix to divide. |
Returns
Type | Description |
---|---|
Matrix | The quotient of the two matrices. |
Divide(Matrix, Single)
Scales a matrix by the given value.
Declaration
public static Matrix Divide(Matrix left, float right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The matrix to scale. |
Single | right | The amount by which to scale. |
Returns
Type | Description |
---|---|
Matrix | The scaled matrix. |
Equals(Matrix)
Returns a value that indicates whether the current instance is equal to the specified object.
Declaration
public bool Equals(Matrix other)
Parameters
Type | Name | Description |
---|---|---|
Matrix | other | Object to make the comparison with. |
Returns
Type | Description |
---|---|
Boolean | true if the current instance is equal to the specified object; false otherwise. |
Equals(Object)
Returns a value that indicates whether the current instance is equal to a specified object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | Object to make the comparison with. |
Returns
Type | Description |
---|---|
Boolean | true if the current instance is equal to the specified object; false otherwise. |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer hash code. |
Overrides
| Improve this Doc View SourceInverseTransformPoint(Vector3)
Calculates the position of a point before this transformation matrix gets applied
Declaration
public Vector3 InverseTransformPoint(Vector3 point)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | The transformed vertex location |
Returns
Type | Description |
---|---|
Vector3 | The original vertex location before being transformed by the given Matrix |
Invert()
Inverts the matrix.
Declaration
public void Invert()
Invert(Matrix)
Calculates the inverse of a matrix if it exists.
Declaration
public static Matrix Invert(Matrix matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix | matrix |
Returns
Type | Description |
---|---|
Matrix | The inverse of the matrix. |
Lerp(Matrix, Matrix, Single)
Performs a linear interpolation between two matrices.
Declaration
public static Matrix Lerp(Matrix start, Matrix end, float amount)
Parameters
Type | Name | Description |
---|---|---|
Matrix | start | Start matrix. |
Matrix | end | End matrix. |
Single | amount | Value between 0 and 1 indicating the weight of |
Returns
Type | Description |
---|---|
Matrix | The linear interpolation of the two matrices. |
Remarks
This method performs the linear interpolation based on the following formula.
start + (end - start) * amount
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Multiply(Matrix, Matrix)
Determines the product of two matrices.
Declaration
public static Matrix Multiply(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to multiply. |
Matrix | right | The second matrix to multiply. |
Returns
Type | Description |
---|---|
Matrix | The product of the two matrices. |
Multiply(Matrix, Single)
Scales a matrix by the given value.
Declaration
public static Matrix Multiply(Matrix left, float right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The matrix to scale. |
Single | right | The amount by which to scale. |
Returns
Type | Description |
---|---|
Matrix | The scaled matrix. |
Negate(Matrix)
Negates a matrix.
Declaration
public static Matrix Negate(Matrix matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix | matrix | The matrix to be negated. |
Returns
Type | Description |
---|---|
Matrix | The negated matrix. |
RotationAxis(Vector3, Single)
Creates a matrix that rotates around an arbitrary axis.
Declaration
public static Matrix RotationAxis(Vector3 axis, float angle)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | axis | The axis around which to rotate. |
Single | angle | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
RotationQuaternion(Quaternion)
Creates a rotation matrix from a rotation.
Declaration
public static Matrix RotationQuaternion(Quaternion rotation)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | rotation | The quaternion to use to build the matrix. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
RotationX(Single)
Creates a matrix that rotates around the x-axis.
Declaration
public static Matrix RotationX(float angle)
Parameters
Type | Name | Description |
---|---|---|
Single | angle | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
RotationY(Single)
Creates a matrix that rotates around the y-axis.
Declaration
public static Matrix RotationY(float angle)
Parameters
Type | Name | Description |
---|---|---|
Single | angle | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
RotationYawPitchRoll(Single, Single, Single)
Creates a rotation matrix with a specified yaw, pitch, and roll.
Declaration
public static Matrix RotationYawPitchRoll(float yaw, float pitch, float roll)
Parameters
Type | Name | Description |
---|---|---|
Single | yaw | Yaw around the y-axis, in radians. |
Single | pitch | Pitch around the x-axis, in radians. |
Single | roll | Roll around the z-axis, in radians. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
RotationZ(Single)
Creates a matrix that rotates around the z-axis.
Declaration
public static Matrix RotationZ(float angle)
Parameters
Type | Name | Description |
---|---|---|
Single | angle | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. |
Returns
Type | Description |
---|---|
Matrix | The created rotation matrix. |
Scaling(Vector3)
Creates a matrix that scales along the x-axis, y-axis, and y-axis.
Declaration
public static Matrix Scaling(Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | scale | Scaling factor for all three axes. |
Returns
Type | Description |
---|---|
Matrix | The created scaling matrix. |
Scaling(Single, Single, Single)
Creates a matrix that scales along the x-axis, y-axis, and y-axis.
Declaration
public static Matrix Scaling(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
Single | x | Scaling factor that is applied along the x-axis. |
Single | y | Scaling factor that is applied along the y-axis. |
Single | z | Scaling factor that is applied along the z-axis. |
Returns
Type | Description |
---|---|
Matrix | The created scaling matrix. |
Subtract(Matrix, Matrix)
Determines the difference between two matrices.
Declaration
public static Matrix Subtract(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to subtract. |
Matrix | right | The second matrix to subtract. |
Returns
Type | Description |
---|---|
Matrix | The difference between the two matrices. |
ToArray()
Converts the matrix to an array of floats.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
Single[] |
ToString()
Converts the value of the object to its equivalent string representation.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The string representation of the value of this instance. |
Overrides
| Improve this Doc View SourceToString(String)
Converts the value of the object to its equivalent string representation.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
String | format | The format. |
Returns
Type | Description |
---|---|
String | The string representation of the value of this instance. |
TransformPoint(Vector3)
Apply the transformation matrix to a point in world space
Declaration
public Vector3 TransformPoint(Vector3 point)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | point | The original vertex location |
Returns
Type | Description |
---|---|
Vector3 | The vertex location transformed by the given Matrix |
Translation(Vector3)
Creates a translation matrix using the specified offsets.
Declaration
public static Matrix Translation(Vector3 amount)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | amount | The offset for all three coordinate planes. |
Returns
Type | Description |
---|---|
Matrix | The created translation matrix. |
Translation(Single, Single, Single)
Creates a translation matrix using the specified offsets.
Declaration
public static Matrix Translation(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
Single | x | X-coordinate offset. |
Single | y | Y-coordinate offset. |
Single | z | Z-coordinate offset. |
Returns
Type | Description |
---|---|
Matrix | The created translation matrix. |
Transpose(Matrix)
Calculates the transpose of the specified matrix.
Declaration
public static Matrix Transpose(Matrix matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix | matrix | The matrix whose transpose is to be calculated. |
Returns
Type | Description |
---|---|
Matrix | The transpose of the specified matrix. |
Operators
| Improve this Doc View SourceAddition(Matrix, Matrix)
Adds two matrices.
Declaration
public static Matrix operator +(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to add. |
Matrix | right | The second matrix to add. |
Returns
Type | Description |
---|---|
Matrix | The sum of the two matrices. |
Division(Matrix, Matrix)
Divides two matrices.
Declaration
public static Matrix operator /(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to divide. |
Matrix | right | The second matrix to divide. |
Returns
Type | Description |
---|---|
Matrix | The quotient of the two matrices. |
Division(Matrix, Single)
Scales a matrix by a given value.
Declaration
public static Matrix operator /(Matrix left, float right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The matrix to scale. |
Single | right | The amount by which to scale. |
Returns
Type | Description |
---|---|
Matrix | The scaled matrix. |
Equality(Matrix, Matrix)
Tests for equality between two objects.
Declaration
public static bool operator ==(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first value to compare. |
Matrix | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Inequality(Matrix, Matrix)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first value to compare. |
Matrix | right | The second value to compare. |
Returns
Type | Description |
---|---|
Boolean | true if |
Multiply(Matrix, Matrix)
Multiplies two matrices.
Declaration
public static Matrix operator *(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to multiply. |
Matrix | right | The second matrix to multiply. |
Returns
Type | Description |
---|---|
Matrix | The product of the two matrices. |
Multiply(Matrix, Single)
Scales a matrix by a given value.
Declaration
public static Matrix operator *(Matrix left, float right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The matrix to scale. |
Single | right | The amount by which to scale. |
Returns
Type | Description |
---|---|
Matrix | The scaled matrix. |
Multiply(Single, Matrix)
Scales a matrix by a given value.
Declaration
public static Matrix operator *(float left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Single | left | The amount by which to scale. |
Matrix | right | The matrix to scale. |
Returns
Type | Description |
---|---|
Matrix | The scaled matrix. |
Subtraction(Matrix, Matrix)
Subtracts two matrices.
Declaration
public static Matrix operator -(Matrix left, Matrix right)
Parameters
Type | Name | Description |
---|---|---|
Matrix | left | The first matrix to subtract. |
Matrix | right | The second matrix to subtract. |
Returns
Type | Description |
---|---|
Matrix | The difference between the two matrices. |
UnaryNegation(Matrix)
Negates a matrix.
Declaration
public static Matrix operator -(Matrix matrix)
Parameters
Type | Name | Description |
---|---|---|
Matrix | matrix | The matrix to negate. |
Returns
Type | Description |
---|---|
Matrix | The negated matrix. |