Mat4D

Description

struct Tinman.Core.Math.Vectors.Mat4D

A 4x4 matrix with 64-bit floating-point precision.

/                      \
|  M11  M12  M13  M14  |
|  M21  M22  M23  M24  |
|  M31  M32  M33  M34  |
|  M41  M42  M43  M44  |
\                      /

Public / Constants

Identity


public static readonly attribute Identity → (Mat4D)

The identity matrix.

Zero


public static readonly attribute Zero → (Mat4D)

The zero matrix.

Public / Constructors

From​Columns


[Pure]
public static method FromColumns → (4)

col1 in : Vec4D

The first column vector.

col2 in : Vec4D

The second column vector.

col3 in : Vec4D

The third column vector.

col4 in : Vec4D

The fourth column vector.

returns → Mat4D

The matrix.

Creates a new instance of Mat4D.

From​Rows


[Pure]
public static method FromRows → (4)

row1 in : Vec4D

The first row vector.

row2 in : Vec4D

The second row vector.

row3 in : Vec4D

The third row vector.

row4 in : Vec4D

The fourth row vector.

returns → Mat4D

The matrix.

Creates a new instance of Mat4D.

Look​At


[Pure]
public static method LookAt → (4)

origin in : Vec3D

The origin position.

target in : Vec3D

The look-at position.

up in : Vec3D

The up-direction vector.

rightHanded in : bool

true to create a right-handed coordinate system,
false to create a left-handed one.

returns → Mat4D

The transformation matrix.

Creates a look-at transformation matrix.

Mat4​D


public constructor Mat4D → (16)

m11 in : float64

Matrix component in first row, first column.

m12 in : float64

Matrix component in first row, second column.

m13 in : float64

Matrix component in first row, third column.

m14 in : float64

Matrix component in first row, fourth column.

m21 in : float64

Matrix component in second row, first column.

m22 in : float64

Matrix component in second row, second column.

m23 in : float64

Matrix component in second row, third column.

m24 in : float64

Matrix component in second row, fourth column.

m31 in : float64

Matrix component in third row, first column.

m32 in : float64

Matrix component in third row, second column.

m33 in : float64

Matrix component in third row, third column.

m34 in : float64

Matrix component in third row, fourth column.

m41 opt : float64 = 0

Matrix component in fourth row, first column.

m42 opt : float64 = 0

Matrix component in fourth row, second column.

m43 opt : float64 = 0

Matrix component in fourth row, third column.

m44 opt : float64 = 1

Matrix component in fourth row, fourth column.

Creates a new instance of Mat4D.

Orthographic


[Pure]
public static method Orthographic → (7)

left in : float64

The X-coordinate to map to -1.

right in : float64

The X-coordinate to map to +1.

top in : float64

The Y-coordinate to map to -1.

bottom in : float64

The Y-coordinate to map to +1.

zNear in : float64

The Z-coordinate to map to 0 resp. -1.

zFar in : float64

The Z-coordinate to map to +1.

nearAtZero in : bool

true to map zNear in to 0,
false to map zNear in to -1.

returns → Mat4D

The projection matrix.

Creates an orthographic projection matrix.

Perspective​Fov


[Pure]
public static method PerspectiveFov → (6)

fov in : float64

The field-of-view along the viewport Y-axis, in radians.

aspect in : float64

The viewport aspect ratio (width divided by height).

in : float64

Near clipping plane Z-value (will be mapped to 0 resp. -1 in clip-space; see nearAtZero in for details).

in : float64

Far clipping plane Z-value (will be mapped to 1 in clip-space).

nearAtZero in : bool

When true, the near clipping plane will be mapped to 0 in clip-space (e.g. Direct3D); when false it will be mapped to -1 (e.g. OpenGL).

rightHanded in : bool

Create projection matrix for a right-handed (true) or left-handed (false) coordinate system?

returns → Mat4D

The projection matrix.

Creates a perspective projection matrix.

Rotate

2 overloads


[Pure]
public static method Rotate1 → (2)

axis in : Vec3D

Unit-length rotation axis vector.

angle in : float64

The rotation angle, in radians.

returns → Mat4D

The resulting matrix.

Returns a rotation matrix (counter-clockwise around the given axis for right-handed coordinate system).


[Pure]
public static method Rotate2 → (4)

in : float64

X-component of unit-length rotation axis vector.

in : float64

Y-component of unit-length rotation axis vector.

in : float64

Z-component of unit-length rotation axis vector.

angle in : float64

The rotation angle, in radians.

returns → Mat4D

The resulting matrix.

Returns a rotation matrix (counter-clockwise around the given axis for right-handed coordinate system).

Rotate​X


[Pure]
public static method RotateX → (1)

angle in : float64

The rotation angle, in radians.

returns → Mat4D

The resulting matrix.

Returns a rotation matrix (counter-clockwise around X-axis for right-handed coordinate system).

Rotate​Y


[Pure]
public static method RotateY → (1)

angle in : float64

The rotation angle, in radians.

returns → Mat4D

The resulting matrix.

Returns a rotation matrix (counter-clockwise around Y-axis for right-handed coordinate system).

Rotate​Z


[Pure]
public static method RotateZ → (1)

angle in : float64

The rotation angle, in radians.

returns → Mat4D

The resulting matrix.

Returns a rotation matrix (counter-clockwise around Z-axis for right-handed coordinate system).

Scale

3 overloads


[Pure]
public static method Scale1 → (1)

in : float64

The scale factor.

returns → Mat4D

The resulting matrix.

Returns a scaling matrix.


[Pure]
public static method Scale2 → (1)

in : Vec4D

The scale factors.

returns → Mat4D

The resulting matrix.

Returns a scaling matrix.


[Pure]
public static method Scale3 → (4)

fx in : float64

The scale factor along the X-axis.

fy in : float64

The scale factor along the Y-axis.

fz in : float64

The scale factor along the Z-axis.

fw in : float64

The scale factor along the W-axis.

returns → Mat4D

The resulting matrix.

Returns a scaling matrix.

Translate

2 overloads


[Pure]
public static method Translate1 → (1)

in : Vec3D

The translation vector.

returns → Mat4D

The translation matrix.

Returns a translation matrix.


[Pure]
public static method Translate2 → (3)

in : float64

X-component of translation vector.

in : float64

Y-component of translation vector.

in : float64

Z-component of translation vector.

returns → Mat4D

The translation matrix.

Returns a translation matrix.

Warp


[Pure]
public static method Warp → (6)

a0 in : Vec3D

First vertex of source triangle.

b0 in : Vec3D

Second vertex of source triangle.

c0 in : Vec3D

Third vertex of source triangle.

a1 in : Vec3D

First vertex of target triangle.

b1 in : Vec3D

Second vertex of target triangle.

c1 in : Vec3D

Third vertex of target triangle.

returns → Mat4D

The homogeneous 3D warp matrix.

Computes an invertible 3D homogeneous warp matrix that transforms the given source triangle onto the specified target triangle.

The fourth row of the returned matrix will always be (0,0,0,1), so it is not necessary to perform the homogeneous divide. Also all elements along the main diagonal will be 1.

Public / Methods

Equals​Almost


[Pure]
public method EqualsAlmost → (1)

other in : Mat4D

The other matrix.

returns → bool

true if both matrices are similar, false if they are not.

Checks if this matrix and the given one are similar but necessarily equal.

See also

Maths.Similar2

Get​Column


[Pure]
public method GetColumn → (1)

index in : int32

The zero-based column index.

returns → Vec4D

The column vector.

Returns a column vector.

Get​Row


[Pure]
public method GetRow → (1)

index in : int32

The zero-based row index.

returns → Vec4D

The row vector.

Returns a row vector.

Lerp


[Pure]
public method Lerp → (2)

other in : Mat4D

The other matrix.

factor in : float64

The interpolation factor (0: this, 1: other in).

returns → Mat4D

The resulting matrix.

Performs a component-wise linear interpolation between this matrix and the given one.

Mul


[Pure]
public method Mul → (1)

in : Mat4D

The matrix.

returns → Mat4D

The resulting matrix.

Multiplies this matrix (left-side) with the given one (right-side): result = this * m.

Mul3

2 overloads


[Pure]
public method Mul31 → (2)

in : Vec3D

The vector.

in : float64

The W-component to assume.

returns → Vec3D

The resulting vector, scaled by 1/result.W.

Multiplies this matrix (left-side) with the given homogeneous 3D vector (right-side): result = this * v.


[Pure]
public method Mul32 → (4)

in : float64

X-component of vector.

in : float64

Y-component of vector.

in : float64

Z-component of vector.

in : float64

The W-component to assume.

returns → Vec3D

The resulting vector, scaled by 1/result.W.

Multiplies this matrix (left-side) with the given homogeneous 3D vector (right-side): result = this * v.

Mul4

2 overloads


[Pure]
public method Mul41 → (1)

in : Vec4D

The vector.

returns → Vec4D

The resulting vector.

Multiplies this matrix (left-side) with the given 4D vector (right-side): result = this * v.


[Pure]
public method Mul42 → (4)

in : float64

X-component of vector.

in : float64

Y-component of vector.

in : float64

Z-component of vector.

in : float64

W-component of vector.

returns → Vec4D

The resulting vector.

Multiplies this matrix (left-side) with the given 4D vector (right-side): result = this * v.

Perspective​Ray


[Pure]
public method PerspectiveRay → (6)

translation in : Vec3D

The translation components, if they have been omitted in the view projection, otherwise Vec3D.Zero.

pixelX in : float64

Pixel X-coordinate (see remarks).

pixelY in : float64

Pixel Y-coordinate (see remarks).

screenWidth in : int32

Screen width, in pixels.

screenHeight in : int32

Screen height, in pixels.

nearAtZero in : bool

When true, the near clipping plane will be mapped to 0 in clip-space (e.g. Direct3D); when false it will be mapped to -1 (e.g. OpenGL).

returns → Ray

The ray

Computes a ray for a screen-pixel.

This matrix must be the inverse of a combined world-view-projection matrix (for example, PerspectiveFov). The pixel coordinates (0,0) refer to the top-left corner of the top-left screen pixel. The pixel coordinates (w,h) refer to the bottom-right corner of the bottom-right screen pixel (where w and h are the screen width resp. height). If you want to cast rays for pixel centers, you have to add an offset of 0.5 to the pixel coordinates.

To​Array


public method ToArray → (4)

values in : float64 [ ]

[not-null]
The output array.

offset opt : int32 = 0

Offset into values in to top-left matrix element.

strideRow opt : int32 = 4

Array index distance between matrix rows.

strideCol opt : int32 = 1

Array index distance between matrix columns.

Copies matrix elements to the given array.

The method uses the following indexing scheme to write values to values in:

values[offset + (row - 1) * strideRow + (col - 1) * strideCol := matrix[row, col];

where row and col depict the matrix row and column number (starting at 1).

To​String

2 overloads


[Pure]
public method ToString2 → (1)

flags in : FormatFlags

The format flags to use.

returns → string

The string representation.

Returns the string representation of this matrix.

See also

Vec4D.ToString2

Public / Attributes

Determinant


public attribute Determinant → (get)

value : float64

The determinant value.

Returns the determinant of this matrix.

Inverse


public attribute Inverse → (get)

value : Mat4D

The inverse matrix.

Returns the inverse of this matrix.

M11


public readonly attribute M11 → (float64)

Matrix component in first row, first column.

M12


public readonly attribute M12 → (float64)

Matrix component in first row, second column.

M13


public readonly attribute M13 → (float64)

Matrix component in first row, third column.

M14


public readonly attribute M14 → (float64)

Matrix component in first row, fourth column.

M21


public readonly attribute M21 → (float64)

Matrix component in second row, first column.

M22


public readonly attribute M22 → (float64)

Matrix component in second row, second column.

M23


public readonly attribute M23 → (float64)

Matrix component in second row, third column.

M24


public readonly attribute M24 → (float64)

Matrix component in second row, fourth column.

M31


public readonly attribute M31 → (float64)

Matrix component in third row, first column.

M32


public readonly attribute M32 → (float64)

Matrix component in third row, second column.

M33


public readonly attribute M33 → (float64)

Matrix component in third row, third column.

M34


public readonly attribute M34 → (float64)

Matrix component in third row, fourth column.

M41


public readonly attribute M41 → (float64)

Matrix component in fourth row, first column.

M42


public readonly attribute M42 → (float64)

Matrix component in fourth row, second column.

M43


public readonly attribute M43 → (float64)

Matrix component in fourth row, third column.

M44


public readonly attribute M44 → (float64)

Matrix component in fourth row, fourth column.

Transpose


public attribute Transpose → (get)

value : Mat4D

The transposed matrix.

Returns the transpose of this matrix.

Serialization

Serializer


public static readonly attribute Serializer → (ITypeSerializer<Mat4D>)

The serialization helper object for values of Mat4D.