FastMathAbout FastMath Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers License |
record TMatrix4
Unit
Neslib.FastMath
Declaration
type TMatrix4 = record
Description
A 4x4 matrix in row-major order (M[Row, Column]). You can access the elements directly using M[0,0]..M[3,3] or m11..m44. You can also access the matrix using its four rows R[0]..R[3] (which map directly to the elements M[]).
TMatrix4 is compatible with TMatrix3D in the Delphi RTL. You can typecast between these two types or implicitly convert from one to the other through assignment (eg. MyMatrix4 := MyMatrix3D).
When the conditional define FM_COLUMN_MAJOR is set, the matrix is stored in column-major order instead (M[Column, Row]), and the Rows property and R fields are replaced by Columns and C respectively. Also, in that case assigning an RTL TMatrix3D to a TMatrix4 will transpose the matrix to keep behavior the same.
Overview
Fields
Methods
procedure Init; overload; inline; |
procedure Init(const ADiagonal: Single); overload; inline; |
procedure Init(const ARow0, ARow1, ARow2, ARow3: TVector4); overload; inline; |
procedure Init(const A11, A12, A13, A14, A21, A22, A23, A24, A31, A32, A33, A34, A41, A42, A43, A44: Single); overload; inline; |
procedure Init(const AMatrix: TMatrix2); overload; inline; |
procedure Init(const AMatrix: TMatrix3); overload; inline; |
procedure InitScaling(const AScale: Single); overload; |
procedure InitScaling(const AScaleX, AScaleY, AScaleZ: Single); overload; inline; |
procedure InitScaling(const AScale: TVector3); overload; inline; |
procedure InitTranslation(const ADeltaX, ADeltaY, ADeltaZ: Single); overload; inline; |
procedure InitTranslation(const ADelta: TVector3); overload; inline; |
procedure InitRotationX(const AAngle: Single); |
procedure InitRotationY(const AAngle: Single); |
procedure InitRotationZ(const AAngle: Single); |
procedure InitRotation(const AAxis: TVector3; const AAngle: Single); |
procedure InitRotationYawPitchRoll(const AYaw, APitch, ARoll: Single); |
procedure InitRotationHeadingPitchBank(const AHeading, APitch, ABank: Single); |
procedure InitLookAtLH(const ACameraPosition, ACameraTarget, ACameraUp: TVector3); |
procedure InitLookAtRH(const ACameraPosition, ACameraTarget, ACameraUp: TVector3); |
procedure InitLookAtDirLH(const ACameraPosition, ACameraDirection, ACameraUp: TVector3); |
procedure InitLookAtDirRH(const ACameraPosition, ACameraDirection, ACameraUp: TVector3); |
procedure InitOrthoLH(const AWidth, AHeight, AZNearPlane, AZFarPlane: Single); |
procedure InitOrthoRH(const AWidth, AHeight, AZNearPlane, AZFarPlane: Single); |
procedure InitOrthoOffCenterLH(const ALeft, ATop, ARight, ABottom, AZNearPlane, AZFarPlane: Single); |
procedure InitOrthoOffCenterRH(const ALeft, ATop, ARight, ABottom, AZNearPlane, AZFarPlane: Single); |
procedure InitPerspectiveFovLH(const AFieldOfView, AAspectRatio, ANearPlaneDistance, AFarPlaneDistance: Single; const AHorizontalFOV: Boolean = False); |
procedure InitPerspectiveFovRH(const AFieldOfView, AAspectRatio, ANearPlaneDistance, AFarPlaneDistance: Single; const AHorizontalFOV: Boolean = False); |
class operator Implicit(const A: TMatrix3D): TMatrix4; inline; |
class operator Implicit(const A: TMatrix4): TMatrix3D; inline; |
class operator Equal(const A, B: TMatrix4): Boolean; inline; |
class operator NotEqual(const A, B: TMatrix4): Boolean; inline; |
class operator Negative(const A: TMatrix4): TMatrix4; |
class operator Add(const A: TMatrix4; const B: Single): TMatrix4; |
class operator Add(const A: Single; const B: TMatrix4): TMatrix4; |
class operator Add(const A, B: TMatrix4): TMatrix4; |
class operator Subtract(const A: TMatrix4; const B: Single): TMatrix4; |
class operator Subtract(const A: Single; const B: TMatrix4): TMatrix4; |
class operator Subtract(const A, B: TMatrix4): TMatrix4; |
class operator Multiply(const A: TMatrix4; const B: Single): TMatrix4; |
class operator Multiply(const A: Single; const B: TMatrix4): TMatrix4; |
class operator Multiply(const A: TMatrix4; const B: TVector4): TVector4; |
class operator Multiply(const A: TVector4; const B: TMatrix4): TVector4; |
class operator Multiply(const A, B: TMatrix4): TMatrix4; |
class operator Divide(const A: TMatrix4; const B: Single): TMatrix4; |
class operator Divide(const A: Single; const B: TMatrix4): TMatrix4; |
class operator Divide(const A: TMatrix4; const B: TVector4): TVector4; |
class operator Divide(const A: TVector4; const B: TMatrix4): TVector4; |
class operator Divide(const A, B: TMatrix4): TMatrix4; inline; |
function CompMult(const AOther: TMatrix4): TMatrix4; |
function Transpose: TMatrix4; |
procedure SetTransposed; |
function Inverse: TMatrix4; |
procedure SetInversed; |
Properties
property Rows[constAIndex:Integer]: TVector4 read GetRow write SetRow; |
property Components[constARow,AColumn:Integer]: Single read GetComponent write SetComponent; |
property Determinant: Single read GetDeterminant; |
Description
Fields
V: array [0..3] of TVector4 |
Row or column vectors, depending on FM_COLUMN_MAJOR define
|
R: array [0..3] of TVector4 |
The four row vectors making up the matrix
|
M: array [0..3, 0..3] of Single |
The elements of the matrix in row-major order
|
Methods
procedure Init; overload; inline; |
Initializes the matrix to an identity matrix (filled with 0 and value 1 for the diagonal)
|
procedure Init(const ADiagonal: Single); overload; inline; |
Fills the matrix with zeros and sets the diagonal.
Parameters
- ADiagonal
- the value to use for the diagonal. Use 1 to set the matrix to an identity matrix.
|
procedure Init(const ARow0, ARow1, ARow2, ARow3: TVector4); overload; inline; |
Initializes the matrix using four row vectors.
Parameters
- ARow0
- the first row of the matrix.
- ARow1
- the second row of the matrix.
- ARow2
- the third row of the matrix.
- ARow3
- the fourth row of the matrix.
|
procedure Init(const A11, A12, A13, A14, A21, A22, A23, A24, A31, A32, A33, A34, A41, A42, A43, A44: Single); overload; inline; |
Initializes the matrix with explicit values.
Parameters: A11-A44: the values of the matrix elements, in row-major order.
|
procedure Init(const AMatrix: TMatrix2); overload; inline; |
Initializes the matrix with a 2x2 matrix. The 2x2 matrix is copied to the top-left corner of the 4x4 matrix, and the remaining elements are set according to an identity matrix.
Parameters
- AMatrix
- the source 2x2 matrix.
|
procedure Init(const AMatrix: TMatrix3); overload; inline; |
Initializes the matrix with a 3x3 matrix. The 3x3 matrix is copied to the top-left corner of the 4x4 matrix, and the remaining elements are set according to an identity matrix.
Parameters
- AMatrix
- the source 3x3 matrix.
|
procedure InitScaling(const AScale: Single); overload; |
Creates a scaling matrix that scales uniformly.
Parameters
- AScale
- the uniform scale factor
|
procedure InitScaling(const AScaleX, AScaleY, AScaleZ: Single); overload; inline; |
Creates a scaling matrix.
Parameters
- AScaleX
- the value to scale by on the X axis
- AScaleY
- the value to scale by on the Y axis
- AScaleZ
- the value to scale by on the Z axis
|
procedure InitScaling(const AScale: TVector3); overload; inline; |
Creates a scaling matrix.
Parameters
- AScale
- the scale factors
|
procedure InitTranslation(const ADeltaX, ADeltaY, ADeltaZ: Single); overload; inline; |
Creates a translation matrix.
Parameters
- ADeltaX
- translation in the X direction
- ADeltaY
- translation in the Y direction
- ADeltaZ
- translation in the Z direction
|
procedure InitTranslation(const ADelta: TVector3); overload; inline; |
Creates a translation matrix.
Parameters
- ADelta
- translation vector
|
procedure InitRotationX(const AAngle: Single); |
Creates a matrix for rotating points around the X axis.
Parameters
- AAngle
- the rotation angle around the X axis, in radians
|
procedure InitRotationY(const AAngle: Single); |
Creates a matrix for rotating points around the Y axis.
Parameters
- AAngle
- the rotation angle around the Y axis, in radians
|
procedure InitRotationZ(const AAngle: Single); |
Creates a matrix for rotating points around the Z axis.
Parameters
- AAngle
- the rotation angle around the Z axis, in radians
|
procedure InitRotation(const AAxis: TVector3; const AAngle: Single); |
Creates a matrix for rotating points around a certain axis.
Parameters
- AAxis
- the direction of the axis to rotate around.
- AAngle
- the rotation angle around AAxis, in radians
|
procedure InitRotationYawPitchRoll(const AYaw, APitch, ARoll: Single); |
Creates a rotation matrix from a yaw, pitch and roll angle.
Parameters
- AYaw
- the rotation angle around the Y axis, in radians
- APitch
- the rotation angle around the X axis, in radians
- ARoll
- the rotation angle around the Z axis, in radians
|
procedure InitRotationHeadingPitchBank(const AHeading, APitch, ABank: Single); |
Creates a rotation matrix from a heading, pitch and bank angle.
Parameters
- AHeading
- the heading angle, in radians
- APitch
- the pitch angle, in radians
- ABank
- the bank angle, in radians
|
procedure InitLookAtLH(const ACameraPosition, ACameraTarget, ACameraUp: TVector3); |
Creates a left-handed view matrix looking at a certain target.
Parameters
- ACameraPosition
- position of the camera (or eye).
- ACameraTarget
- the target towards which the camera is pointing.
- ACameraUp
- the direction that is "up" from the camera's point of view
|
procedure InitLookAtRH(const ACameraPosition, ACameraTarget, ACameraUp: TVector3); |
Creates a right-handed view matrix looking at a certain target.
Parameters
- ACameraPosition
- position of the camera (or eye).
- ACameraTarget
- the target towards which the camera is pointing.
- ACameraUp
- the direction that is "up" from the camera's point of view
|
procedure InitLookAtDirLH(const ACameraPosition, ACameraDirection, ACameraUp: TVector3); |
Creates a left-handed view matrix looking into a certain direction.
Parameters
- ACameraPosition
- position of the camera (or eye).
- ACameraDirection
- the direction the camera is pointing in.
- ACameraUp
- the direction that is "up" from the camera's point of view
|
procedure InitLookAtDirRH(const ACameraPosition, ACameraDirection, ACameraUp: TVector3); |
Creates a right-handed view matrix looking into a certain direction.
Parameters
- ACameraPosition
- position of the camera (or eye).
- ACameraDirection
- the direction the camera is pointing in.
- ACameraUp
- the direction that is "up" from the camera's point of view
|
procedure InitOrthoLH(const AWidth, AHeight, AZNearPlane, AZFarPlane: Single); |
Creates a left-handed orthographic projection matrix from the given view volume dimensions.
Parameters
- AWidth
- the width of the view volume.
- AHeight
- the height of the view volume.
- AZNearPlane
- the minimum Z-value of the view volume.
- AZFarPlane
- the maximum Z-value of the view volume.
|
procedure InitOrthoRH(const AWidth, AHeight, AZNearPlane, AZFarPlane: Single); |
Creates a right-handed orthographic projection matrix from the given view volume dimensions.
Parameters
- AWidth
- the width of the view volume.
- AHeight
- the height of the view volume.
- AZNearPlane
- the minimum Z-value of the view volume.
- AZFarPlane
- the maximum Z-value of the view volume.
|
procedure InitOrthoOffCenterLH(const ALeft, ATop, ARight, ABottom, AZNearPlane, AZFarPlane: Single); |
Creates a customized left-handed orthographic projection matrix.
Parameters
- ALeft
- the minimum X-value of the view volume.
- ATop
- the maximum Y-value of the view volume.
- ARight
- the maximum X-value of the view volume.
- ABottom
- the minimum Y-value of the view volume.
- AZNearPlane
- the minimum Z-value of the view volume.
- AZFarPlane
- the maximum Z-value of the view volume.
|
procedure InitOrthoOffCenterRH(const ALeft, ATop, ARight, ABottom, AZNearPlane, AZFarPlane: Single); |
Creates a customized right-handed orthographic projection matrix.
Parameters
- ALeft
- the minimum X-value of the view volume.
- ATop
- the maximum Y-value of the view volume.
- ARight
- the maximum X-value of the view volume.
- ABottom
- the minimum Y-value of the view volume.
- AZNearPlane
- the minimum Z-value of the view volume.
- AZFarPlane
- the maximum Z-value of the view volume.
|
procedure InitPerspectiveFovLH(const AFieldOfView, AAspectRatio, ANearPlaneDistance, AFarPlaneDistance: Single; const AHorizontalFOV: Boolean = False); |
Creates a left-handed perspective projection matrix based on a field of view, aspect ratio, and near and far view plane distances.
Parameters
- AFieldOfView
- the field of view in radians.
- AAspectRatio
- the aspect ratio, defined as view space width divided by height.
- ANearPlaneDistance
- the distance to the near view plane.
- AFarPlaneDistance
- the distance to the far view plane.
- AHorizontalFOV
- (optional) boolean indicating the direction of the field of view. If False (default), AFieldOfView is in the Y direction, otherwise in the X direction
|
procedure InitPerspectiveFovRH(const AFieldOfView, AAspectRatio, ANearPlaneDistance, AFarPlaneDistance: Single; const AHorizontalFOV: Boolean = False); |
Creates a right-handed perspective projection matrix based on a field of view, aspect ratio, and near and far view plane distances.
Parameters
- AFieldOfView
- the field of view in radians.
- AAspectRatio
- the aspect ratio, defined as view space width divided by height.
- ANearPlaneDistance
- the distance to the near view plane.
- AFarPlaneDistance
- the distance to the far view plane.
- AHorizontalFOV
- (optional) boolean indicating the direction of the field of view. If False (default), AFieldOfView is in the Y direction, otherwise in the X direction
|
class operator Implicit(const A: TMatrix3D): TMatrix4; inline; |
Implicitly converts a TMatrix3D to a TMatrix4.
|
class operator Implicit(const A: TMatrix4): TMatrix3D; inline; |
Implicitly converts a TMatrix4 to a TMatrix3D.
|
class operator Equal(const A, B: TMatrix4): Boolean; inline; |
Checks two matrices for equality.
Returns
True if the two matrices match each other exactly. |
class operator NotEqual(const A, B: TMatrix4): Boolean; inline; |
Checks two matrices for inequality.
Returns
True if the two matrices are not equal. |
class operator Negative(const A: TMatrix4): TMatrix4; |
Negates a matrix.
Returns
The negative value of the matrix (with all elements negated). |
class operator Add(const A: TMatrix4; const B: Single): TMatrix4; |
Adds a scalar value to each element of a matrix.
|
class operator Add(const A: Single; const B: TMatrix4): TMatrix4; |
Adds a scalar value to each element of a matrix.
|
class operator Add(const A, B: TMatrix4): TMatrix4; |
Adds two matrices component-wise.
|
class operator Subtract(const A: TMatrix4; const B: Single): TMatrix4; |
Subtracts a scalar value from each element of a matrix.
|
class operator Subtract(const A: Single; const B: TMatrix4): TMatrix4; |
Subtracts a matrix from a scalar value.
|
class operator Subtract(const A, B: TMatrix4): TMatrix4; |
Subtracts two matrices component-wise.
|
class operator Multiply(const A: TMatrix4; const B: Single): TMatrix4; |
Multiplies a matrix with a scalar value.
|
class operator Multiply(const A: Single; const B: TMatrix4): TMatrix4; |
Multiplies a matrix with a scalar value.
|
class operator Multiply(const A: TMatrix4; const B: TVector4): TVector4; |
Performs a matrix * row vector linear algebraic multiplication.
|
class operator Multiply(const A: TVector4; const B: TMatrix4): TVector4; |
Performs a column vector * matrix linear algebraic multiplication.
|
class operator Multiply(const A, B: TMatrix4): TMatrix4; |
Multiplies two matrices using linear algebraic multiplication.
|
class operator Divide(const A: TMatrix4; const B: Single): TMatrix4; |
Divides a matrix by a scalar value.
|
class operator Divide(const A: Single; const B: TMatrix4): TMatrix4; |
Divides a scalar value by a matrix.
|
class operator Divide(const A: TMatrix4; const B: TVector4): TVector4; |
Divides a matrix by a vector. This is equivalent to multiplying the inverse of the matrix with a row vector using linear algebraic multiplication.
|
class operator Divide(const A: TVector4; const B: TMatrix4): TVector4; |
Divides a vector by a matrix. This is equivalent to multiplying a column vector with the inverse of the matrix using linear algebraic multiplication.
|
class operator Divide(const A, B: TMatrix4): TMatrix4; inline; |
Divides two matrices. This is equivalent to multiplying the first matrix with the inverse of the second matrix using linear algebraic multiplication.
|
function CompMult(const AOther: TMatrix4): TMatrix4; |
Multiplies this matrix with another matrix component-wise.
Note: For linear algebraic matrix multiplication, use the multiply (*) operator instead.
Parameters
- AOther
- the other matrix.
Returns
This matrix multiplied by AOther component-wise. That is, Result.M[I,J] := M[I,J] * AOther.M[I,J]. |
function Transpose: TMatrix4; |
Creates a transposed version of this matrix.
Note: Does not change this matrix. To update this itself, use SetTransposed.
Returns
The transposed version of this matrix. |
procedure SetTransposed; |
Transposes this matrix.
Note: If you do not want to change this matrix, but get a transposed version instead, then use Transpose.
|
function Inverse: TMatrix4; |
Calculates the inverse of this matrix.
Note: Does not change this matrix. To update this itself, use SetInversed.
Note: The values in the returned matrix are undefined if this matrix is singular or poorly conditioned (nearly singular).
Returns
The inverse of this matrix. |
procedure SetInversed; |
Inverts this matrix.
Note: If you do not want to change this matrix, but get an inversed version instead, then use Inverse.
Note: The values in the inversed matrix are undefined if this matrix is singular or poorly conditioned (nearly singular).
|
Properties
property Rows[constAIndex:Integer]: TVector4 read GetRow write SetRow; |
Returns the rows of the matrix. This is identical to accessing the R-field.
Parameters
- AIndex
- index of the row to return (0-3). Range is checked with an assertion.
|
property Components[constARow,AColumn:Integer]: Single read GetComponent write SetComponent; |
Returns the elements of the matrix (in row-major order). This is identical to accessing the M-field, but this property can be used as a default array property.
Parameters
- ARow
- the row index (0-3). Range is checked with an assertion.
- AColumn
- the column index (0-3). Range is checked with an assertion.
|
property Determinant: Single read GetDeterminant; |
The determinant of this matrix.
|
Generated by PasDocEx, based on PasDoc 0.14.0.
|