SOFA plugin: LeapMotion  master
Open source framework for multi-physics simuation
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Leap::Matrix Struct Reference

#include <LeapMath.h>

Detailed Description

The Matrix struct represents a transformation matrix.

To use this struct to transform a Vector, construct a matrix containing the desired transformation and then use the Matrix::transformPoint() or Matrix::transformDirection() functions to apply the transform.

Transforms can be combined by multiplying two or more transform matrices using the * operator.

Public Attributes

Vector xBasis
 
Vector yBasis
 
Vector zBasis
 
Vector origin
 

Public Member Functions

 Matrix ()
 
 Matrix (const Matrix &other)
 
 Matrix (const Vector &_xBasis, const Vector &_yBasis, const Vector &_zBasis)
 
 Matrix (const Vector &_xBasis, const Vector &_yBasis, const Vector &_zBasis, const Vector &_origin)
 
 Matrix (const Vector &axis, float angleRadians)
 
 Matrix (const Vector &axis, float angleRadians, const Vector &translation)
 
void setRotation (const Vector &_axis, float angleRadians)
 
Vector transformPoint (const Vector &in) const
 
Vector transformDirection (const Vector &in) const
 
Matrix rigidInverse () const
 
Matrix operator* (const Matrix &other) const
 
Matrixoperator*= (const Matrix &other)
 
bool operator== (const Matrix &other) const
 
bool operator!= (const Matrix &other) const
 
template<typename Matrix3x3Type >
const Matrix3x3Type toMatrix3x3 () const
 
template<typename Matrix4x4Type >
const Matrix4x4Type toMatrix4x4 () const
 
template<typename T >
T * toArray3x3 (T *output) const
 
FloatArray toArray3x3 () const
 
template<typename T >
T * toArray4x4 (T *output) const
 
FloatArray toArray4x4 () const
 
std::string toString () const
 

Static Public Member Functions

static const Matrixidentity ()
 

Friends

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

Attribute details

◆ origin

Vector Leap::Matrix::origin

The translation factors for all three axes.

◆ xBasis

Vector Leap::Matrix::xBasis

The rotation and scale factors for the x-axis.

◆ yBasis

Vector Leap::Matrix::yBasis

The rotation and scale factors for the y-axis.

◆ zBasis

Vector Leap::Matrix::zBasis

The rotation and scale factors for the z-axis.

Constructor details

◆ Matrix() [1/6]

Leap::Matrix::Matrix ( )
inline

Constructs an identity transformation matrix.

◆ Matrix() [2/6]

Leap::Matrix::Matrix ( const Matrix other)
inline

Constructs a copy of the specified Matrix object.

◆ Matrix() [3/6]

Leap::Matrix::Matrix ( const Vector _xBasis,
const Vector _yBasis,
const Vector _zBasis 
)
inline

Constructs a transformation matrix from the specified basis vectors.

Parameters
_xBasisA Vector specifying rotation and scale factors for the x-axis.
_yBasisA Vector specifying rotation and scale factors for the y-axis.
_zBasisA Vector specifying rotation and scale factors for the z-axis.

◆ Matrix() [4/6]

Leap::Matrix::Matrix ( const Vector _xBasis,
const Vector _yBasis,
const Vector _zBasis,
const Vector _origin 
)
inline

Constructs a transformation matrix from the specified basis and translation vectors.

Parameters
_xBasisA Vector specifying rotation and scale factors for the x-axis.
_yBasisA Vector specifying rotation and scale factors for the y-axis.
_zBasisA Vector specifying rotation and scale factors for the z-axis.
_originA Vector specifying translation factors on all three axes.

◆ Matrix() [5/6]

Leap::Matrix::Matrix ( const Vector axis,
float  angleRadians 
)
inline

Constructs a transformation matrix specifying a rotation around the specified vector.

Parameters
axisA Vector specifying the axis of rotation.
angleRadiansThe amount of rotation in radians.

◆ Matrix() [6/6]

Leap::Matrix::Matrix ( const Vector axis,
float  angleRadians,
const Vector translation 
)
inline

Constructs a transformation matrix specifying a rotation around the specified vector and a translation by the specified vector.

Parameters
axisA Vector specifying the axis of rotation.
angleRadiansThe angle of rotation in radians.
translationA Vector representing the translation part of the transform.

Function details

◆ identity()

static const Matrix& Leap::Matrix::identity ( )
inlinestatic

Returns the identity matrix specifying no translation, rotation, and scale.

Returns
The identity matrix.

◆ operator!=()

bool Leap::Matrix::operator!= ( const Matrix other) const
inline

Compare Matrix inequality component-wise.

◆ operator*()

Matrix Leap::Matrix::operator* ( const Matrix other) const
inline

Multiply transform matrices.

Combines two transformations into a single equivalent transformation.

Parameters
otherA Matrix to multiply on the right hand side.
Returns
A new Matrix representing the transformation equivalent to applying the other transformation followed by this transformation.

◆ operator*=()

Matrix& Leap::Matrix::operator*= ( const Matrix other)
inline

Multiply transform matrices and assign the product.

◆ operator==()

bool Leap::Matrix::operator== ( const Matrix other) const
inline

Compare Matrix equality component-wise.

◆ rigidInverse()

Matrix Leap::Matrix::rigidInverse ( ) const
inline

Performs a matrix inverse if the matrix consists entirely of rigid transformations (translations and rotations). If the matrix is not rigid, this operation will not represent an inverse.

Note that all matrices that are directly returned by the API are rigid.

Returns
The rigid inverse of the matrix.

◆ setRotation()

void Leap::Matrix::setRotation ( const Vector _axis,
float  angleRadians 
)
inline

Sets this transformation matrix to represent a rotation around the specified vector.

This function erases any previous rotation and scale transforms applied to this matrix, but does not affect translation.

Parameters
_axisA Vector specifying the axis of rotation.
angleRadiansThe amount of rotation in radians.

◆ toArray3x3() [1/2]

FloatArray Leap::Matrix::toArray3x3 ( ) const
inline

Convert a 3x3 Matrix object to a 9 element row-major float array.

Translation factors are discarded.

Returns a FloatArray struct to avoid dynamic memory allocation.

◆ toArray3x3() [2/2]

template<typename T >
T* Leap::Matrix::toArray3x3 ( T *  output) const
inline

Writes the 3x3 Matrix object to a 9 element row-major float or double array.

Translation factors are discarded.

Returns a pointer to the same data.

◆ toArray4x4() [1/2]

FloatArray Leap::Matrix::toArray4x4 ( ) const
inline

Convert a 4x4 Matrix object to a 16 element row-major float array.

Returns a FloatArray struct to avoid dynamic memory allocation.

◆ toArray4x4() [2/2]

template<typename T >
T* Leap::Matrix::toArray4x4 ( T *  output) const
inline

Writes the 4x4 Matrix object to a 16 element row-major float or double array.

Returns a pointer to the same data.

◆ toMatrix3x3()

template<typename Matrix3x3Type >
const Matrix3x3Type Leap::Matrix::toMatrix3x3 ( ) const
inline

Convert a Leap::Matrix object to another 3x3 matrix type.

The new type must define a constructor function that takes each matrix element as a parameter in row-major order.

Translation factors are discarded.

◆ toMatrix4x4()

template<typename Matrix4x4Type >
const Matrix4x4Type Leap::Matrix::toMatrix4x4 ( ) const
inline

Convert a Leap::Matrix object to another 4x4 matrix type.

The new type must define a constructor function that takes each matrix element as a parameter in row-major order.

◆ toString()

std::string Leap::Matrix::toString ( ) const
inline

Write the matrix to a string in a human readable format.

◆ transformDirection()

Vector Leap::Matrix::transformDirection ( const Vector in) const
inline

Transforms a vector with this matrix by transforming its rotation and scale only.

Parameters
inThe Vector to transform.
Returns
A new Vector representing the transformed original.

◆ transformPoint()

Vector Leap::Matrix::transformPoint ( const Vector in) const
inline

Transforms a vector with this matrix by transforming its rotation, scale, and translation.

Translation is applied after rotation and scale.

Parameters
inThe Vector to transform.
Returns
A new Vector representing the transformed original.

Related details

◆ operator<<

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

Write the matrix to an output stream in a human readable format.