# MatrixΒΆ

Matrix Struct Reference

The Matrix struct represents a transformation matrix. More...

## Public Member Functions

Matrix ()
Constructs an identity transformation matrix. More...

Matrix (const Matrix &other)
Constructs a copy of the specified Matrix object. More...

Matrix (const Vector &_xBasis, const Vector &_yBasis, const Vector &_zBasis)
Constructs a transformation matrix from the specified basis vectors. More...

Matrix (const Vector &_xBasis, const Vector &_yBasis, const Vector &_zBasis, const Vector &_origin)
Constructs a transformation matrix from the specified basis and translation vectors. More...

Matrix (const Vector &axis, float angleRadians)
Constructs a transformation matrix specifying a rotation around the specified vector. More...

Matrix (const Vector &axis, float angleRadians, const Vector &translation)
Constructs a transformation matrix specifying a rotation around the specified vector and a translation by the specified vector. More...

bool operator!= (const Matrix &other) const
Compare Matrix inequality component-wise. More...

Matrix operator* (const Matrix &other) const
Multiply transform matrices. More...

Matrixoperator*= (const Matrix &other)
Multiply transform matrices and assign the product. More...

bool operator== (const Matrix &other) const
Compare Matrix equality component-wise. More...

Matrix rigidInverse () const
Performs a matrix inverse if the matrix consists entirely of rigid transformations (translations and rotations). More...

void setRotation (const Vector &axis, float angleRadians)
Sets this transformation matrix to represent a rotation around the specified vector. More...

template<typename T >
T * toArray3x3 (T *output) const
Writes the 3x3 Matrix object to a 9 element row-major float or double array. More...

FloatArray toArray3x3 () const
Convert a 3x3 Matrix object to a 9 element row-major float array. More...

template<typename T >
T * toArray4x4 (T *output) const
Writes the 4x4 Matrix object to a 16 element row-major float or double array. More...

FloatArray toArray4x4 () const
Convert a 4x4 Matrix object to a 16 element row-major float array. More...

template<typename Matrix3x3Type >
const Matrix3x3Type toMatrix3x3 () const
Convert a Leap::Matrix object to another 3x3 matrix type. More...

template<typename Matrix4x4Type >
const Matrix4x4Type toMatrix4x4 () const
Convert a Leap::Matrix object to another 4x4 matrix type. More...

std::string toString () const
Write the matrix to a string in a human readable format. More...

Vector transformDirection (const Vector &in) const
Transforms a vector with this matrix by transforming its rotation and scale only. More...

Vector transformPoint (const Vector &in) const
Transforms a vector with this matrix by transforming its rotation, scale, and translation. More...

## Static Public Member Functions

static const Matrixidentity ()
Returns the identity matrix specifying no translation, rotation, and scale. More...

## Public Attributes

Vector origin
The translation factors for all three axes. More...

Vector xBasis
The basis vector for the x-axis. More...

Vector yBasis
The basis vector for the y-axis. More...

Vector zBasis
The basis vector for the z-axis. More...

## Friends

std::ostream & operator<< (std::ostream &out, const Matrix &matrix)
Write the matrix to an output stream in a human readable format. More...

## 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.

Since
1.0

## Constructor & Destructor Documentation

 Matrix ( )
inline

Constructs an identity transformation matrix.

Since
1.0
 Matrix ( const Matrix & other )
inline

Constructs a copy of the specified Matrix object.

Matrix thisMatrix = Matrix(thatMatrix);
Since
1.0
 Matrix ( const Vector & _xBasis, const Vector & _yBasis, const Vector & _zBasis )
inline

Constructs a transformation matrix from the specified basis vectors.

Vector xBasis = Vector(23, 0, 0);
Vector yBasis = Vector(0, 12, 0);
Vector zBasis = Vector(0, 0, 45);
Matrix transformMatrix = Matrix(xBasis, yBasis, zBasis);
Parameters
 _xBasis A Vector specifying rotation and scale factors for the x-axis. _yBasis A Vector specifying rotation and scale factors for the y-axis. _zBasis A Vector specifying rotation and scale factors for the z-axis.
Since
1.0
 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.

Hand leapHand = frame.hand(handID);
Vector handXBasis = leapHand.basis().xBasis;
Vector handYBasis = leapHand.basis().yBasis;
Vector handZBasis = leapHand.basis().zBasis;
Vector handOrigin = leapHand.palmPosition();
Matrix handTransform = Matrix(handXBasis, handYBasis, handZBasis, handOrigin);
Parameters
 _xBasis A Vector specifying rotation and scale factors for the x-axis. _yBasis A Vector specifying rotation and scale factors for the y-axis. _zBasis A Vector specifying rotation and scale factors for the z-axis. _origin A Vector specifying translation factors on all three axes.
Since
1.0
 Matrix ( const Vector & axis, float angleRadians )
inline

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

Vector axisOfRotation = leapHand.direction();
float angleOfRotation = 1.27;
Matrix rotator = Matrix(axisOfRotation, angleOfRotation);
Parameters
 axis A Vector specifying the axis of rotation. angleRadians The amount of rotation in radians.
Since
1.0
 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.

Vector rotationAxis = Vector::yAxis();
float angle = .733;
Vector translation = Vector(10,220,103);
Matrix transform = Matrix(rotationAxis, angle, translation);
Parameters
 axis A Vector specifying the axis of rotation. angleRadians The angle of rotation in radians. translation A Vector representing the translation part of the transform.
Since
1.0

## Member Function Documentation

 static const Matrix& identity ( )
inlinestatic

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

Matrix identity = Matrix::identity();
Returns
The identity matrix.
Since
1.0
 bool operator!= ( const Matrix & other ) const
inline

Compare Matrix inequality component-wise.

thisMatrix != thatMatrix;
Since
1.0
 Matrix operator* ( const Matrix & other ) const
inline

Multiply transform matrices.

Combines two transformations into a single equivalent transformation.

thisMatrix * thatMatrix;
Parameters
 other A 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.
Since
1.0
 Matrix& operator*= ( const Matrix & other )
inline

Multiply transform matrices and assign the product.

thisMatrix *= thatMatrix;
Since
1.0
 bool operator== ( const Matrix & other ) const
inline

Compare Matrix equality component-wise.

thisMatrix == thatMatrix;
Since
1.0
 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.

thisMatrix = thatMatrix.rigidInverse();

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

Returns
The rigid inverse of the matrix.
Since
1.0
 void setRotation ( const Vector & axis, float angleRadians )
inline

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

thisMatrix.setRotation(Vector::zAxis(), 1.46);

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

Parameters
 axis A Vector specifying the axis of rotation. angleRadians The amount of rotation in radians.
Since
1.0
 T* toArray3x3 ( T * output ) const
inline

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

Returns a pointer to the same data.

Since
1.0
 FloatArray toArray3x3 ( ) const
inline

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

FloatArray rotations = thisMatrix.toArray3x3();

Returns a FloatArray struct to avoid dynamic memory allocation.

Since
1.0
 T* 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.

Since
1.0
 FloatArray toArray4x4 ( ) const
inline

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

FloatArray transforms = thisMatrix.toArray4x4();

Returns a FloatArray struct to avoid dynamic memory allocation.

Since
1.0
 const Matrix3x3Type 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.

Since
1.0
 const Matrix4x4Type 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.

Since
1.0
 std::string toString ( ) const
inline

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

Since
1.0
 Vector transformDirection ( const Vector & in ) const
inline

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

Vector newDirection = thisMatrix.transformDirection(oldDirection);
Parameters
 in The Vector to transform.
Returns
A new Vector representing the transformed original.
Since
1.0
 Vector transformPoint ( const Vector & in ) const
inline

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

Vector newPosition = thisMatrix.transformPoint(oldPosition);

Translation is applied after rotation and scale.

Parameters
 in The Vector to transform.
Returns
A new Vector representing the transformed original.
Since
1.0

## Friends And Related Function Documentation

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

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

std::cout << thisMatrix << std::endl;
Since
1.0

## Member Data Documentation

 Vector origin

The translation factors for all three axes.

Vector thisTranslation = thisMatrix.origin;
Since
1.0
 Vector xBasis

The basis vector for the x-axis.

Vector xTransform = thisMatrix.xBasis;
Since
1.0
 Vector yBasis

The basis vector for the y-axis.

Vector yTransform = thisMatrix.yBasis;
Since
1.0
 Vector zBasis

The basis vector for the z-axis.

Vector zTransform = thisMatrix.zBasis;
Since
1.0