Struct float4x4
Represents a 4x4 Matrix typically used in ComputerGraphics algorithms.
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct float4x4 : IEquatable<float4x4>
Remarks
float4x4 objects represent matrices used in column-vector-notation, that means when used in common matrix-vector-multiplication scenarios, the vector should be multiplied from the right to the matrix (M * v). Concatenations of matrices from left to right represent a transformation where the rightmost matrix is applied first and the leftmost matrix is applied last, for example in (M3 * M2 * M1) * v the vector v is first transformed by M1, then by M2 and finally by M3. The translation part of a 4x4 matrix used in homogeneous coordinate calculations can be found in the leftmost column (M14 - x-translation, M24 - y-translation, M34 - z-translation).
Note that although float4x4 objects represent matrices in COLUMN-vector-NOTATION as found in math books, the objects' contents is physically stored in ROW-major-ORDER, meaning that in physical memory, a float4x4's components are stored contiguously in the following order: first row (M11, M12, M13, M14), then second row (M21, M22, M21, M24), and so on. When exchanging matrix contents with libraries like graphics engines (OpenGL, Direct3D), physics engines, file formats, etc. make sure to convert to and from the given Matrix layout of the API you are exchanging data with.
float4x4 contains convenience construction methods to create matrices commonly used in Computer Graphics. Most of these application matrices are handedness-agnostic, meaning that the resulting matrices can be used in both, left-handed and right-handed coordinate systems. This does not hold for LookAt and Projection matrices where the viewing direction plays a role. In left-handed coordinate systems the viewing direction is positive, meaning positions further away have bigger positive z-coordinates whereas in right-handed coordinate systems positions further away have smaller negative z-coordinates. By default, float4x4 will assume a left-handed coordinate system, but contains convenience construction methods to also create right-handed matrices if necessary. The right-handed versions of methods are postfixed with "RH".
Constructors
float4x4(double4x4)
Constructs a new float4x4 by converting from a double4x4.
Declaration
public float4x4(double4x4 d4x4)
Parameters
Type | Name | Description |
---|---|---|
double4x4 | d4x4 | The double4x4 to copy components from. |
float4x4(float3x3)
Constructs a new float4x4 from a float3x3 by setting the 4th column and row to UnitW respectively.
Declaration
public float4x4(float3x3 f3x3)
Parameters
Type | Name | Description |
---|---|---|
float3x3 | f3x3 | The float3x3 matrix to copy components from. |
float4x4(float4, float4, float4, float4)
Constructs a new instance.
Declaration
public float4x4(float4 row1, float4 row2, float4 row3, float4 row4)
Parameters
Type | Name | Description |
---|---|---|
float4 | row1 | Top row of the matrix |
float4 | row2 | Second row of the matrix |
float4 | row3 | Third row of the matrix |
float4 | row4 | Bottom row of the matrix |
float4x4(Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single)
Constructs a new instance.
Declaration
public float4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
Parameters
Type | Name | Description |
---|---|---|
System.Single | m11 | First item of the first row of the matrix. |
System.Single | m12 | Second item of the first row of the matrix. |
System.Single | m13 | Third item of the first row of the matrix. |
System.Single | m14 | Fourth item of the first row of the matrix. |
System.Single | m21 | First item of the second row of the matrix. |
System.Single | m22 | Second item of the second row of the matrix. |
System.Single | m23 | Third item of the second row of the matrix. |
System.Single | m24 | Fourth item of the second row of the matrix. |
System.Single | m31 | First item of the third row of the matrix. |
System.Single | m32 | Second item of the third row of the matrix. |
System.Single | m33 | Third item of the third row of the matrix. |
System.Single | m34 | First item of the third row of the matrix. |
System.Single | m41 | Fourth item of the fourth row of the matrix. |
System.Single | m42 | Second item of the fourth row of the matrix. |
System.Single | m43 | Third item of the fourth row of the matrix. |
System.Single | m44 | Fourth item of the fourth row of the matrix. |
Fields
Identity
The identity matrix
Declaration
public static readonly float4x4 Identity
Field Value
Type | Description |
---|---|
float4x4 |
Row1
Top row of the matrix
Declaration
public float4 Row1
Field Value
Type | Description |
---|---|
float4 |
Row2
2nd row of the matrix
Declaration
public float4 Row2
Field Value
Type | Description |
---|---|
float4 |
Row3
3rd row of the matrix
Declaration
public float4 Row3
Field Value
Type | Description |
---|---|
float4 |
Row4
Bottom row of the matrix
Declaration
public float4 Row4
Field Value
Type | Description |
---|---|
float4 |
Zero
The zero matrix
Declaration
public static readonly float4x4 Zero
Field Value
Type | Description |
---|---|
float4x4 |
Properties
Column1
The first column of this matrix
Declaration
public float4 Column1 { get; set; }
Property Value
Type | Description |
---|---|
float4 |
Column2
The second column of this matrix
Declaration
public float4 Column2 { get; set; }
Property Value
Type | Description |
---|---|
float4 |
Column3
The third column of this matrix
Declaration
public float4 Column3 { get; set; }
Property Value
Type | Description |
---|---|
float4 |
Column4
The fourth column of this matrix
Declaration
public float4 Column4 { get; set; }
Property Value
Type | Description |
---|---|
float4 |
Determinant
The determinant of this matrix
Declaration
public readonly float Determinant { get; }
Property Value
Type | Description |
---|---|
System.Single |
IsAffine
Checks whether row three (the projection part) of the matrix is equal to (0, 0, 0, 1). If this is the case the matrix is affine.
Declaration
public readonly bool IsAffine { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32, Int32]
Sets/Gets value from given index
Declaration
public float this[int i, int j] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The ROW index |
System.Int32 | j | The COLUMN index |
Property Value
Type | Description |
---|---|
System.Single |
M11
Gets and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and 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 and sets the value at row 4, column 4 of this instance.
Declaration
public float M44 { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
Offset
Gets the offset part of the matrix as a float3 instance.
Declaration
public readonly float3 Offset { get; }
Property Value
Type | Description |
---|---|
float3 |
Remarks
The offset part of the matrix consists of the M14, M24 and M34 components (in row major order notation).
ParseConverter
Gets and sets the Converter object. Has the ability to convert a string to a float4x4.
Declaration
public static Converter<string, float4x4> ParseConverter { get; set; }
Property Value
Type | Description |
---|---|
Converter<System.String, float4x4> | The parse property. |
Trace
Returns the trace of this matrix
Declaration
public readonly float Trace { get; }
Property Value
Type | Description |
---|---|
System.Single |
Methods
Add(in float4x4, in float4x4)
Adds two instances.
Declaration
public static float4x4 Add(in float4x4 left, in float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | The left operand of the addition. |
float4x4 | right | The right operand of the addition. |
Returns
Type | Description |
---|---|
float4x4 | A new instance that is the result of the addition. |
CreateFromAxisAngle(float3, Single)
Build a rotation matrix from the specified axis/angle rotation.
Declaration
public static float4x4 CreateFromAxisAngle(float3 axis, float angle)
Parameters
Type | Name | Description |
---|---|---|
float3 | axis | The axis to rotate about. |
System.Single | angle | Angle to rotate counter-clockwise (looking in the direction of the given axis). |
Returns
Type | Description |
---|---|
float4x4 | A matrix instance. |
CreateOrthographic(Single, Single, Single, Single)
Creates a left handed orthographic projection matrix.
Declaration
public static float4x4 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 |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateOrthographicOffCenter(Single, Single, Single, Single, Single, Single)
Creates a left handed orthographic projection matrix.
Declaration
public static float4x4 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 |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateOrthographicOffCenterRH(Single, Single, Single, Single, Single, Single)
Creates a right handed orthographic projection matrix.
Declaration
public static float4x4 CreateOrthographicOffCenterRH(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 |
---|---|
float4x4 | The resulting float4x4 instance. |
CreatePerspectiveFieldOfView(Single, Single, Single, Single)
Creates a left handed perspective projection matrix.
Declaration
public static float4x4 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 |
---|---|
float4x4 | 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 left handed perspective projection matrix.
Declaration
public static float4x4 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 |
---|---|
float4x4 | A projection matrix that transforms camera space to raster space |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown under the following conditions:
|
CreatePerspectiveOffCenterRH(Single, Single, Single, Single, Single, Single)
Creates a right handed perspective projection matrix.
Declaration
public static float4x4 CreatePerspectiveOffCenterRH(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 |
---|---|
float4x4 | A right handed projection matrix that transforms camera space to raster space |
Remarks
Generates a matrix mapping a frustum shaped volume (the viewing frustum) to the unit cube (ranging from -1 to 1 in each dimension, also in z). The sign of the z-value will be flipped for vectors multiplied with this matrix. Given that the underlying rendering platform interprets z-values returned by the vertex shader to be in left-handed coordinates, where increasing z-values indicate locations further away from the view point (as BOTH, Direct3D AND OpenGL do), this type of matrix is widely called to be a "right handed" projection matrix as it assumes a right-handed camera coordinate system.
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 float4x4 CreateRotationX(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateRotationXY(float2)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationXY(float2 xy)
Parameters
Type | Name | Description |
---|---|---|
float2 | xy | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationXY(Single, Single)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationXY(float x, float y)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | counter-clockwise angles in radians. |
System.Single | y | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationY(Single)
Builds a rotation matrix for a rotation around the y-axis.
Declaration
public static float4x4 CreateRotationY(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateRotationZ(Single)
Builds a rotation matrix for a rotation around the z-axis.
Declaration
public static float4x4 CreateRotationZ(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The counter-clockwise angle in radians. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateRotationZX(float2)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationZX(float2 xz)
Parameters
Type | Name | Description |
---|---|---|
float2 | xz | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationZX(Single, Single)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationZX(float x, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | counter-clockwise angles in radians. |
System.Single | z | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationZXY(float3)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationZXY(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationZXY(Single, Single, Single)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationZXY(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | counter-clockwise angles in radians. |
System.Single | y | counter-clockwise angles in radians. |
System.Single | z | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationZY(float2)
Builds a rotation matrix for a rotation around the y and z-axis.
Declaration
public static float4x4 CreateRotationZY(float2 yz)
Parameters
Type | Name | Description |
---|---|---|
float2 | yz | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateRotationZY(Single, Single)
Builds a rotation matrix for a rotation around the y and x-axis.
Declaration
public static float4x4 CreateRotationZY(float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | y | counter-clockwise angles in radians. |
System.Single | z | counter-clockwise angles in radians. |
Returns
Type | Description |
---|---|
float4x4 |
CreateScale(float3)
Creates a scale matrix.
Declaration
public static float4x4 CreateScale(float3 vector)
Parameters
Type | Name | Description |
---|---|---|
float3 | vector | The scale vector. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateScale(Single)
Creates a uniform scale matrix with the same scale value along all three dimensions.
Declaration
public static float4x4 CreateScale(float scale)
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | The value to scale about x, y, and z. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateScale(Single, Single, Single)
Creates a scale matrix.
Declaration
public static float4x4 CreateScale(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | X scale. |
System.Single | y | Y scale. |
System.Single | z | Z scale. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateTranslation(float3)
Creates a translation matrix.
Declaration
public static float4x4 CreateTranslation(float3 vector)
Parameters
Type | Name | Description |
---|---|---|
float3 | vector | The translation vector. |
Returns
Type | Description |
---|---|
float4x4 | The resulting float4x4 instance. |
CreateTranslation(Single, Single, Single)
Creates a translation matrix.
Declaration
public static float4x4 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 |
---|---|
float4x4 | The resulting float4x4 instance. |
Equals(float4x4)
Indicates whether the current matrix is equal to another matrix.
Declaration
public readonly bool Equals(float4x4 other)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | other | A 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 readonly 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
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
GetScale(float4x4)
Calculates the scale factor of the given float4x4 and returns it as a float3 vector.
Declaration
public static float3 GetScale(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat |
Returns
Type | Description |
---|---|
float3 |
GetTranslation(float4x4)
Calculates translation of the given float4x4 matrix and returns it as a float3 vector.
Declaration
public static float3 GetTranslation(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat |
Returns
Type | Description |
---|---|
float3 |
Invert()
Converts this instance into its inverse.
Declaration
public float4x4 Invert()
Returns
Type | Description |
---|---|
float4x4 |
Invert(in float4x4)
Calculate the inverse of the given matrix. If you are unsure whether the matrix is invertible, check it with IsInvertable() first.
Declaration
public static float4x4 Invert(in float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | The matrix to invert. |
Returns
Type | Description |
---|---|
float4x4 | The inverse of the given matrix. |
IsInvertable(float4x4)
Checks if this matrix is invertible.
Declaration
public static bool IsInvertable(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat | The matrix. |
Returns
Type | Description |
---|---|
System.Boolean |
IsInvertable(float4x4, out Single)
Checks if this matrix is invertible.
Declaration
public static bool IsInvertable(float4x4 mat, out float det)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat | The matrix. |
System.Single | det | The determinant of the matrix. |
Returns
Type | Description |
---|---|
System.Boolean |
LookAt(float3, float3, float3)
Build a left handed world space to camera space matrix
Declaration
public static float4x4 LookAt(float3 eye, float3 target, float3 up)
Parameters
Type | Name | Description |
---|---|---|
float3 | eye | Eye (camera) position in world space |
float3 | target | Target position in world space |
float3 | up | Up vector in world space (should not be parallel to the camera direction, that is target - eye) |
Returns
Type | Description |
---|---|
float4x4 | 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 float4x4 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 |
---|---|
float4x4 | A float4x4 that transforms world space to camera space |
LookAtRH(float3, float3, float3)
Build a right handed world space to camera space matrix
Declaration
public static float4x4 LookAtRH(float3 eye, float3 target, float3 up)
Parameters
Type | Name | Description |
---|---|---|
float3 | eye | Eye (camera) position in world space |
float3 | target | Target position in world space |
float3 | up | Up vector in world space (should not be parallel to the camera direction, that is target - eye) |
Returns
Type | Description |
---|---|
float4x4 | A float4x4 that transforms world space to camera space |
Mult(in float4x4, in float4x4)
Multiplies two instances.
Declaration
public static float4x4 Mult(in float4x4 left, in float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | The left operand of the multiplication. |
float4x4 | right | The right operand of the multiplication. |
Returns
Type | Description |
---|---|
float4x4 | A new instance that is the result of the multiplication |
Parse(String, IFormatProvider)
Parses a string into a float4x4.
Declaration
public static float4x4 Parse(string source, IFormatProvider provider = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | |
System.IFormatProvider | provider |
Returns
Type | Description |
---|---|
float4x4 |
RotationComponent()
The rotation component of this matrix.
Declaration
public float4x4 RotationComponent()
Returns
Type | Description |
---|---|
float4x4 |
RotationDecomposition(float4x4)
Calculates and returns the rotation component of the given float4x4 matrix.
Declaration
public static float4x4 RotationDecomposition(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat |
Returns
Type | Description |
---|---|
float4x4 |
RotMatToEuler(float4x4)
Returns the euler angles from a given rotation matrix.
Declaration
public static float3 RotMatToEuler(float4x4 rotMat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | rotMat | The roation matrix. |
Returns
Type | Description |
---|---|
float3 |
Round()
Rounds this instance to 6 digits (max float precision).
Declaration
public float4x4 Round()
Returns
Type | Description |
---|---|
float4x4 |
Round(float4x4)
Rounds the given matrix to 6 digits (max float precision).
Declaration
public static float4x4 Round(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat | The matrix to round. |
Returns
Type | Description |
---|---|
float4x4 | The rounded matrix. |
Scale()
The scale factors of this matrix.
Declaration
public float3 Scale()
Returns
Type | Description |
---|---|
float3 |
Scale(float3)
Build a scaling matrix
Declaration
public static float4x4 Scale(float3 scale)
Parameters
Type | Name | Description |
---|---|---|
float3 | scale | Scale factors for x,y and z axes |
Returns
Type | Description |
---|---|
float4x4 | A scaling matrix |
Scale(Single)
Build a scaling matrix
Declaration
public static float4x4 Scale(float scale)
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | Single scale factor for x,y and z axes |
Returns
Type | Description |
---|---|
float4x4 | A scaling matrix |
Scale(Single, Single, Single)
Build a scaling matrix
Declaration
public static float4x4 Scale(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | Scale factor for x-axis |
System.Single | y | Scale factor for y-axis |
System.Single | z | Scale factor for z-axis |
Returns
Type | Description |
---|---|
float4x4 | A scaling matrix |
ScaleComponent()
The scale component of this matrix.
Declaration
public float4x4 ScaleComponent()
Returns
Type | Description |
---|---|
float4x4 |
ScaleDecomposition(float4x4)
Calculates and returns the scale component of the given float4x4 matrix.
Declaration
public static float4x4 ScaleDecomposition(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat |
Returns
Type | Description |
---|---|
float4x4 |
Subtract(in float4x4, in float4x4)
Subtracts the right instance from the left instance.
Declaration
public static float4x4 Subtract(in float4x4 left, in float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | The left operand of the subtraction. |
float4x4 | right | The right operand of the subtraction. |
Returns
Type | Description |
---|---|
float4x4 | A new instance that is the result of the subtraction. |
ToArray()
Returns the matrix as float array.
Declaration
public float[] ToArray()
Returns
Type | Description |
---|---|
System.Single[] |
ToString()
Returns a System.String that represents the current float4x4.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string. |
Overrides
ToString(IFormatProvider)
Returns a System.String that represents the current float4x4.
Declaration
public string ToString(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider | Provides information about a specific culture. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Transform(float4x4, float3)
Transforms a given 3D vector by a matrix using perspective division via matrix*vector (Postmultiplication of the vector).
Declaration
public static float3 Transform(float4x4 matrix, float3 vector)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | A float4x4 instance. |
float3 | vector | A float3 instance. |
Returns
Type | Description |
---|---|
float3 | A new float3 instance containing the result. |
Remarks
Before the matrix multiplication the 3D vector is extended to 4D by setting its W component to 1. After the matrix multiplication the resulting 4D vector is transformed to 3D by dividing X, Y, and Z by W. (perspective division).
Transform(float4x4, float4)
Transforms a given vector by a matrix via matrix*vector (Postmultiplication of the vector).
Declaration
public static float4 Transform(float4x4 matrix, float4 vector)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | A float4x4 instance. |
float4 | vector | A float4 instance. |
Returns
Type | Description |
---|---|
float4 | A new float4 instance containing the result. |
TransformPerspective(float4x4, float3)
Transforms a given 3D vector by a matrix, and projects the resulting float4 back to a float3.
Declaration
public static float3 TransformPerspective(float4x4 mat, float3 vec)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat | The desired transformation matrix. |
float3 | vec | The given vector. |
Returns
Type | Description |
---|---|
float3 | The transformed vector. |
TransformPerspective(float4x4, float4)
Transforms the given vector by the given matrix and applies a perspective division.
Declaration
public static float4 TransformPerspective(float4x4 mat, float4 vec)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat | The desired transformation. |
float4 | vec | The given vector. |
Returns
Type | Description |
---|---|
float4 | The transformed vector. |
TransformPremult(float3, float4x4)
Transforms a given 3D vector by a matrix using perspective division via vector*matrix (Premultiplication of the vector).
Declaration
public static float3 TransformPremult(float3 vector, float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float3 | vector | A float3 instance. |
float4x4 | matrix | A float4x4 instance. |
Returns
Type | Description |
---|---|
float3 | A new float3 instance containing the result. |
Remarks
Before the matrix multiplication the 3D vector is extended to 4D by setting its W component to 1. After the matrix multiplication the resulting 4D vector is transformed to 3D by dividing X, Y, and Z by W. (perspective division).
TransformPremult(float4, float4x4)
Transforms a given vector by a matrix via vector*matrix (Premultiplication of the vector).
Declaration
public static float4 TransformPremult(float4 vector, float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | A float4 instance. |
float4x4 | matrix | A float4x4 instance. |
Returns
Type | Description |
---|---|
float4 | A new float4 instance containing the result. |
Translation()
The translation of this matrix.
Declaration
public float3 Translation()
Returns
Type | Description |
---|---|
float3 |
TranslationComponent()
The translation component of this matrix.
Declaration
public float4x4 TranslationComponent()
Returns
Type | Description |
---|---|
float4x4 |
TranslationDecomposition(float4x4)
Calculates and returns only the translation component of the given float4x4 matrix.
Declaration
public static float4x4 TranslationDecomposition(float4x4 mat)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | mat |
Returns
Type | Description |
---|---|
float4x4 |
Transpose()
Converts this instance into its transpose.
Declaration
public float4x4 Transpose()
Returns
Type | Description |
---|---|
float4x4 |
Transpose(float4x4)
Calculate the transpose of the given matrix
Declaration
public static float4x4 Transpose(float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | The matrix to transpose |
Returns
Type | Description |
---|---|
float4x4 | The transpose of the given matrix |
Operators
Addition(float4x4, float4x4)
Matrix addition
Declaration
public static float4x4 operator +(float4x4 left, float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | left-hand operand |
float4x4 | right | right-hand operand |
Returns
Type | Description |
---|---|
float4x4 | A new float4x4 which holds the result of the multiplication |
Equality(float4x4, float4x4)
Compares two instances for equality.
Declaration
public static bool operator ==(float4x4 left, float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | The first instance. |
float4x4 | right | The second instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if left equals right; false otherwise. |
Explicit(double4x4 to float4x4)
Explicit cast operator to cast a double4x4 into a float4x4 value.
Declaration
public static explicit operator float4x4(double4x4 d4x4)
Parameters
Type | Name | Description |
---|---|---|
double4x4 | d4x4 | The double4x4 value to cast. |
Returns
Type | Description |
---|---|
float4x4 | A float4x4 value. |
Inequality(float4x4, float4x4)
Compares two instances for inequality.
Declaration
public static bool operator !=(float4x4 left, float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | The first instance. |
float4x4 | right | The second instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if left does not equal right; false otherwise. |
Multiply(float3, float4x4)
Transforms a given three dimensional vector by a matrix via vector*matrix (pre-multiplication of the vector).
Declaration
public static float3 operator *(float3 vector, float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float3 | vector | A float3 instance. |
float4x4 | matrix | A float4x4 instance. |
Returns
Type | Description |
---|---|
float3 | A new float4 instance containing the result. |
Remarks
Before the matrix multiplication the 3D vector is extended to 4D by setting its W component to 1. After the matrix multiplication the resulting 4D vector is transformed to 3D by dividing X, Y, and Z by W. (perspective division).
Multiply(float4, float4x4)
Transforms a given vector by a matrix via vector*matrix (pre-multiplication of the vector).
Declaration
public static float4 operator *(float4 vector, float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float4 | vector | A float4 instance. |
float4x4 | matrix | A float4x4 instance. |
Returns
Type | Description |
---|---|
float4 | A new float4 instance containing the result. |
Multiply(float4x4, float3)
Transforms a given three dimensional vector by a matrix via matrix*vector (post-multiplication of the vector).
Declaration
public static float3 operator *(float4x4 matrix, float3 vector)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | A float4x4 instance. |
float3 | vector | A float3 instance. |
Returns
Type | Description |
---|---|
float3 | A new float4 instance containing the result. |
Remarks
Before the matrix multiplication the 3D vector is extended to 4D by setting its W component to 1. After the matrix multiplication the resulting 4D vector is transformed to 3D by dividing X, Y, and Z by W. (perspective division).
Multiply(float4x4, float4)
Transforms a given vector by a matrix via matrix*vector (post-multiplication of the vector).
Declaration
public static float4 operator *(float4x4 matrix, float4 vector)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | A float4x4 instance. |
float4 | vector | A float4 instance. |
Returns
Type | Description |
---|---|
float4 | A new float4 instance containing the result. |
Multiply(float4x4, float4x4)
Matrix multiplication
Declaration
public static float4x4 operator *(float4x4 left, float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | left-hand operand |
float4x4 | right | right-hand operand |
Returns
Type | Description |
---|---|
float4x4 | A new Matrix44 which holds the result of the multiplication |
Subtraction(float4x4, float4x4)
Matrix subtraction
Declaration
public static float4x4 operator -(float4x4 left, float4x4 right)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | left | left-hand operand |
float4x4 | right | right-hand operand |
Returns
Type | Description |
---|---|
float4x4 | A new float2x2 which holds the result of the multiplication |