Kanzi 4.0.0-beta2
kanzi::Matrix4x4 Class Reference

Matrix with 4x4 elements. More...

#include <kanzi/core/math/matrix4x4.hpp>

Public Types

enum class  FieldOfViewType { XFov , YFov }
 Field of view type of a camera. More...
 

Public Member Functions

constexpr Vector4 getColumn (size_t index) const
 Gets the column of a matrix.
 
optional< Vector3getRotationAngle () const
 Calculates Euler rotation angles of the matrix.
 
constexpr Vector4 getRow (size_t index) const
 Gets the row of a matrix.
 
Vector3 getScale () const
 Get scale as a vector.
 
constexpr Vector3 getTranslation () const
 Get translation.
 
constexpr float getTranslationX () const
 Get translation on X axis.
 
constexpr float getTranslationY () const
 Get translation on Y axis.
 
constexpr float getTranslationZ () const
 Get translation on Z axis.
 
constexpr Vector3 getXAxis () const
 Get X axis.
 
constexpr Vector3 getYAxis () const
 Get Y axis.
 
constexpr Vector3 getZAxis () const
 Get Z axis.
 
constexpr Matrix4x4 ()
 Default constructor.
 
constexpr Matrix4x4 (float value)
 Constructor.
 
constexpr Matrix4x4 (float x0, float x1, float x2, float x3, float x4, float x5, float x6, float x7, float x8, float x9, float x10, float x11, float x12, float x13, float x14, float x15)
 Constructs the matrix from elements in column-major order.
 
constexpr Matrix4x4 (Vector3 x, Vector3 y, Vector3 z, Vector3 translation)
 Constructs the matrix from four column vectors.
 
constexpr Matrix4x4 (Vector4 x, Vector4 y, Vector4 z, Vector4 translation)
 Constructs the matrix from four column vectors.
 
constexpr Vector3 operator* (Vector3 rhs) const
 Multiply a 3-component vector with a 4x4 matrix.
 
constexpr Vector4 operator* (Vector4 rhs) const
 Multiply a 4-component vector with a 4x4 matrix.
 
constexpr Matrix4x4operator*= (const Matrix4x4 &m)
 Modifies this matrix by multiplying it with another matrix.
 
constexpr Matrix4x4operator+= (const Matrix4x4 &v)
 Modifies this matrix by adding another matrix.
 
constexpr Matrix4x4operator-= (const Matrix4x4 &v)
 Modifies this matrix by subtracting another matrix from this matrix.
 
constexpr floatoperator[] (size_t index)
 Access to individual elements of the matrix.
 
constexpr const floatoperator[] (size_t index) const
 Access to individual elements of the matrix.
 
constexpr void scale (Vector3 scale)
 Scales this matrix.
 
constexpr void scaleUniform (float scale)
 Scales this matrix.
 
constexpr void setColumn (size_t index, Vector4 column)
 Sets the column of a matrix.
 
constexpr void setRow (size_t index, Vector4 row)
 Sets the row of a matrix.
 
constexpr void setTranslation (Vector3 translation)
 Set translation.
 
constexpr void setTranslationX (float translationX)
 Set translation on X axis.
 
constexpr void setTranslationY (float translationY)
 Set translation on Y axis.
 
constexpr void setTranslationZ (float translationZ)
 Set translation on Z axis.
 
constexpr void setXAxis (Vector3 v)
 Set X axis.
 
constexpr void setYAxis (Vector3 v)
 Set Y axis.
 
constexpr void setZAxis (Vector3 v)
 Set Z axis.
 
constexpr void translate (Vector3 translate)
 Translates this matrix.
 
constexpr Matrix4x4 transposed () const
 Applies a transpose to a matrix.
 

Static Public Member Functions

static constexpr Matrix4x4 createFilled (float value)
 Creates a matrix with all elements set to value.
 
static constexpr Matrix4x4 createFromHomogenousMatrix (const Matrix3x3 &matrix)
 Creates a matrix from an existing homogeneous matrix.
 
static constexpr Matrix4x4 createFromHomogenousMatrix (const Matrix3x3 &matrix, float zTranslation)
 Creates a matrix from an existing homogeneous matrix and Z translation.
 
static constexpr Matrix4x4 createIdentity ()
 Creates identity matrix.
 
static optional< Matrix4x4createLookAtMatrix (Vector3 position, Vector3 lookAtPoint, Vector3 upVector)
 Creates a lookup transformation matrix, so that it is in a given position looking at the given point.
 
static constexpr Matrix4x4 createOrthogonalProjection (float left, float right, float bottom, float top, float nearPlane, float farPlane)
 Creates a projection matrix for orthogonal projection.
 
static constexpr Matrix4x4 createOrthogonalProjection (float left, float right, float bottom, float top, float nearPlane, float farPlane, float clipNear, float clipFar)
 Creates a projection matrix for orthogonal projection.
 
static Matrix4x4 createPerspectiveProjection (float nearPlane, float farPlane, FieldOfViewType fovType, float fovInDegrees, float aspectRatio)
 Creates a perspective projection matrix for a symmetrical viewing volume.
 
static Matrix4x4 createPerspectiveProjection (float nearPlane, float farPlane, Vector4 fovInDegrees)
 Creates a perspective projection matrix for a viewing volume.
 
static Matrix4x4 createRotation (float angleInRadians, Vector3 rotationAxis)
 Creates a rotation matrix over an arbitrary axis.
 
static Matrix4x4 createRotationInDegrees (float angleInDegrees, Vector3 rotationAxis)
 Creates a rotation matrix over an arbitrary axis.
 
static constexpr Matrix4x4 createScale (Vector3 scale)
 Creates a scaling matrix.
 
static Matrix4x4 createSRT (Vector3 scale, Vector3 rotationInRadians, Vector3 translation)
 Create an SRT matrix.
 
static Matrix4x4 createSubProjection (const Matrix4x4 &projection, float relativeOffsetX, float relativeOffsetY, float relativeSizeX, float relativeSizeY)
 Calculate sub-quad projection of an existing projection matrix.
 
static constexpr Matrix4x4 createTranslation (float x, float y, float z)
 Creates translation matrix.
 
static constexpr Matrix4x4 createTranslation (Vector3 translation)
 Creates translation matrix.
 
static Matrix4x4 createXRotationInDegrees (float angleInDegrees)
 Creates a X rotation matrix.
 
static Matrix4x4 createXRotationInRadians (float angleInRadians)
 Creates a X rotation matrix.
 
static Matrix4x4 createYRotationInDegrees (float angleInDegrees)
 Creates a Y rotation matrix.
 
static Matrix4x4 createYRotationInRadians (float angleInRadians)
 Creates a Y rotation matrix.
 
static Matrix4x4 createZRotationInDegrees (float angleInDegrees)
 Creates a Z rotation matrix.
 
static Matrix4x4 createZRotationInRadians (float angleInRadians)
 Creates a Z rotation matrix.
 

Detailed Description

Matrix with 4x4 elements.

Member Enumeration Documentation

◆ FieldOfViewType

Field of view type of a camera.

Enumerator
XFov 

Field of view is specified in the x axis direction.

YFov 

Field of view is specified in the y axis direction.

Constructor & Destructor Documentation

◆ Matrix4x4() [1/5]

constexpr kanzi::Matrix4x4::Matrix4x4 ( )
inlineexplicitconstexpr

Default constructor.

Initializes the matrix to identity matrix.

◆ Matrix4x4() [2/5]

constexpr kanzi::Matrix4x4::Matrix4x4 ( float value)
inlineexplicitconstexpr

Constructor.

Initializes every component to the same value.

◆ Matrix4x4() [3/5]

constexpr kanzi::Matrix4x4::Matrix4x4 ( float x0,
float x1,
float x2,
float x3,
float x4,
float x5,
float x6,
float x7,
float x8,
float x9,
float x10,
float x11,
float x12,
float x13,
float x14,
float x15 )
inlineexplicitconstexpr

Constructs the matrix from elements in column-major order.

Parameters
x0First column first element.
x1First column second element.
x2First column third element.
x3First column fourth element.
x4Second column first element.
x5Second column second element.
x6Second column third element.
x7Second column fourth element.
x8Third column first element.
x9Third column second element.
x10Third column third element.
x11Third column fourth element.
x12Fourth column first element.
x13Fourth column second element.
x14Fourth column third element.
x15Fourth column fourth element.

◆ Matrix4x4() [4/5]

constexpr kanzi::Matrix4x4::Matrix4x4 ( Vector3 x,
Vector3 y,
Vector3 z,
Vector3 translation )
inlineexplicitconstexpr

Constructs the matrix from four column vectors.

Parameters
xFirst column vector.
ySecond column vector.
zThird column vector.
translationTranslation vector.

◆ Matrix4x4() [5/5]

constexpr kanzi::Matrix4x4::Matrix4x4 ( Vector4 x,
Vector4 y,
Vector4 z,
Vector4 translation )
inlineexplicitconstexpr

Constructs the matrix from four column vectors.

Parameters
xFirst column vector.
ySecond column vector.
zThird column vector.
translationTranslation vector.

Member Function Documentation

◆ operator[]() [1/2]

constexpr const float & kanzi::Matrix4x4::operator[] ( size_t index) const
inlineconstexpr

Access to individual elements of the matrix.

Elements are stored in column-major order.

Parameters
indexIndex of the accessed element. Possible values are numbers from 0 to 15.
Returns

◆ operator[]() [2/2]

constexpr float & kanzi::Matrix4x4::operator[] ( size_t index)
inlineconstexpr

Access to individual elements of the matrix.

Elements are stored in column-major order.

Parameters
indexIndex of the accessed element. Possible values are numbers from 0 to 15.
Returns

◆ getRow()

constexpr Vector4 kanzi::Matrix4x4::getRow ( size_t index) const
inlineconstexpr

Gets the row of a matrix.

Parameters
indexIndex of the accessed row.
Returns
The row.

◆ getColumn()

constexpr Vector4 kanzi::Matrix4x4::getColumn ( size_t index) const
inlineconstexpr

Gets the column of a matrix.

Parameters
indexIndex of the accessed column.
Returns
The column.

◆ setRow()

constexpr void kanzi::Matrix4x4::setRow ( size_t index,
Vector4 row )
inlineconstexpr

Sets the row of a matrix.

Parameters
indexIndex of the accessed row.
rowThe value to set to the row.

◆ setColumn()

constexpr void kanzi::Matrix4x4::setColumn ( size_t index,
Vector4 column )
inlineconstexpr

Sets the column of a matrix.

Parameters
indexIndex of the accessed column.
columnThe value to set to the column.

◆ getXAxis()

constexpr Vector3 kanzi::Matrix4x4::getXAxis ( ) const
inlineconstexpr

Get X axis.

◆ getYAxis()

constexpr Vector3 kanzi::Matrix4x4::getYAxis ( ) const
inlineconstexpr

Get Y axis.

◆ getZAxis()

constexpr Vector3 kanzi::Matrix4x4::getZAxis ( ) const
inlineconstexpr

Get Z axis.

◆ getScale()

Vector3 kanzi::Matrix4x4::getScale ( ) const

Get scale as a vector.

◆ getRotationAngle()

optional< Vector3 > kanzi::Matrix4x4::getRotationAngle ( ) const

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.

Returns
Euler angles in radians, or nullopt if the matrix is not decomposable.

◆ scale()

constexpr void kanzi::Matrix4x4::scale ( Vector3 scale)
inlineconstexpr

Scales this matrix.

Parameters
scaleScaling vector.

◆ scaleUniform()

constexpr void kanzi::Matrix4x4::scaleUniform ( float scale)
inlineconstexpr

Scales this matrix.

Parameters
scaleUniform scaling value.

◆ translate()

constexpr void kanzi::Matrix4x4::translate ( Vector3 translate)
inlineconstexpr

Translates this matrix.

Parameters
translateTranslation vector.

◆ setXAxis()

constexpr void kanzi::Matrix4x4::setXAxis ( Vector3 v)
inlineconstexpr

Set X axis.

Parameters
vX axis vector.

◆ setYAxis()

constexpr void kanzi::Matrix4x4::setYAxis ( Vector3 v)
inlineconstexpr

Set Y axis.

Parameters
vY axis vector.

◆ setZAxis()

constexpr void kanzi::Matrix4x4::setZAxis ( Vector3 v)
inlineconstexpr

Set Z axis.

Parameters
vZ axis vector.

◆ getTranslation()

constexpr Vector3 kanzi::Matrix4x4::getTranslation ( ) const
inlineconstexpr

Get translation.

Returns
Translation vector.

◆ setTranslation()

constexpr void kanzi::Matrix4x4::setTranslation ( Vector3 translation)
inlineconstexpr

Set translation.

Parameters
translationTranslation vector.

◆ getTranslationX()

constexpr float kanzi::Matrix4x4::getTranslationX ( ) const
inlineconstexpr

Get translation on X axis.

Returns
Translation X component.

◆ setTranslationX()

constexpr void kanzi::Matrix4x4::setTranslationX ( float translationX)
inlineconstexpr

Set translation on X axis.

Parameters
translationXTranslation X component.

◆ getTranslationY()

constexpr float kanzi::Matrix4x4::getTranslationY ( ) const
inlineconstexpr

Get translation on Y axis.

Returns
Translation Y component.

◆ setTranslationY()

constexpr void kanzi::Matrix4x4::setTranslationY ( float translationY)
inlineconstexpr

Set translation on Y axis.

Parameters
translationYTranslation Y component.

◆ getTranslationZ()

constexpr float kanzi::Matrix4x4::getTranslationZ ( ) const
inlineconstexpr

Get translation on Z axis.

Returns
Translation Z component.

◆ setTranslationZ()

constexpr void kanzi::Matrix4x4::setTranslationZ ( float translationZ)
inlineconstexpr

Set translation on Z axis.

Parameters
translationZTranslation Y component.

◆ operator+=()

constexpr Matrix4x4 & kanzi::Matrix4x4::operator+= ( const Matrix4x4 & v)
inlineconstexpr

Modifies this matrix by adding another matrix.

Parameters
vAnother matrix.
Returns
This matrix.

◆ operator-=()

constexpr Matrix4x4 & kanzi::Matrix4x4::operator-= ( const Matrix4x4 & v)
inlineconstexpr

Modifies this matrix by subtracting another matrix from this matrix.

Parameters
vAnother matrix.
Returns
This matrix.

◆ operator*() [1/2]

constexpr Vector3 kanzi::Matrix4x4::operator* ( Vector3 rhs) const
inlineconstexpr

Multiply a 3-component vector with a 4x4 matrix.

Parameters
rhsRight-hand-side vector.
Returns
Result of the multiplication.

◆ operator*() [2/2]

constexpr Vector4 kanzi::Matrix4x4::operator* ( Vector4 rhs) const
inlineconstexpr

Multiply a 4-component vector with a 4x4 matrix.

Parameters
rhsRight-hand-side vector.
Returns
Result of the multiplication.

◆ operator*=()

constexpr Matrix4x4 & kanzi::Matrix4x4::operator*= ( const Matrix4x4 & m)
constexpr

Modifies this matrix by multiplying it with another matrix.

Parameters
mAnother matrix.
Returns
This matrix.

◆ createTranslation() [1/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createTranslation ( Vector3 translation)
inlinestaticconstexpr

Creates translation matrix.

Parameters
translationTranslation vector.
Returns
Translation matrix.

◆ createTranslation() [2/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createTranslation ( float x,
float y,
float z )
inlinestaticconstexpr

Creates translation matrix.

Parameters
xX component of the Translation vector.
yY component of the Translation vector.
zZ component of the Translation vector.
Returns
Translation matrix.

◆ createIdentity()

static constexpr Matrix4x4 kanzi::Matrix4x4::createIdentity ( )
inlinestaticconstexpr

Creates identity matrix.

Returns
Identity matrix.

◆ createFromHomogenousMatrix() [1/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createFromHomogenousMatrix ( const Matrix3x3 & matrix,
float zTranslation )
inlinestaticconstexpr

Creates a matrix from an existing homogeneous matrix and Z translation.

Parameters
matrixHomogeneous matrix.
zTranslationX translation.
Returns
Newly constructed matrix.

◆ createFromHomogenousMatrix() [2/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createFromHomogenousMatrix ( const Matrix3x3 & matrix)
inlinestaticconstexpr

Creates a matrix from an existing homogeneous matrix.

0.0f is used for the Z translation.

Parameters
matrixHomogeneous matrix.
Returns
Newly constructed matrix.

◆ createRotation()

static Matrix4x4 kanzi::Matrix4x4::createRotation ( float angleInRadians,
Vector3 rotationAxis )
static

Creates a rotation matrix over an arbitrary axis.

Similar to the matrix used by glRotatef. The rotation axis needs not be normalized.

Parameters
angleInRadiansRotation angle in radians.
rotationAxisArbitrary rotation axis.
Returns
Rotation matrix.

◆ createRotationInDegrees()

static Matrix4x4 kanzi::Matrix4x4::createRotationInDegrees ( float angleInDegrees,
Vector3 rotationAxis )
inlinestatic

Creates a rotation matrix over an arbitrary axis.

Similar to the matrix used by glRotatef. The rotation axis needs not be normalized.

Parameters
angleInDegreesRotation angle in degrees.
rotationAxisArbitrary rotation axis.
Returns
Rotation matrix.

◆ createXRotationInRadians()

static Matrix4x4 kanzi::Matrix4x4::createXRotationInRadians ( float angleInRadians)
static

Creates a X rotation matrix.

Parameters
angleInRadiansRotation angle in radians.
Returns
X Rotation matrix.

◆ createXRotationInDegrees()

static Matrix4x4 kanzi::Matrix4x4::createXRotationInDegrees ( float angleInDegrees)
inlinestatic

Creates a X rotation matrix.

Parameters
angleInDegreesRotation angle in degrees.
Returns
X Rotation matrix.

◆ createYRotationInRadians()

static Matrix4x4 kanzi::Matrix4x4::createYRotationInRadians ( float angleInRadians)
static

Creates a Y rotation matrix.

Parameters
angleInRadiansRotation angle in radians.
Returns
Y Rotation matrix.

◆ createYRotationInDegrees()

static Matrix4x4 kanzi::Matrix4x4::createYRotationInDegrees ( float angleInDegrees)
inlinestatic

Creates a Y rotation matrix.

Parameters
angleInDegreesRotation angle in degrees.
Returns
Y Rotation matrix.

◆ createZRotationInRadians()

static Matrix4x4 kanzi::Matrix4x4::createZRotationInRadians ( float angleInRadians)
static

Creates a Z rotation matrix.

Parameters
angleInRadiansRotation angle in radians.
Returns
Z Rotation matrix.

◆ createZRotationInDegrees()

static Matrix4x4 kanzi::Matrix4x4::createZRotationInDegrees ( float angleInDegrees)
inlinestatic

Creates a Z rotation matrix.

Parameters
angleInDegreesRotation angle in degrees.
Returns
Z Rotation matrix.

◆ createScale()

static constexpr Matrix4x4 kanzi::Matrix4x4::createScale ( Vector3 scale)
inlinestaticconstexpr

Creates a scaling matrix.

Parameters
scaleScaling vector.
Returns
Scaled matrix.

◆ createOrthogonalProjection() [1/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createOrthogonalProjection ( float left,
float right,
float bottom,
float top,
float nearPlane,
float farPlane,
float clipNear,
float clipFar )
inlinestaticconstexpr

Creates a projection matrix for orthogonal projection.

Parameters
leftThe left edge of the viewing box.
rightViewing box right.
bottomViewing box bottom.
topThe top edge of the viewing box.
nearPlaneThe distance to the near clipping plane of the camera.
farPlaneThe distance to the far clipping plane of the camera.
clipNearThe near edge of the clipping box, usually 0.0 or -1.0.
clipFarThe far edge of the clipping box, usually 1.0.
Returns
The orthogonal projection matrix.

◆ createOrthogonalProjection() [2/2]

static constexpr Matrix4x4 kanzi::Matrix4x4::createOrthogonalProjection ( float left,
float right,
float bottom,
float top,
float nearPlane,
float farPlane )
inlinestaticconstexpr

Creates a projection matrix for orthogonal projection.

Maps the z range automatically to the correct clipping box, depending on the backend.

Parameters
leftThe left edge of the viewing box.
rightThe right edge of the viewing box.
bottomThe bottom edge of the viewing box.
topThe top edge of the viewing box.
nearPlaneThe distance to the near clipping plane of the camera.
farPlaneThe distance to the far clipping plane of the camera.
Returns
The orthogonal projection matrix.

◆ createPerspectiveProjection() [1/2]

static Matrix4x4 kanzi::Matrix4x4::createPerspectiveProjection ( float nearPlane,
float farPlane,
FieldOfViewType fovType,
float fovInDegrees,
float aspectRatio )
static

Creates a perspective projection matrix for a symmetrical viewing volume.

Parameters
nearPlaneCamera near value.
farPlaneCamera far value.
fovTypeTells whether the fovInDegrees parameter is xfov or yfov.
fovInDegreesField of view in degrees.
aspectRatioThe aspect ratio of the viewport.
Returns
Perspective projection matrix.

◆ createPerspectiveProjection() [2/2]

static Matrix4x4 kanzi::Matrix4x4::createPerspectiveProjection ( float nearPlane,
float farPlane,
Vector4 fovInDegrees )
static

Creates a perspective projection matrix for a viewing volume.

Parameters
nearPlaneCamera near value.
farPlaneCamera far value.
fovInDegreesField of view in degrees, specified in order left, right, up, down. Angles to the right of center and upwards of center are positive.
Returns
Perspective projection matrix.

◆ createSubProjection()

static Matrix4x4 kanzi::Matrix4x4::createSubProjection ( const Matrix4x4 & projection,
float relativeOffsetX,
float relativeOffsetY,
float relativeSizeX,
float relativeSizeY )
static

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]

Translated 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]

Parameters
projectionProjection matrix.
relativeOffsetXX offset of sub-quad as portion of the size of the projection area.
relativeOffsetYY offset of sub-quad as portion of the size of the projection area.
relativeSizeXProjection area X size in regard to sub-quad area size.
relativeSizeYProjection area Y size in regard to sub-quad area size.
Returns
Modified projection matrix.

◆ createLookAtMatrix()

static optional< Matrix4x4 > kanzi::Matrix4x4::createLookAtMatrix ( Vector3 position,
Vector3 lookAtPoint,
Vector3 upVector )
static

Creates a lookup transformation matrix, so that it is in a given position looking at the given point.

Parameters
positionThe new translation of the node.
lookAtPointA point where the node is looking at.
upVectorThe new up vector of the node.
Returns
Lookup matrix if position is not the same as lookAtPoint and upVector is not null, nullopt otherwise.

◆ createSRT()

static Matrix4x4 kanzi::Matrix4x4::createSRT ( Vector3 scale,
Vector3 rotationInRadians,
Vector3 translation )
static

Create an SRT matrix.

Parameters
scaleScales by axises.
rotationInRadiansRotation component in radians.
translationTranslation component.
Returns
Newly constructed matrix.

◆ createFilled()

static constexpr Matrix4x4 kanzi::Matrix4x4::createFilled ( float value)
inlinestaticconstexpr

Creates a matrix with all elements set to value.

Parameters
valueValue to set to all elements.
Returns
Newly constructed matrix.
Since
Kanzi 3.9.9

◆ transposed()

constexpr Matrix4x4 kanzi::Matrix4x4::transposed ( ) const
inlineconstexpr

Applies a transpose to a matrix.

Returns
Newly constructed transpose matrix.

The documentation for this class was generated from the following file: