Kanzi  3.9.4
Kanzi Engine API
kanzi::Matrix4x4 Class Reference

Matrix with 4x4 elements. More...

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

Public Types

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

Public Member Functions

Vector4 getColumn (size_t index) const
 Gets the column of a matrix. More...
 
optional< Vector3getRotationAngle () const
 Calculates Euler rotation angles of the matrix. More...
 
Vector4 getRow (size_t index) const
 Gets the row of a matrix. More...
 
Vector3 getScale () const
 Get scale as a vector. More...
 
Vector3 getTranslation () const
 Get translation. More...
 
float getTranslationX () const
 Get translation on X axis. More...
 
float getTranslationY () const
 Get translation on Y axis. More...
 
float getTranslationZ () const
 Get translation on Z axis. More...
 
Vector3 getXAxis () const
 Get X axis. More...
 
Vector3 getYAxis () const
 Get Y axis. More...
 
Vector3 getZAxis () const
 Get Z axis. More...
 
 Matrix4x4 ()
 Default constructor, initializes the matrix to identity matrix. More...
 
 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. More...
 
 Matrix4x4 (const Vector3 &x, const Vector3 &y, const Vector3 &z, const Vector3 &translation)
 Constructs the matrix from four column vectors. More...
 
 Matrix4x4 (const Vector4 &x, const Vector4 &y, const Vector4 &z, const Vector4 &translation)
 Constructs the matrix from four column vectors. More...
 
Vector3 operator* (const Vector3 &vector) const
 Multiply a 3-component vector with this matrix. More...
 
Vector4 operator* (const Vector4 &vector) const
 Multiply a 4-component vector with this matrix. More...
 
Matrix4x4operator*= (const Matrix4x4 &m)
 Modifies this matrix by multiplying it with another matrix. More...
 
Matrix4x4operator+= (const Matrix4x4 &v)
 Modifies this matrix by adding another matrix. More...
 
Matrix4x4operator-= (const Matrix4x4 &v)
 Modifies this matrix by subtracting another matrix from this matrix. More...
 
const float & operator[] (size_t index) const
 Access to individual elements of the matrix. More...
 
float & operator[] (size_t index)
 Access to individual elements of the matrix. More...
 
void scale (const Vector3 &scale)
 Scales this matrix. More...
 
void scaleUniform (float scale)
 Scales this matrix. More...
 
void setColumn (size_t index, const Vector4 &column)
 Sets the column of a matrix. More...
 
void setRow (size_t index, const Vector4 &row)
 Sets the row of a matrix. More...
 
void setTranslation (Vector3 translation)
 Set translation. More...
 
void setTranslationX (float translationX)
 Set translation on X axis. More...
 
void setTranslationY (float translationY)
 Set translation on Y axis. More...
 
void setTranslationZ (float translationZ)
 Set translation on Z axis. More...
 
void setXAxis (Vector3 v)
 Set X axis. More...
 
void setYAxis (Vector3 v)
 Set Y axis. More...
 
void setZAxis (Vector3 v)
 Set Z axis. More...
 
void translate (const Vector3 &translate)
 Translates this matrix. More...
 
Matrix4x4 transposed () const
 Applies a transpose to a matrix. More...
 

Static Public Member Functions

static Matrix4x4 createFromHomogenousMatrix (const Matrix3x3 &matrix, float zTranslation)
 Creates a matrix from an existing homogeneous matrix and Z translation. More...
 
static Matrix4x4 createFromHomogenousMatrix (const Matrix3x3 &matrix)
 Creates a matrix from an existing homogeneous matrix. More...
 
static Matrix4x4 createIdentity ()
 Creates identity matrix. More...
 
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. More...
 
static Matrix4x4 createOrthogonalProjection (float left, float right, float bottom, float top, float near, float far)
 Creates projection matrix for orthogonal projection. More...
 
static Matrix4x4 createPerspectiveProjection (float near, float far, FieldOfViewType fovType, float fovInDegrees, float aspectRatio)
 Creates a perspective projection matrix for a symmetrical viewing volume. More...
 
static Matrix4x4 createPerspectiveProjection (float near, float far, Vector4 fovInDegrees)
 Creates a perspective projection matrix for a viewing volume. More...
 
static Matrix4x4 createRotation (float angleInRadians, Vector3 rotationAxis)
 Creates a rotation matrix over an arbitrary axis. More...
 
static Matrix4x4 createRotationInDegrees (float angleInDegrees, Vector3 rotationAxis)
 Creates a rotation matrix over an arbitrary axis. More...
 
static Matrix4x4 createScale (Vector3 scale)
 Creates a scaling matrix. More...
 
static Matrix4x4 createSRT (Vector3 scale, Vector3 rotationInRadians, Vector3 translation)
 Create an SRT matrix. More...
 
static Matrix4x4 createSubProjection (const Matrix4x4 &projection, float relativeOffsetX, float relativeOffsetY, float relativeSizeX, float relativeSizeY)
 Calculate sub-quad projection of an existing projection matrix. More...
 
static Matrix4x4 createTranslation (Vector3 translation)
 Creates translation matrix. More...
 
static Matrix4x4 createTranslation (float x, float y, float z)
 Creates translation matrix. More...
 
static Matrix4x4 createXRotationInDegrees (float angleInDegrees)
 Creates a X rotation matrix. More...
 
static Matrix4x4 createXRotationInRadians (float angleInRadians)
 Creates a X rotation matrix. More...
 
static Matrix4x4 createYRotationInDegrees (float angleInDegrees)
 Creates a Y rotation matrix. More...
 
static Matrix4x4 createYRotationInRadians (float angleInRadians)
 Creates a Y rotation matrix. More...
 
static Matrix4x4 createZRotationInDegrees (float angleInDegrees)
 Creates a Z rotation matrix. More...
 
static Matrix4x4 createZRotationInRadians (float angleInRadians)
 Creates a Z rotation matrix. More...
 

Friends

bool operator!= (const Matrix4x4 &left, const Matrix4x4 &right)
 Inequality operator. More...
 
Matrix4x4 operator+ (Matrix4x4 lhs, const Matrix4x4 &rhs)
 Creates a new matrix by adding an existing matrix to another one. More...
 
Matrix4x4 operator- (Matrix4x4 lhs, const Matrix4x4 &rhs)
 Creates a new matrix by subtracting an existing matrix from another one. More...
 
bool operator== (const Matrix4x4 &left, const Matrix4x4 &right)
 Equality operator. More...
 

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/4]

kanzi::Matrix4x4::Matrix4x4 ( )
inlineexplicit

Default constructor, initializes the matrix to identity matrix.

◆ Matrix4x4() [2/4]

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 
)
inlineexplicit

Constructs the matrix from elements in column-major order.

◆ Matrix4x4() [3/4]

kanzi::Matrix4x4::Matrix4x4 ( const Vector3 x,
const Vector3 y,
const Vector3 z,
const Vector3 translation 
)
inlineexplicit

Constructs the matrix from four column vectors.

◆ Matrix4x4() [4/4]

kanzi::Matrix4x4::Matrix4x4 ( const Vector4 x,
const Vector4 y,
const Vector4 z,
const Vector4 translation 
)
inlineexplicit

Constructs the matrix from four column vectors.

Member Function Documentation

◆ operator[]() [1/2]

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

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]

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

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()

Vector4 kanzi::Matrix4x4::getRow ( size_t  index) const
inline

Gets the row of a matrix.

Parameters
indexIndex of the accessed row.
Returns
The row.

◆ getColumn()

Vector4 kanzi::Matrix4x4::getColumn ( size_t  index) const
inline

Gets the column of a matrix.

Parameters
indexIndex of the accessed column.
Returns
The column.

◆ setRow()

void kanzi::Matrix4x4::setRow ( size_t  index,
const Vector4 row 
)
inline

Sets the row of a matrix.

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

◆ setColumn()

void kanzi::Matrix4x4::setColumn ( size_t  index,
const Vector4 column 
)
inline

Sets the column of a matrix.

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

◆ getXAxis()

Vector3 kanzi::Matrix4x4::getXAxis ( ) const
inline

Get X axis.

◆ getYAxis()

Vector3 kanzi::Matrix4x4::getYAxis ( ) const
inline

Get Y axis.

◆ getZAxis()

Vector3 kanzi::Matrix4x4::getZAxis ( ) const
inline

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()

void kanzi::Matrix4x4::scale ( const Vector3 scale)
inline

Scales this matrix.

Parameters
scaleScaling vector.

◆ scaleUniform()

void kanzi::Matrix4x4::scaleUniform ( float  scale)
inline

Scales this matrix.

Parameters
scaleUniform scaling value.

◆ translate()

void kanzi::Matrix4x4::translate ( const Vector3 translate)
inline

Translates this matrix.

Parameters
translateTranslation vector.

◆ setXAxis()

void kanzi::Matrix4x4::setXAxis ( Vector3  v)
inline

Set X axis.

Parameters
vX axis vector.

◆ setYAxis()

void kanzi::Matrix4x4::setYAxis ( Vector3  v)
inline

Set Y axis.

Parameters
vY axis vector.

◆ setZAxis()

void kanzi::Matrix4x4::setZAxis ( Vector3  v)
inline

Set Z axis.

Parameters
vZ axis vector.

◆ getTranslation()

Vector3 kanzi::Matrix4x4::getTranslation ( ) const
inline

Get translation.

Returns
Translation vector.

◆ setTranslation()

void kanzi::Matrix4x4::setTranslation ( Vector3  translation)
inline

Set translation.

Parameters
translationTranslation vector.

◆ getTranslationX()

float kanzi::Matrix4x4::getTranslationX ( ) const
inline

Get translation on X axis.

Returns
Translation X component.

◆ setTranslationX()

void kanzi::Matrix4x4::setTranslationX ( float  translationX)
inline

Set translation on X axis.

Parameters
translationXTranslation X component.

◆ getTranslationY()

float kanzi::Matrix4x4::getTranslationY ( ) const
inline

Get translation on Y axis.

Returns
Translation Y component.

◆ setTranslationY()

void kanzi::Matrix4x4::setTranslationY ( float  translationY)
inline

Set translation on Y axis.

Parameters
translationYTranslation Y component.

◆ getTranslationZ()

float kanzi::Matrix4x4::getTranslationZ ( ) const
inline

Get translation on Z axis.

Returns
Translation Z component.

◆ setTranslationZ()

void kanzi::Matrix4x4::setTranslationZ ( float  translationZ)
inline

Set translation on Z axis.

Parameters
translationZTranslation Y component.

◆ operator+=()

Matrix4x4& kanzi::Matrix4x4::operator+= ( const Matrix4x4 v)
inline

Modifies this matrix by adding another matrix.

Parameters
vAnother matrix.
Returns
This matrix.

◆ operator-=()

Matrix4x4& kanzi::Matrix4x4::operator-= ( const Matrix4x4 v)
inline

Modifies this matrix by subtracting another matrix from this matrix.

Parameters
vAnother matrix.
Returns
This matrix.

◆ operator*() [1/2]

Vector3 kanzi::Matrix4x4::operator* ( const Vector3 vector) const
inline

Multiply a 3-component vector with this matrix.

Parameters
vectorA Vector3.
Returns
Result of the multiplication.

◆ operator*() [2/2]

Vector4 kanzi::Matrix4x4::operator* ( const Vector4 vector) const
inline

Multiply a 4-component vector with this matrix.

Parameters
vectorA Vector4.
Returns
Result of the multiplication.

◆ operator*=()

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

Modifies this matrix by multiplying it with another matrix.

Parameters
mAnother matrix.
Returns
This matrix.

◆ createTranslation() [1/2]

static Matrix4x4 kanzi::Matrix4x4::createTranslation ( Vector3  translation)
inlinestatic

Creates translation matrix.

Parameters
translationTranslation vector.
Returns
Translation matrix.

◆ createTranslation() [2/2]

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

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 Matrix4x4 kanzi::Matrix4x4::createIdentity ( )
inlinestatic

Creates identity matrix.

Returns
Identity matrix.

◆ createFromHomogenousMatrix() [1/2]

static Matrix4x4 kanzi::Matrix4x4::createFromHomogenousMatrix ( const Matrix3x3 matrix,
float  zTranslation 
)
inlinestatic

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

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

◆ createFromHomogenousMatrix() [2/2]

static Matrix4x4 kanzi::Matrix4x4::createFromHomogenousMatrix ( const Matrix3x3 matrix)
inlinestatic

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 Matrix4x4 kanzi::Matrix4x4::createScale ( Vector3  scale)
static

Creates a scaling matrix.

Parameters
scaleScaling vector.
Returns
Scaled matrix.

◆ createOrthogonalProjection()

static Matrix4x4 kanzi::Matrix4x4::createOrthogonalProjection ( float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far 
)
static

Creates projection matrix for orthogonal projection.

Parameters
leftViewing box left.
rightViewing box right.
bottomViewing box bottom.
topViewing box top.
nearCamera near value.
farCamera far value.
Returns
A newly constructed projection matrix.

◆ createPerspectiveProjection() [1/2]

static Matrix4x4 kanzi::Matrix4x4::createPerspectiveProjection ( float  near,
float  far,
FieldOfViewType  fovType,
float  fovInDegrees,
float  aspectRatio 
)
static

Creates a perspective projection matrix for a symmetrical viewing volume.

Parameters
nearCamera near value.
farCamera 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  near,
float  far,
Vector4  fovInDegrees 
)
static

Creates a perspective projection matrix for a viewing volume.

Parameters
nearCamera near value.
farCamera 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]

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]

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.

◆ transposed()

Matrix4x4 kanzi::Matrix4x4::transposed ( ) const
inline

Applies a transpose to a matrix.

Returns
Newly constructed transpose matrix.

Friends And Related Function Documentation

◆ operator+

Matrix4x4 operator+ ( Matrix4x4  lhs,
const Matrix4x4 rhs 
)
friend

Creates a new matrix by adding an existing matrix to another one.

Parameters
lhsFirst matrix, left hand side.
rhsSecond matrix, right hand side.
Returns
A new matrix resulting from the addition of the right hand side to the left hand side.

◆ operator-

Matrix4x4 operator- ( Matrix4x4  lhs,
const Matrix4x4 rhs 
)
friend

Creates a new matrix by subtracting an existing matrix from another one.

Parameters
lhsFirst matrix, left hand side.
rhsSecond matrix, right hand side.
Returns
A new matrix resulting from the subtraction of the right hand side from the left hand side.

◆ operator==

bool operator== ( const Matrix4x4 left,
const Matrix4x4 right 
)
friend

Equality operator.

Compares two matrices for equality. Note that this is a floating point comparison without any tolerance, so you probably don't want to use this.

Parameters
leftLeft hand side matrix.
rightRight hand side matrix.
Returns
True if vectors are equal.

◆ operator!=

bool operator!= ( const Matrix4x4 left,
const Matrix4x4 right 
)
friend

Inequality operator.

Compares two matrices for inequality. Note that this is a floating point comparison without any tolerance, so you probably don't want to use this.

Parameters
leftLeft-hand side matrix.
rightRight-hand side matrix.
Returns
True if matrices are not equal, false if they are.

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