Matrix4x4
¶
Matrix with 4x4 elements.
Functions which can be used to create new instances of Matrix4x4.
Matrix4x4() | Default constructor, initializes the matrix to identity matrix |
Matrix4x4() | Constructs the matrix from elements in column-major order |
Matrix4x4() | Constructs the matrix from four column vectors |
Matrix4x4() | Constructs the matrix from four column vectors |
Default constructor, initializes the matrix to identity matrix.
local matrix4x4 = Matrix4x4()
Constructs the matrix from elements in column-major order.
local matrix4x4 = Matrix4x4(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15)
Constructs the matrix from four column vectors.
local matrix4x4 = Matrix4x4(x, y, z, translation)
Constructs the matrix from four column vectors.
local matrix4x4 = Matrix4x4(x, y, z, translation)
Methods of Matrix4x4 class.
Matrix4x4:getRow() | Gets the row of a matrix |
Matrix4x4:getColumn() | Gets the column of a matrix |
Matrix4x4:setRow() | Sets the row of a matrix |
Matrix4x4:setColumn() | Sets the column of a matrix |
Matrix4x4:getXAxis() | Get X axis |
Matrix4x4:getYAxis() | Get Y axis |
Matrix4x4:getZAxis() | Get Z axis |
Matrix4x4:getScale() | Get scale as a vector |
Matrix4x4:getRotationAngle() | Calculates Euler rotation angles of the matrix |
Matrix4x4:scale() | Scales this matrix |
Matrix4x4:scaleUniform() | Scales this matrix |
Matrix4x4:translate() | Translates this matrix |
Matrix4x4:setXAxis() | Set X axis |
Matrix4x4:setYAxis() | Set Y axis |
Matrix4x4:setZAxis() | Set Z axis |
Matrix4x4:getTranslation() | Get translation |
Matrix4x4:setTranslation() | Set translation |
Matrix4x4:getTranslationX() | Get translation on X axis |
Matrix4x4:setTranslationX() | Set translation on X axis |
Matrix4x4:getTranslationY() | Get translation on Y axis |
Matrix4x4:setTranslationY() | Set translation on Y axis |
Matrix4x4:getTranslationZ() | Get translation on Z axis |
Matrix4x4:setTranslationZ() | Set translation on Z axis |
Matrix4x4.createTranslation() | Creates translation matrix |
Matrix4x4.createTranslation() | Creates translation matrix |
Matrix4x4.createIdentity() | Creates identity matrix |
Matrix4x4.createFromHomogenousMatrix() | Creates a matrix from an existing homogeneous matrix and Z translation |
Matrix4x4.createFromHomogenousMatrix() | Creates a matrix from an existing homogeneous matrix |
Matrix4x4.createRotation() | Creates a rotation matrix over an arbitrary axis |
Matrix4x4.createRotationInDegrees() | Creates a rotation matrix over an arbitrary axis |
Matrix4x4.createXRotationInRadians() | Creates a X rotation matrix |
Matrix4x4.createXRotationInDegrees() | Creates a X rotation matrix |
Matrix4x4.createYRotationInRadians() | Creates a Y rotation matrix |
Matrix4x4.createYRotationInDegrees() | Creates a Y rotation matrix |
Matrix4x4.createZRotationInRadians() | Creates a Z rotation matrix |
Matrix4x4.createZRotationInDegrees() | Creates a Z rotation matrix |
Matrix4x4.createScale() | Creates a scaling matrix |
Matrix4x4.createOrthogonalProjection() | Creates projection matrix for orthogonal projection |
Matrix4x4.createPerspectiveProjection() | Creates a perspective projection matrix for a symmetrical viewing volume |
Matrix4x4.createPerspectiveProjection() | Creates a perspective projection matrix for a viewing volume |
Matrix4x4.createSubProjection() | Calculate sub-quad projection of an existing projection matrix |
Matrix4x4.createLookAtMatrix() | Creates a lookup transformation matrix, so that it is in a given position looking at the given point |
Matrix4x4.createSRT() | Create an SRT matrix |
Matrix4x4.createFilled() | Creates a matrix with all elements set to \p value |
Matrix4x4:transposed() | Applies a transpose to a matrix |
Gets the row of a matrix.
index | (size_t) | Index of the accessed row. |
(Vector4) | The row. |
Gets the column of a matrix.
index | (size_t) | Index of the accessed column. |
(Vector4) | The column. |
Sets the row of a matrix.
index | (size_t) | Index of the accessed row. |
row | (Vector4) | The value to set to the row. |
Sets the column of a matrix.
index | (size_t) | Index of the accessed column. |
column | (Vector4) | The value to set to the column. |
Get X axis.
Get Y axis.
Get Z axis.
Get scale as a vector.
Calculates Euler rotation angles of the matrix. Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y and z.
(Vector3 or nil) | Euler angles in radians, or nil if the matrix is not decomposable. |
Scales this matrix.
scale | (Vector3) | Scaling vector. |
Scales this matrix.
scale | (float) | Uniform scaling value. |
Translates this matrix.
translate | (Vector3) | Translation vector. |
Set X axis.
v | (Vector3) | X axis vector. |
Set Y axis.
v | (Vector3) | Y axis vector. |
Set Z axis.
v | (Vector3) | Z axis vector. |
Get translation.
(Vector3) | Translation vector. |
Set translation.
translation | (Vector3) | Translation vector. |
Get translation on X axis.
(float) | Translation X component. |
Set translation on X axis.
translationX | (float) | Translation X component. |
Get translation on Y axis.
(float) | Translation Y component. |
Set translation on Y axis.
translationY | (float) | Translation Y component. |
Get translation on Z axis.
(float) | Translation Z component. |
Set translation on Z axis.
translationZ | (float) | Translation Y component. |
Creates translation matrix.
translation | (Vector3) | Translation vector. |
(Matrix4x4) | Translation matrix. |
Creates translation matrix.
x | (float) | X component of the Translation vector. |
y | (float) | Y component of the Translation vector. |
z | (float) | Z component of the Translation vector. |
(Matrix4x4) | Translation matrix. |
Creates identity matrix.
(Matrix4x4) | Identity matrix. |
Creates a matrix from an existing homogeneous matrix and Z translation.
matrix | (Matrix3x3) | Homogeneous matrix. |
zTranslation | (float) | X translation. |
(Matrix4x4) | Newly constructed matrix. |
Creates a matrix from an existing homogeneous matrix. 0.0f is used for the Z translation.
matrix | (Matrix3x3) | Homogeneous matrix. |
(Matrix4x4) | Newly constructed matrix. |
Creates a rotation matrix over an arbitrary axis. Similar to the matrix used by glRotatef. The rotation axis needs not be normalized.
angleInRadians | (float) | Rotation angle in radians. |
rotationAxis | (Vector3) | Arbitrary rotation axis. |
(Matrix4x4) | Rotation matrix. |
Creates a rotation matrix over an arbitrary axis. Similar to the matrix used by glRotatef. The rotation axis needs not be normalized.
angleInDegrees | (float) | Rotation angle in degrees. |
rotationAxis | (Vector3) | Arbitrary rotation axis. |
(Matrix4x4) | Rotation matrix. |
Creates a X rotation matrix.
angleInRadians | (float) | Rotation angle in radians. |
(Matrix4x4) | X Rotation matrix. |
Creates a X rotation matrix.
angleInDegrees | (float) | Rotation angle in degrees. |
(Matrix4x4) | X Rotation matrix. |
Creates a Y rotation matrix.
angleInRadians | (float) | Rotation angle in radians. |
(Matrix4x4) | Y Rotation matrix. |
Creates a Y rotation matrix.
angleInDegrees | (float) | Rotation angle in degrees. |
(Matrix4x4) | Y Rotation matrix. |
Creates a Z rotation matrix.
angleInRadians | (float) | Rotation angle in radians. |
(Matrix4x4) | Z Rotation matrix. |
Creates a Z rotation matrix.
angleInDegrees | (float) | Rotation angle in degrees. |
(Matrix4x4) | Z Rotation matrix. |
Creates a scaling matrix.
scale | (Vector3) | Scaling vector. |
(Matrix4x4) | Scaled matrix. |
Creates projection matrix for orthogonal projection.
left | (float) | Viewing box left. |
right | (float) | Viewing box right. |
bottom | (float) | Viewing box bottom. |
top | (float) | Viewing box top. |
near | (float) | Camera near value. |
far | (float) | Camera far value. |
(Matrix4x4) | A newly constructed projection matrix. |
Creates a perspective projection matrix for a symmetrical viewing volume.
near | (float) | Camera near value. |
far | (float) | Camera far value. |
fovType | (FieldOfViewType) | Tells whether the fovInDegrees parameter is xfov or yfov. |
fovInDegrees | (float) | Field of view in degrees. |
aspectRatio | (float) | The aspect ratio of the viewport. |
(Matrix4x4) | Perspective projection matrix. |
Creates a perspective projection matrix for a viewing volume.
near | (float) | Camera near value. |
far | (float) | Camera far value. |
fovInDegrees | (Vector4) | Field of view in degrees, specified in order left, right, up, down. Angles to the right of center and upwards of center are positive. |
(Matrix4x4) | Perspective projection matrix. |
Calculate sub-quad projection of an existing projection matrix.
This is a specific solution for an axis-aligned case.
Old projection matrix = [P00 0 P02 P03] [ 0 P11 P12 P13] [ 0 0 P22 P23] [ 0 0 -1 0]
Traslated and scaled: (x, y) |--> (Ox, Oy) + (Sx * x, Sy * y) [Sx P00, 0, Ox P22 + Sx P02, Ox P23] [ 0, Sy P11, Oy P22 + Sy P12, Oy P23] [ 0, 0, P22, P23] [ 0, 0, -1, 0]
projection | (Matrix4x4) | Projection matrix. |
relativeOffsetX | (float) | X offset of sub-quad as portion of the size of the projection area. |
relativeOffsetY | (float) | Y offset of sub-quad as portion of the size of the projection area. |
relativeSizeX | (float) | Projection area X size in regard to sub-quad area size. |
relativeSizeY | (float) | Projection area Y size in regard to sub-quad area size. |
(Matrix4x4) | Modified projection matrix. |
Creates a lookup transformation matrix, so that it is in a given position looking at the given point.
position | (Vector3) | The new translation of the node. |
lookAtPoint | (Vector3) | A point where the node is looking at. |
upVector | (Vector3) | The new up vector of the node. |
(Matrix4x4 or nil) | Lookup matrix if position is not the same as lookAtPoint and upVector is not null, nil otherwise. |
Create an SRT matrix.
scale | (Vector3) | Scales by axises. |
rotationInRadians | (Vector3) | Rotation component in radians. |
translation | (Vector3) | Translation component. |
(Matrix4x4) | Newly constructed matrix. |
Creates a matrix with all elements set to \p value.
value | (float) | Value to set to all elements. |
(Matrix4x4) | Newly constructed matrix. |
Applies a transpose to a matrix.
(Matrix4x4) | Newly constructed transpose matrix. |
Matrix4x4 specific standalone functions, which are not a part of the Matrix4x4 class.
multiplyAffine() | Multiplies two affine matrices and returns the product |
orthonormalizeBase() | Orthonormalizes base vectors of the given matrix |
matrixMultiplyVectorBy3x3() | Multiplies a 3D vector with the top 3x3 part of a given matrix |
inverse() | Applies an inversion to a matrix |
inverseAffine() | Applies an inversion to an affine matrix |
inverseOrthogonal() | Applies an inversion to an orthogonal affine matrix |
isTranslationOnly() | Returns whether a matrix is translation-only |
extractSRT() | Extracts from a matrix the scale, rotation, and translation information |
extract3x3() | Extracts the 3x3 rotation and scaling part of a matrix |
normalizeBase() | Normalizes base vectors of a matrix |
getDeterminant() | Calculates the determinant of a matrix |
getDeterminant3x3() | Calculates the determinant of the 3x3 part of a matrix |
getTrace() | Calculates the trace of a matrix |
createRelativeOrthogonalProjection() | Creates an orthogonal projection matrix for a symmetrical viewing volume |
calculateCameraViewPosition() | Calculates a homogeneous camera view position that you can use to calculate the view direction in a shader |
componentWiseMultiply() | Multiplies matrix components component-wise and returns the resulting matrix |
componentWiseDivide() | Divides matrix components component-wise and returns the resulting matrix |
componentWiseMax() | Calculates the component-wise maximum for all matrix elements and returns the resulting matrix |
componentWiseMin() | Calculates the component-wise minimum for all matrix elements and returns the resulting matrix |
Multiplies two affine matrices and returns the product.
left | (Matrix4x4) | Left hand side matrix. |
right | (Matrix4x4) | Right hand side matrix. |
(Matrix4x4) | The result matrix. |
Orthonormalizes base vectors of the given matrix. The result is in out_matrix. The orthonormalization is done using the Gram-Schmidt process. Z axis is kept still, then Y is handled, then X. You can use this function to prevent value drift.
matrix | (Matrix4x4) | Input matrix. |
(Matrix4x4) | The orthonormalized matrix. |
Multiplies a 3D vector with the top 3x3 part of a given matrix.
matrix | (Matrix4x4) | The matrix that you want to multiply with a 3D vector. |
vector | (Vector3) | The 3D vector that you want to multiply with a matrix. |
(Vector3) | The result of the multiplication. |
Applies an inversion to a matrix.
matrix | (Matrix4x4) | Input matrix. |
(Matrix4x4 or nil) | Inverted matrix if the input matrix is invertible, nil otherwise. |
Applies an inversion to an affine matrix.
matrix | (Matrix4x4) | Input matrix. |
(Matrix4x4 or nil) | Inverted matrix if the input matrix is invertible, nil otherwise. |
Applies an inversion to an orthogonal affine matrix.
matrix | (Matrix4x4) | Input matrix. |
(Matrix4x4 or nil) | Inverted matrix if the input matrix is invertible, nil otherwise. |
Returns whether a matrix is translation-only.
matrix | (Matrix4x4) | Input matrix. |
(bool) | If the input matrix is translation-only, true, otherwise false. |
Extracts from a matrix the scale, rotation, and translation information.
local result, scale, rotationInRadians, translation = extractSRT(matrix)
matrix | (Matrix4x4) | Input matrix. |
1. | (boolean) | True if the matrix could be decomposed and the extraction of SRT components succeeded, false otherwise. |
2. | (Vector3) | Scale vector. |
3. | (Vector3) | Rotation vector, rotation angle in radians. |
4. | (Vector3) | Translation vector. |
Extracts the 3x3 rotation and scaling part of a matrix.
Normalizes base vectors of a matrix. The matrix must be an affine transformation.
(Matrix4x4) | Matrix4x4 with base vectors normalized. |
Calculates the determinant of a matrix.
matrix | (Matrix4x4) | The matrix for which you want to return the determinant. |
(float) | Determinant of the matrix. |
Calculates the determinant of the 3x3 part of a matrix.
matrix | (Matrix4x4) | The matrix for which you want to return the determinant. |
(float) | Determinant of the matrix. |
Calculates the trace of a matrix.
(float) | Trace of the matrix. |
Creates an orthogonal projection matrix for a symmetrical viewing volume.
near | (float) | Camera near value. |
far | (float) | Camera far value. |
fovType | (Matrix4x4::FieldOfViewType) | Tells whether the orthoSize parameter is the width or height of the viewing box. |
orthoSize | (float) | Specifies the size of the viewing box (either width of height). |
aspectRatio | (float) | Specifies the aspect ratio of the viewing box. |
(Matrix4x4) | Orthogonal projection matrix. |
Calculates a homogeneous camera view position that you can use to calculate the view direction in a shader. For orthogonal projections the w-component of the viewpoint is 0 to indicate that the viewpoint is at infinity.
projectionCameraMatrix | (Matrix4x4) | The matrix to use for calculating the viewpoint. |
(Vector4 or nil) | Homogeneous viewpoint. |
Multiplies matrix components component-wise and returns the resulting matrix.
m1 | (Matrix4x4) | The first matrix. |
m2 | (Matrix4x4) | The second matrix. |
(Matrix4x4) | The result matrix. |
Divides matrix components component-wise and returns the resulting matrix.
m1 | (Matrix4x4) | The first matrix. |
m2 | (Matrix4x4) | The second matrix. |
(Matrix4x4) | The result matrix. |
Calculates the component-wise maximum for all matrix elements and returns the resulting matrix.
v1 | (Matrix4x4) | The first matrix. |
v2 | (Matrix4x4) | The second matrix. |
(Matrix4x4) | The result matrix. |
Calculates the component-wise minimum for all matrix elements and returns the resulting matrix.
v1 | (Matrix4x4) | The first matrix. |
v2 | (Matrix4x4) | The second matrix. |
(Matrix4x4) | The result matrix. |