Helper class for exchanging 4x4 transform matrices. More...
#include <InstantIO/Matrix4.h>
Public Types | |
enum | MatrixElementIndex { M_00 = 0, M_01 = 1, M_02 = 2, M_03 = 3, M_10 = 4, M_11 = 5, M_12 = 6, M_13 = 7, M_20 = 8, M_21 = 9, M_22 = 10, M_23 = 11, M_30 = 12, M_31 = 13, M_32 = 14, M_33 = 15 } |
Defines symbolic indices for the elements of the matrix. | |
enum | QuaternionElementIndex { Q_X = 0, Q_Y = 1, Q_Z = 2, Q_W = 3 } |
Defines symbolic indices for the elements of a quaternion. | |
enum | VectorElementIndex { V_X = 0, V_Y = 1, V_Z = 2 } |
Defines symbolic indices for the elements of a vector. | |
Public Member Functions | |
Matrix4 () | |
Creates a new Matrix4 object that contains an identity matrix. | |
Matrix4 (const Matrix4 &obj) | |
Creates a new Matrix4 object that is an exact copy of another Matrix4 object. | |
Matrix4 (const T matrix[16], bool transposed=false) | |
Creates a new Matrix4 object that gets initialized by a given 16 component float array representing a 4x4 matrix. | |
Matrix4 (T tx, T ty, T tz, T qx, T qy, T qz, T qw) | |
Creates a new Matrix4 object and initializes it with a given translation and rotation. | |
Matrix4 (T tx, T ty, T tz, T qx, T qy, T qz, T qw, T sx, T sy, T sz) | |
Creates a new Matrix4 object and initializes it with a given translation, rotation and scale. | |
const Matrix4 & | operator= (const Matrix4 &obj) |
Assigns another Matrix4 to this Matrix4. | |
const T * | operator= (const T matrix[16]) |
Assigns the sixteen components of an float array to this Matrix4. | |
void | setIdentity () |
Sets the Matrix4 to identity. | |
void | setTransform (T tx, T ty, T tz) |
Sets the Matrix4 from three components of a translation. | |
void | setTransform (T qx, T qy, T qz, T qw) |
Sets the Matrix4 from four components of a quaternion. | |
void | setTransform (T tx, T ty, T tz, T qx, T qy, T qz, T qw) |
Sets the Matrix4 from three components of a translation and four components of a quaternion. | |
void | setTransform (T tx, T ty, T tz, T qx, T qy, T qz, T qw, T sx, T sy, T sz) |
Sets the Matrix4 from three components of a translation, four components of a quaternion and three elements of a scale vector. | |
template<class TranslationT , class QuaternionT , class ScaleT > | |
void | setTransform (const TranslationT &t, const QuaternionT &q, const ScaleT &s) |
Sets the Matrix4 from a from a translation , a quaternion and a scale. | |
template<class TranslationT , class QuaternionT > | |
void | setTransform (const TranslationT &t, const QuaternionT &q) |
Sets the Matrix4 from a translation and a quaternion. | |
template<class Vec3fT > | |
void | setTranslationAxisAngle (const Vec3fT &translation, const Vec3fT &axis, T angle) |
Sets the Matrix4 from a translation, a rotation axis and a rotation angle. | |
template<class ArrayT > | |
void | setMatrixFromArray (const ArrayT &array, bool transposed=false) |
Sets the Matrix4 elements from an array of 16 values. | |
template<class MatrixT > | |
void | setMatrixFromMatrix (const MatrixT &matrix, bool transposed=false) |
Sets the Matrix4 elements from a matrix. | |
void | setRotationFromQuaternion (T qx, T qy, T qz, T qw) |
Sets the value of the Matrix4 from a quaternion. | |
template<class QuaternionT > | |
void | setRotationFromQuaternion (const QuaternionT &q) |
Sets the value of the Matrix4 from a quaternion. | |
template<class RotationMatrixT > | |
void | setRotationFromRotationMatrix (const RotationMatrixT &r, bool transposed=false) |
Sets the value of the Matrix4 from a 3x3 rotation matrix. | |
template<class TranslationT > | |
void | setTranslation (const TranslationT &translation) |
Sets the translation components of the Matrix4. | |
void | setTranslation (T tx, T ty, T tz) |
Sets the translation components of the Matrix4. | |
template<class ScaleT > | |
void | applyScale (const ScaleT &s) |
Scales the Matrix4. | |
void | applyScale (T sx, T sy, T sz) |
Scales the Matrix4. | |
T | operator[] (MatrixElementIndex i) const |
Returns a component of the Matrix4. | |
T & | operator[] (MatrixElementIndex i) |
Returns a component of the Matrix4. | |
const T * | getValue () const |
Returns the components of the Matrix4 as an array of 16 float values. | |
T * | getValue () |
Returns the components of the Matrix4 as an array of 16 float values. | |
void | getTransform (T &tx, T &ty, T &tz, T &qx, T &qy, T &qz, T &qw, T &sx, T &sy, T &sz) const |
Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale. | |
void | getTransform (T &tx, T &ty, T &tz, T &qx, T &qy, T &qz, T &qw) const |
Returns the transformation stored in the Matrix4 as a translation and a quaternion. | |
template<class TranslationT , class QuaternionT , class ScaleT > | |
void | getTransform (TranslationT &t, QuaternionT &q, ScaleT &s) const |
Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale. | |
template<class TranslationT , class QuaternionT > | |
void | getTransform (TranslationT &t, QuaternionT &q) const |
Returns the transformation stored in the Matrix4 as a translation and a quaternion. | |
template<class ArrayT > | |
void | getMatrixAsArray (ArrayT &matrix, bool transposed=false) const |
Returns the components of the Matrix4 in an array of 16 values. | |
template<class MatrixT > | |
void | getMatrixAsMatrix (MatrixT &matrix, bool transposed=false) const |
Returns the components of the Matrix4 in a matrix. | |
operator T * () | |
Transforms the Matrix4 to an array of 16 float values. | |
operator const T * () const | |
Transforms the Matrix4 to an array of 16 float values. | |
void | scale (T s) |
Scales the Matrix4 elements. | |
void | add (const Matrix4 &m) |
Adds a matrix. | |
void | addScaled (const Matrix4 &m, T s) |
Adds a scaled Matrix4. | |
void | negate () |
Negates the Matrix4. | |
void | multLeft (const Matrix4 &m) |
Multiplies the matrix with another matrix. | |
void | mult (const Matrix4 &m) |
Multiplies the matrix with another matrix. | |
template<class Vec3fT > | |
void | multVec (Vec3fT &v) |
Multiplies a vector with the matrix. | |
template<class Vec3fT > | |
void | multPnt (Vec3fT &v) |
Multiplies a point with the matrix. | |
T | normInfinity () |
Returns the infinity norm of the Matrix4. | |
T | det () const |
Returns the determinat of the whole 4x4 matrix. | |
bool | getInverse (Matrix4 &result) const |
Stores the inverse of the matrix into result. | |
bool | sqrt () |
Sets this matrix to its square root, assumes det > 0. | |
void | setExpOf (const Matrix4 &m) |
Sets this matrix to the exponential of the given matrix. | |
bool | setLogOf (const Matrix4 &matrix) |
Sets this Matrix4 to the logarithm of the given matrix, assumes det > 0. | |
void | print (std::ostream &target) |
Prints the matrix to an output stream. | |
Static Public Attributes | |
static const T | epsilon = static_cast<T>(0.000001) |
Epsilon value used for comparisons. |
Helper class for exchanging 4x4 transform matrices.
Matrix4 is a basic helper class for exchanging transformations between different software components. It does not contain any means for matrix arithmetics, only methods for setting and getting the transformation. It is not meant to be used directly by software components for matrix representation. Instead, software components should use their own, appropriate classes for handling matrices. Only when sending matrices to an OutSlot, or when receiving matrices from an InSlot, the internal representation of matrices should be converted to Matrix4's. This ensures the interoperability between different software components that use different internal representations for matrices.
Matrices are internally stored as 4x4 matrices. You can access these matrices directly, or you can use methods that convert a translation vector, a quaternion axis and a scale vector to a Matrix4.
InstantIO::Matrix4< T >::Matrix4 | ( | const Matrix4< T > & | obj | ) | [inline] |
Creates a new Matrix4 object that is an exact copy of another Matrix4 object.
obj | The other Matrix4 object |
InstantIO::Matrix4< T >::Matrix4 | ( | const T | matrix[16], | |
bool | transposed = false | |||
) | [inline] |
Creates a new Matrix4 object that gets initialized by a given 16 component float array representing a 4x4 matrix.
matrix | The sixteen components of the matrix | |
transposed | Flags that must be set to true when the array needs to be transposed when copying it into the Matrix4 object |
InstantIO::Matrix4< T >::Matrix4 | ( | T | tx, | |
T | ty, | |||
T | tz, | |||
T | qx, | |||
T | qy, | |||
T | qz, | |||
T | qw | |||
) | [inline] |
Creates a new Matrix4 object and initializes it with a given translation and rotation.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion |
InstantIO::Matrix4< T >::Matrix4 | ( | T | tx, | |
T | ty, | |||
T | tz, | |||
T | qx, | |||
T | qy, | |||
T | qz, | |||
T | qw, | |||
T | sx, | |||
T | sy, | |||
T | sz | |||
) | [inline] |
Creates a new Matrix4 object and initializes it with a given translation, rotation and scale.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion | |
sx | The first component of the scale | |
sy | The second component of the scale | |
sz | The third component of the scale |
const Matrix4& InstantIO::Matrix4< T >::operator= | ( | const Matrix4< T > & | obj | ) | [inline] |
Assigns another Matrix4 to this Matrix4.
obj | The other Matrix4 object |
const T* InstantIO::Matrix4< T >::operator= | ( | const T | matrix[16] | ) | [inline] |
Assigns the sixteen components of an float array to this Matrix4.
matrix | The sixteen components of the matrix |
void InstantIO::Matrix4< T >::setTransform | ( | T | tx, | |
T | ty, | |||
T | tz | |||
) | [inline] |
Sets the Matrix4 from three components of a translation.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation |
void InstantIO::Matrix4< T >::setTransform | ( | T | qx, | |
T | qy, | |||
T | qz, | |||
T | qw | |||
) | [inline] |
Sets the Matrix4 from four components of a quaternion.
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion |
void InstantIO::Matrix4< T >::setTransform | ( | T | tx, | |
T | ty, | |||
T | tz, | |||
T | qx, | |||
T | qy, | |||
T | qz, | |||
T | qw | |||
) | [inline] |
Sets the Matrix4 from three components of a translation and four components of a quaternion.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion |
void InstantIO::Matrix4< T >::setTransform | ( | T | tx, | |
T | ty, | |||
T | tz, | |||
T | qx, | |||
T | qy, | |||
T | qz, | |||
T | qw, | |||
T | sx, | |||
T | sy, | |||
T | sz | |||
) | [inline] |
Sets the Matrix4 from three components of a translation, four components of a quaternion and three elements of a scale vector.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion | |
sx | The first component of the scale | |
sy | The second component of the scale | |
sz | The third component of the scale |
void InstantIO::Matrix4< T >::setTransform | ( | const TranslationT & | t, | |
const QuaternionT & | q, | |||
const ScaleT & | s | |||
) | [inline] |
Sets the Matrix4 from a from a translation , a quaternion and a scale.
t | The translation (arb. 3 component vector) | |
q | The rotation as quatenion (arb. 4 component vector) | |
s | The scale (arb. 3 component vector) |
void InstantIO::Matrix4< T >::setTransform | ( | const TranslationT & | t, | |
const QuaternionT & | q | |||
) | [inline] |
Sets the Matrix4 from a translation and a quaternion.
t | The translation (arb. 3 component vector) | |
q | The rotation as quatenion (arb. 4 component vector) |
void InstantIO::Matrix4< T >::setTranslationAxisAngle | ( | const Vec3fT & | translation, | |
const Vec3fT & | axis, | |||
T | angle | |||
) | [inline] |
Sets the Matrix4 from a translation, a rotation axis and a rotation angle.
translation | The translation (arb. 3 component vector) | |
axis | The rotation axis (arb. 3 component vector) | |
angle | The rotation angle (in radians) |
void InstantIO::Matrix4< T >::setMatrixFromArray | ( | const ArrayT & | array, | |
bool | transposed = false | |||
) | [inline] |
Sets the Matrix4 elements from an array of 16 values.
array | An arb. 16 component array for the matrix elements | |
transposed | Flags that must be set to true when the array needs to be transposed when copying it into the Matrix4 object |
void InstantIO::Matrix4< T >::setMatrixFromMatrix | ( | const MatrixT & | matrix, | |
bool | transposed = false | |||
) | [inline] |
Sets the Matrix4 elements from a matrix.
matrix | An arb. 4x4 component matrix for the matrix elements | |
transposed | Flags that must be set to true when the matrix needs to be transposed when copying it into the Matrix4 object |
void InstantIO::Matrix4< T >::setRotationFromQuaternion | ( | T | qx, | |
T | qy, | |||
T | qz, | |||
T | qw | |||
) | [inline] |
Sets the value of the Matrix4 from a quaternion.
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion |
void InstantIO::Matrix4< T >::setRotationFromQuaternion | ( | const QuaternionT & | q | ) | [inline] |
Sets the value of the Matrix4 from a quaternion.
q | The rotation as quatenion (arb. 4 component vector) |
void InstantIO::Matrix4< T >::setRotationFromRotationMatrix | ( | const RotationMatrixT & | r, | |
bool | transposed = false | |||
) | [inline] |
Sets the value of the Matrix4 from a 3x3 rotation matrix.
r | The rotation as matrix (matrix type with double indexed access e.g. float[3][3]) | |
transposed | Flags that must be set to true when the matrix needs to be transposed when copying it into the Matrix4 object |
void InstantIO::Matrix4< T >::setTranslation | ( | const TranslationT & | translation | ) | [inline] |
Sets the translation components of the Matrix4.
translation | The translation (arb. 3 component vector) |
void InstantIO::Matrix4< T >::setTranslation | ( | T | tx, | |
T | ty, | |||
T | tz | |||
) | [inline] |
Sets the translation components of the Matrix4.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation |
void InstantIO::Matrix4< T >::applyScale | ( | const ScaleT & | s | ) | [inline] |
Scales the Matrix4.
s | The scale (arb. 3 component vector) |
void InstantIO::Matrix4< T >::applyScale | ( | T | sx, | |
T | sy, | |||
T | sz | |||
) | [inline] |
Scales the Matrix4.
sx | The x scale | |
sy | The y scale | |
sz | The z scale |
T InstantIO::Matrix4< T >::operator[] | ( | MatrixElementIndex | i | ) | const [inline] |
Returns a component of the Matrix4.
i | The index of the component |
T& InstantIO::Matrix4< T >::operator[] | ( | MatrixElementIndex | i | ) | [inline] |
Returns a component of the Matrix4.
i | The index of the component |
const T* InstantIO::Matrix4< T >::getValue | ( | ) | const [inline] |
Returns the components of the Matrix4 as an array of 16 float values.
T* InstantIO::Matrix4< T >::getValue | ( | ) | [inline] |
Returns the components of the Matrix4 as an array of 16 float values.
void InstantIO::Matrix4< T >::getTransform | ( | T & | tx, | |
T & | ty, | |||
T & | tz, | |||
T & | qx, | |||
T & | qy, | |||
T & | qz, | |||
T & | qw, | |||
T & | sx, | |||
T & | sy, | |||
T & | sz | |||
) | const [inline] |
Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion | |
sx | The first component of the scale | |
sy | The second component of the scale | |
sz | The third component of the scale |
void InstantIO::Matrix4< T >::getTransform | ( | T & | tx, | |
T & | ty, | |||
T & | tz, | |||
T & | qx, | |||
T & | qy, | |||
T & | qz, | |||
T & | qw | |||
) | const [inline] |
Returns the transformation stored in the Matrix4 as a translation and a quaternion.
tx | The first component of the translation | |
ty | The second component of the translation | |
tz | The third component of the translation | |
qx | The first component of the quaternion | |
qy | The second component of the quaternion | |
qz | The third component of the quaternion | |
qw | The fourth component of the quaternion |
void InstantIO::Matrix4< T >::getTransform | ( | TranslationT & | t, | |
QuaternionT & | q, | |||
ScaleT & | s | |||
) | const [inline] |
Returns the transformation stored in the Matrix4 as a translation, a quaternion, and a scale.
t | The translation (arb. 3 component vector) | |
q | The rotation as quatenion (arb. 4 component vector) | |
s | The scale (arb. 3 component vector) |
void InstantIO::Matrix4< T >::getTransform | ( | TranslationT & | t, | |
QuaternionT & | q | |||
) | const [inline] |
Returns the transformation stored in the Matrix4 as a translation and a quaternion.
t | The translation (arb. 3 component vector) | |
q | The rotation as quatenion (arb. 4 component vector) |
void InstantIO::Matrix4< T >::getMatrixAsArray | ( | ArrayT & | matrix, | |
bool | transposed = false | |||
) | const [inline] |
Returns the components of the Matrix4 in an array of 16 values.
matrix | An arb. 16 component array for the matrix elements | |
transposed | Flags that must be set to true when the Matrix4 components need to be transposed when copying them into the array |
void InstantIO::Matrix4< T >::getMatrixAsMatrix | ( | MatrixT & | matrix, | |
bool | transposed = false | |||
) | const [inline] |
Returns the components of the Matrix4 in a matrix.
matrix | An arb. 16 component array for the matrix elements | |
transposed | Flags that must be set to true when the Matrix4 components need to be transposed when copying them into the array |
InstantIO::Matrix4< T >::operator T * | ( | ) | [inline] |
Transforms the Matrix4 to an array of 16 float values.
InstantIO::Matrix4< T >::operator const T * | ( | ) | const [inline] |
Transforms the Matrix4 to an array of 16 float values.
void InstantIO::Matrix4< T >::scale | ( | T | s | ) | [inline] |
Scales the Matrix4 elements.
s | The scale factor. |
void InstantIO::Matrix4< T >::add | ( | const Matrix4< T > & | m | ) | [inline] |
Adds a matrix.
m | A Matrix4 object. |
void InstantIO::Matrix4< T >::addScaled | ( | const Matrix4< T > & | m, | |
T | s | |||
) | [inline] |
Adds a scaled Matrix4.
m | A Matrix4 object. | |
scale | A scale factor. |
void InstantIO::Matrix4< T >::multLeft | ( | const Matrix4< T > & | m | ) | [inline] |
Multiplies the matrix with another matrix.
matrix | A Matrix4 object |
void InstantIO::Matrix4< T >::mult | ( | const Matrix4< T > & | m | ) | [inline] |
Multiplies the matrix with another matrix.
matrix | A Matrix4 object |
void InstantIO::Matrix4< T >::multVec | ( | Vec3fT & | v | ) | [inline] |
Multiplies a vector with the matrix.
v | The vector. |
void InstantIO::Matrix4< T >::multPnt | ( | Vec3fT & | v | ) | [inline] |
Multiplies a point with the matrix.
v | The point. |
T InstantIO::Matrix4< T >::normInfinity | ( | ) | [inline] |
Returns the infinity norm of the Matrix4.
T InstantIO::Matrix4< T >::det | ( | ) | const [inline] |
Returns the determinat of the whole 4x4 matrix.
bool InstantIO::Matrix4< T >::getInverse | ( | Matrix4< T > & | result | ) | const [inline] |
Stores the inverse of the matrix into result.
result | Gets filled with the inverse of this matrix. |
bool InstantIO::Matrix4< T >::sqrt | ( | ) | [inline] |
Sets this matrix to its square root, assumes det > 0.
Source taken from OSGMatrix.
void InstantIO::Matrix4< T >::setExpOf | ( | const Matrix4< T > & | m | ) | [inline] |
Sets this matrix to the exponential of the given matrix.
Source taken from OSGMatrix.
m | The given matrix. |
bool InstantIO::Matrix4< T >::setLogOf | ( | const Matrix4< T > & | matrix | ) | [inline] |
Sets this Matrix4 to the logarithm of the given matrix, assumes det > 0.
matrix | The given matrix. |
void InstantIO::Matrix4< T >::print | ( | std::ostream & | target | ) | [inline] |
Prints the matrix to an output stream.
target | The output stream. |