Dali 3D User Interface Engine
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Friends
Dali::Matrix Class Reference

The Matrix class represents transformations and projections. More...

#include <matrix.h>

Collaboration diagram for Dali::Matrix:
Collaboration graph
[legend]

Public Member Functions

 Matrix ()
 Constructor. More...
 
 Matrix (bool initialize)
 Constructor. More...
 
 Matrix (const float *array)
 Constructor. More...
 
 Matrix (const Quaternion &rotation)
 Constructs a matrix from quaternion. More...
 
 Matrix (const Matrix &matrix)
 Copy constructor. More...
 
Matrixoperator= (const Matrix &matrix)
 Assignment operator. More...
 
void SetIdentity ()
 Sets this matrix to be an identity matrix. More...
 
void SetIdentityAndScale (const Vector3 &scale)
 Sets this matrix to be an identity matrix with scale. More...
 
void InvertTransform (Matrix &result) const
 Invert a transform Matrix. More...
 
bool Invert ()
 Generic brute force Matrix Invert. More...
 
void Transpose ()
 Swaps the rows to columns. More...
 
Vector3 GetXAxis () const
 Returns the xAxis from a Transform matrix. More...
 
Vector3 GetYAxis () const
 Returns the yAxis from a Transform matrix. More...
 
Vector3 GetZAxis () const
 Returns the zAxis from a Transform matrix. More...
 
void SetXAxis (const Vector3 &axis)
 Sets the x axis. More...
 
void SetYAxis (const Vector3 &axis)
 Sets the y axis. More...
 
void SetZAxis (const Vector3 &axis)
 Sets the z axis. More...
 
const Vector4GetTranslation () const
 Gets the translation. More...
 
const Vector3GetTranslation3 () const
 Gets the x,y and z components of the translation as a Vector3. More...
 
void SetTranslation (const Vector4 &translation)
 Sets the translation. More...
 
void SetTranslation (const Vector3 &translation)
 Sets the x,y and z components of the translation from a Vector3. More...
 
void OrthoNormalize ()
 Makes the axes of the matrix orthogonal to each other and of unit length. More...
 
const float * AsFloat () const
 Returns the contents of the matrix as an array of 16 floats. More...
 
float * AsFloat ()
 Returns the contents of the matrix as an array of 16 floats. More...
 
Vector4 operator* (const Vector4 &rhs) const
 The multiplication operator. More...
 
bool operator== (const Matrix &rhs) const
 The equality operator. More...
 
bool operator!= (const Matrix &rhs) const
 The inequality operator. More...
 
void SetTransformComponents (const Vector3 &scale, const Quaternion &rotation, const Vector3 &translation)
 Sets this matrix to contain the position, scale and rotation components. More...
 
void SetInverseTransformComponents (const Vector3 &scale, const Quaternion &rotation, const Vector3 &translation)
 Sets this matrix to contain the inverse of the position, scale and rotation components. More...
 
void SetInverseTransformComponents (const Vector3 &xAxis, const Vector3 &yAxis, const Vector3 &zAxis, const Vector3 &translation)
 Sets this matrix to contain the inverse of the orthonormal basis and position components. More...
 
void GetTransformComponents (Vector3 &position, Quaternion &rotation, Vector3 &scale) const
 Gets the position, scale and rotation components from the given transform matrix. More...
 

Static Public Member Functions

static void Multiply (Matrix &result, const Matrix &lhs, const Matrix &rhs)
 Function to multiply two matrices and store the result onto third. More...
 
static void Multiply (Matrix &result, const Matrix &lhs, const Quaternion &rhs)
 Function to multiply a matrix and quaternion and store the result onto third. More...
 

Static Public Attributes

static const Matrix IDENTITY
 The identity matrix. More...
 

Private Attributes

float mMatrix [16]
 The elements of the matrix. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const Matrix &matrix)
 Print a matrix. More...
 

Detailed Description

The Matrix class represents transformations and projections.

It is agnostic w.r.t. row/column major notation - it operates on a flat array. Each axis is contiguous in memory, so the x axis corresponds to elements 0, 1, 2 and 3, the y axis dorresponds to elements 4, 5, 6, 7, etc. .0

Definition at line 44 of file matrix.h.

Constructor & Destructor Documentation

Dali::Matrix::Matrix ( )

Constructor.

Zero initialises the matrix .0

Definition at line 94 of file matrix.cpp.

References mMatrix, and anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX.

Dali::Matrix::Matrix ( bool  initialize)
explicit

Constructor.

.0

Parameters
initializeto zero or leave uninitialized

Definition at line 99 of file matrix.cpp.

References mMatrix, and anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX.

Dali::Matrix::Matrix ( const float *  array)
explicit

Constructor.

The matrix is initialised with the contents of 'array' which must contain 16 floats. The order of the values for a transform matrix is:

xAxis.x xAxis.y xAxis.z 0.0f yAxis.x yAxis.y yAxis.z 0.0f zAxis.x zAxis.y zAxis.z 0.0f trans.x trans.y trans.z 1.0f

.0

Parameters
[in]array16 floats

Definition at line 107 of file matrix.cpp.

References mMatrix, and anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX.

Dali::Matrix::Matrix ( const Quaternion rotation)
explicit

Constructs a matrix from quaternion.

.0

Parameters
rotationas quaternion

Definition at line 112 of file matrix.cpp.

References anonymous_namespace{matrix.cpp}::Convert(), MATH_INCREASE_BY, and mMatrix.

Here is the call graph for this function:

Dali::Matrix::Matrix ( const Matrix matrix)

Copy constructor.

.0

Parameters
[in]matrixto copy values from

Definition at line 120 of file matrix.cpp.

References mMatrix, and anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX.

Member Function Documentation

const float* Dali::Matrix::AsFloat ( ) const
inline
float* Dali::Matrix::AsFloat ( )
inline

Returns the contents of the matrix as an array of 16 floats.

The order of the values for a transform matrix is:

xAxis.x xAxis.y xAxis.z 0.0f yAxis.x yAxis.y yAxis.z 0.0f zAxis.x zAxis.y zAxis.z 0.0f trans.x trans.y trans.z 1.0f .0

Returns
the matrix contents as an array of 16 floats.
Note
inlined for performance reasons (generates less code than a function call)

Definition at line 278 of file matrix.h.

void Dali::Matrix::GetTransformComponents ( Vector3 position,
Quaternion rotation,
Vector3 scale 
) const

Gets the position, scale and rotation components from the given transform matrix.

.0

Parameters
[out]positionto set
[out]rotationto set - only valid if the transform matrix has not been skewed or sheared
[out]scaleto set - only valid if the transform matrix has not been skewed or sheared
Precondition
This matrix must not contain skews or shears.

Definition at line 721 of file matrix.cpp.

References GetTranslation3(), GetXAxis(), GetYAxis(), GetZAxis(), MATH_INCREASE_BY, MATH_INCREASE_COUNTER, mMatrix, Dali::Quaternion::mVector, Dali::Vector3::ONE, Dali::Vector4::x, Dali::Vector3::x, Dali::Vector4::y, Dali::Vector3::y, Dali::Vector4::z, and Dali::Vector3::z.

Referenced by anonymous_namespace{utc-Dali-Actor.cpp}::PositionComponentConstraint::operator()(), UtcDaliMatrixGetTransformComponents01P(), UtcDaliMatrixGetTransformComponents02P(), and UtcDaliMatrixGetTransformComponents03P().

Here is the call graph for this function:

Here is the caller graph for this function:

const Vector4& Dali::Matrix::GetTranslation ( ) const
inline

Gets the translation.

This assumes the matrix is a transform matrix. .0

Returns
the translation
Note
inlined for performance reasons (generates less code than a function call)

Definition at line 211 of file matrix.h.

Referenced by Dali::Internal::Actor::RayActorTest(), UtcDaliMatrixGetTranslationP(), UtcDaliMatrixOrthoNormalize1P(), and UtcDaliMatrixSetTranslationP().

Here is the caller graph for this function:

const Vector3& Dali::Matrix::GetTranslation3 ( ) const
inline

Gets the x,y and z components of the translation as a Vector3.

This assumes the matrix is a transform matrix. .0

Returns
the translation
Note
inlined for performance reasons (generates less code than a function call)

Definition at line 221 of file matrix.h.

Referenced by Dali::Internal::SceneGraph::AddRendererToRenderList(), GetTransformComponents(), Dali::Internal::SceneGraph::SortRenderItems(), UtcDaliMatrixGetTranslation3P(), and UtcDaliMatrixSetTranslation3P().

Here is the caller graph for this function:

Vector3 Dali::Matrix::GetXAxis ( ) const
Vector3 Dali::Matrix::GetYAxis ( ) const
Vector3 Dali::Matrix::GetZAxis ( ) const
bool Dali::Matrix::Invert ( )

Generic brute force Matrix Invert.

Using the Matrix invert function for the specific type of matrix you are dealing with is faster, more accurate. .0

Returns
true if successful

Definition at line 205 of file matrix.cpp.

References AsFloat(), Dali::InvertMatrix(), and mMatrix.

Referenced by Dali::Internal::anonymous_namespace{camera-actor-impl.cpp}::BuildOrthoPickingRay(), Dali::Internal::Actor::ScreenToLocal(), Dali::Internal::UnprojectFull(), UtcDaliMatrix3Invert(), UtcDaliMatrixInvert01P(), and UtcDaliMatrixInvert02P().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::InvertTransform ( Matrix result) const

Invert a transform Matrix.

Any Matrix representing only a rotation and/or translation can be inverted using this function. It is faster and more accurate then using Invert(). .0

Parameters
[out]resultreturns the inverse of this matrix

Definition at line 135 of file matrix.cpp.

References AsFloat(), DALI_ASSERT_ALWAYS, Dali::Equals(), Dali::EqualsZero(), anonymous_namespace{utc-Dali-Matrix3.cpp}::m1, MATH_INCREASE_BY, and mMatrix.

Referenced by UtcDaliMatrixInvertTransformN(), and UtcDaliMatrixInvertTransformP().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::Multiply ( Matrix result,
const Matrix lhs,
const Matrix rhs 
)
static

Function to multiply two matrices and store the result onto third.

Use this method in time critical path as it does not require temporaries .0

Parameters
resultof the multiplication
lhsmatrix, this can be same matrix as result
rhsmatrix, this cannot be same matrix as result

Definition at line 266 of file matrix.cpp.

References AsFloat(), MATH_INCREASE_BY, MATH_INCREASE_COUNTER, Dali::anonymous_namespace{compile-time-math.cpp}::value0, Dali::anonymous_namespace{compile-time-math.cpp}::value1, Dali::anonymous_namespace{compile-time-math.cpp}::value2, and Dali::anonymous_namespace{compile-time-math.cpp}::value3.

Referenced by Dali::Internal::SceneGraph::AddRendererToRenderList(), Dali::Internal::SceneGraph::AnimatableProperty< Matrix >::BakeRelative(), Dali::Internal::anonymous_namespace{camera-actor-impl.cpp}::BuildOrthoPickingRay(), Dali::Internal::ProjectFull(), Dali::Internal::Actor::ScreenToLocal(), Dali::Internal::anonymous_namespace{render-renderer.cpp}::SetMatrices(), Dali::Internal::SceneGraph::AnimatableProperty< Matrix >::SetRelative(), Dali::Internal::UnprojectFull(), Dali::Internal::SceneGraph::CameraAttachment::Update(), Dali::Internal::SceneGraph::CameraAttachment::UpdateFrustum(), UtcDaliCameraActorCheckLookAtAndFreeLookViews02(), UtcDaliCameraActorCheckLookAtAndFreeLookViews03(), UtcDaliCameraActorModelView(), UtcDaliMatrixInvert01P(), UtcDaliMatrixInvertTransformP(), UtcDaliMatrixMultiplyP(), UtcDaliMatrixSetInverseTransformComponent01P(), UtcDaliMatrixSetInverseTransformComponent02P(), and UtcDaliMatrixSetTransformComponents01P().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::Multiply ( Matrix result,
const Matrix lhs,
const Quaternion rhs 
)
static

Function to multiply a matrix and quaternion and store the result onto third.

Use this method in time critical path as it does not require temporaries .0

Parameters
resultof the multiplication
lhsmatrix, this can be same matrix as result
rhsquaternion

Definition at line 347 of file matrix.cpp.

References AsFloat(), anonymous_namespace{matrix.cpp}::Convert(), MATH_INCREASE_BY, MATH_INCREASE_COUNTER, Dali::anonymous_namespace{compile-time-math.cpp}::value0, Dali::anonymous_namespace{compile-time-math.cpp}::value1, Dali::anonymous_namespace{compile-time-math.cpp}::value2, and Dali::anonymous_namespace{compile-time-math.cpp}::value3.

Here is the call graph for this function:

bool Dali::Matrix::operator!= ( const Matrix rhs) const

The inequality operator.

Utilises appropriate machine epsilon values. .0

Parameters
[in]rhsthe Matrix to compare this to
Returns
true if the matrices are not equal.

Definition at line 488 of file matrix.cpp.

Vector4 Dali::Matrix::operator* ( const Vector4 rhs) const

The multiplication operator.

.0

Parameters
[in]rhsthe Matrix to multiply this by
Returns
A matrix containing the result

Definition at line 428 of file matrix.cpp.

References MATH_INCREASE_BY, mMatrix, Dali::Vector4::w, Dali::Vector4::x, Dali::Vector4::y, and Dali::Vector4::z.

Matrix & Dali::Matrix::operator= ( const Matrix matrix)

Assignment operator.

.0

Parameters
[in]matrixto copy values from
Returns
a reference to this

Definition at line 125 of file matrix.cpp.

References mMatrix, and anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX.

bool Dali::Matrix::operator== ( const Matrix rhs) const

The equality operator.

Utilises appropriate machine epsilon values.

.0

Parameters
[in]rhsthe Matrix to compare this to
Returns
true if the matrices are equal

Definition at line 467 of file matrix.cpp.

References Dali::GetRangedEpsilon(), and mMatrix.

Here is the call graph for this function:

void Dali::Matrix::OrthoNormalize ( )

Makes the axes of the matrix orthogonal to each other and of unit length.

This function is used to correct floating point errors which would otherwise accumulate as operations are applied to the matrix. This function assumes the matrix is a transform matrix. .0

Definition at line 498 of file matrix.cpp.

References Dali::Vector4::Cross(), GetXAxis(), GetYAxis(), GetZAxis(), mMatrix, Dali::Vector4::Normalize(), anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_ROW, anonymous_namespace{matrix.cpp}::ROW1_OFFSET(), and anonymous_namespace{matrix.cpp}::ROW2_OFFSET().

Referenced by UtcDaliMatrixOrthoNormalize0P(), and UtcDaliMatrixOrthoNormalize1P().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::SetIdentity ( )
void Dali::Matrix::SetIdentityAndScale ( const Vector3 scale)

Sets this matrix to be an identity matrix with scale.

.0

Parameters
scaleto set on top of identity matrix

Definition at line 244 of file matrix.cpp.

References mMatrix, anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_MATRIX, Dali::Vector3::x, Dali::Vector3::y, and Dali::Vector3::z.

Referenced by Dali::Toolkit::Internal::Model3dView::UpdateView(), and UtcDaliMatrixSetIdentityAndScaleP().

Here is the caller graph for this function:

void Dali::Matrix::SetInverseTransformComponents ( const Vector3 scale,
const Quaternion rotation,
const Vector3 translation 
)

Sets this matrix to contain the inverse of the position, scale and rotation components.

Performs translation, then rotation, then scale. .0

Parameters
[in]scaleto apply
[in]rotationto apply
[in]translationto apply

Definition at line 608 of file matrix.cpp.

References Dali::Quaternion::Invert(), Dali::Quaternion::IsIdentity(), MATH_INCREASE_BY, MATH_INCREASE_COUNTER, mMatrix, Dali::Quaternion::mVector, Dali::Quaternion::Rotate(), Dali::Vector4::w, Dali::Vector4::x, Dali::Vector3::x, Dali::Vector4::y, Dali::Vector3::y, Dali::Vector4::z, and Dali::Vector3::z.

Referenced by Dali::Internal::SceneGraph::anonymous_namespace{scene-graph-camera-attachment.cpp}::LookAt(), Dali::Toolkit::Internal::LookAt(), Dali::Internal::Actor::RayActorTest(), Dali::Internal::SceneGraph::CameraAttachment::UpdateViewMatrix(), UtcDaliMatrixSetInverseTransformComponent01P(), and UtcDaliMatrixSetInverseTransformComponent02P().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::SetInverseTransformComponents ( const Vector3 xAxis,
const Vector3 yAxis,
const Vector3 zAxis,
const Vector3 translation 
)

Sets this matrix to contain the inverse of the orthonormal basis and position components.

Performs translation, then rotation. .0

Parameters
[in]xAxisThe X axis of the basis
[in]yAxisThe Y axis of the basis
[in]zAxisThe Z axis of the basis
[in]translationto apply

Definition at line 683 of file matrix.cpp.

References mMatrix, SetTranslation(), Dali::Vector4::w, Dali::Vector3::x, Dali::Vector3::y, and Dali::Vector3::z.

Here is the call graph for this function:

void Dali::Matrix::SetTransformComponents ( const Vector3 scale,
const Quaternion rotation,
const Vector3 translation 
)
void Dali::Matrix::SetTranslation ( const Vector4 translation)

Sets the translation.

This assumes the matrix is a transform matrix. .0

Parameters
[in]translationthe translation

Definition at line 256 of file matrix.cpp.

References mMatrix, anonymous_namespace{matrix3.cpp}::NUM_BYTES_IN_ROW, and anonymous_namespace{matrix.cpp}::ROW3_OFFSET().

Referenced by SetInverseTransformComponents(), UtcDaliMatrixOperatorMultiply02P(), UtcDaliMatrixSetTranslation3P(), and UtcDaliMatrixSetTranslationP().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Matrix::SetTranslation ( const Vector3 translation)

Sets the x,y and z components of the translation from a Vector3.

This assumes the matrix is a transform matrix. .0

Parameters
[in]translationthe translation

Definition at line 260 of file matrix.cpp.

References mMatrix, anonymous_namespace{matrix.cpp}::NUM_BYTES_IN_ROW_OF_3(), and anonymous_namespace{matrix.cpp}::ROW3_OFFSET().

Here is the call graph for this function:

void Dali::Matrix::SetXAxis ( const Vector3 axis)

Sets the x axis.

This assumes the matrix is a transform matrix. .0

Parameters
[in]axisthe values to set the axis to

Definition at line 529 of file matrix.cpp.

References mMatrix, Dali::Vector3::x, Dali::Vector3::y, and Dali::Vector3::z.

Referenced by UtcDaliMatrixInvert02P(), UtcDaliMatrixSetTransformComponents01P(), UtcDaliMatrixSetXAxisP(), UtcDaliQuaternionCtorAxesP03(), and UtcDaliQuaternionCtorMatrixP03().

Here is the caller graph for this function:

void Dali::Matrix::SetYAxis ( const Vector3 axis)

Sets the y axis.

This assumes the matrix is a transform matrix. .0

Parameters
[in]axisthe values to set the axis to

Definition at line 536 of file matrix.cpp.

References mMatrix, Dali::Vector3::x, Dali::Vector3::y, and Dali::Vector3::z.

Referenced by UtcDaliMatrixSetTransformComponents01P(), UtcDaliMatrixSetYAxisP(), UtcDaliQuaternionCtorAxesP03(), and UtcDaliQuaternionCtorMatrixP03().

Here is the caller graph for this function:

void Dali::Matrix::SetZAxis ( const Vector3 axis)

Sets the z axis.

This assumes the matrix is a transform matrix. .0

Parameters
[in]axisthe values to set the axis to

Definition at line 543 of file matrix.cpp.

References mMatrix, Dali::Vector3::x, Dali::Vector3::y, and Dali::Vector3::z.

Referenced by UtcDaliMatrixSetTransformComponents01P(), UtcDaliMatrixSetZAxisP(), UtcDaliQuaternionCtorAxesP03(), and UtcDaliQuaternionCtorMatrixP03().

Here is the caller graph for this function:

void Dali::Matrix::Transpose ( )

Swaps the rows to columns.

.0

Definition at line 212 of file matrix.cpp.

References mMatrix.

Referenced by UtcDaliMatrixTransposeP().

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const Matrix matrix 
)
friend

Print a matrix.

It is printed in memory order, i.e. each printed row is contiguous in memory. .0

Parameters
[in]oThe output stream operator.
[in]matrixThe matrix to print.
Returns
The output stream operator.

Definition at line 779 of file matrix.cpp.

Member Data Documentation

const Matrix Dali::Matrix::IDENTITY
static
float Dali::Matrix::mMatrix[16]
private

The documentation for this class was generated from the following files:
Dali Docs Home
Read more about Dali