![]() |
Scanframe Modular Application 0.1.0
|
Generic 4 x 4 matrix template. More...
#include <TMatrix44.h>
Classes | |
union | data_type |
Storage union of the 4x4 matrix as array and 4 x4 array. It is initialized as a unit-matrix. More... | |
Public Types | |
enum | EAxis : unsigned int { axisX = 0 , axisY = 1 , axisZ = 2 , axisT = 3 } |
Enumerate for identifying a matrix axis. More... | |
typedef T | value_type |
Type accessible when implemented. | |
Public Member Functions | |
TMatrix44 ()=default | |
Default constructor which is by default a unit-matrix. | |
TMatrix44 (T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33) | |
Initialization constructor for 16 single floating point values. | |
TMatrix44 (std::initializer_list< T[4]> list) | |
Constructor using an initializer list. | |
TMatrix44 (const T[4][4]) | |
Initialization constructor for 4x4 floating point values. | |
TMatrix44 (const T *) | |
Initialization constructor for 16 floating point values. | |
TMatrix44 (const TVector3D< T > &tv) | |
Construct from a translation vector. Construct a translation transformation from a given 3D Vector. | |
TMatrix44 (T tilt, T pan, T roll) | |
Construct from rotations. | |
TMatrix44 (const TQuaternion< T > &q) | |
Construct from quaternion rotation. | |
TMatrix44 (const TMatrix44 &) | |
Copy constructor. | |
TMatrix44 (TMatrix44 &&) noexcept | |
Move constructor. | |
TMatrix44 & | unit () |
Set or resets this instance as unit/identity matrix. A unit matrix, also known as the identity matrix, is a square matrix in which all the elements along the main diagonal (from the top-left to the bottom-right) are 1, and all other elements are 0. It acts as the multiplicative identity in matrix algebra, meaning that multiplying any matrix by the identity matrix results in the original matrix itself. | |
T | determinant () const |
Gets the 3x3 determinant from this instance. | |
TMatrix44 & | invert () |
Inverts this matrix. | |
TMatrix44 | inverse () const |
Gets the inverted version of this instance. Call the method invert() to do this. | |
TMatrix44 | transposed () const |
Get a transposed matrix of this instance. | |
TMatrix44 & | transpose () |
Transpose this matrix. | |
TMatrix44 & | assign (const T[4][4]) |
Assigns the 4x4 array structure to this matrix. | |
TMatrix44 & | assign (const T *) |
Assigns the 16 values from pointer to this matrix. | |
TMatrix44 & | transposeAssign (const T[4][4]) |
Assigns the transposed 4x4 array structure to this matrix. | |
TMatrix44 & | operator= (const TMatrix44 &) |
Assignment operator. | |
TMatrix44 & | operator= (TMatrix44 &&m) noexcept |
Assignment move operator. | |
TMatrix44 & | operator*= (const TMatrix44 &) |
Applies passed matrix on the axes of this matrix. | |
TVector3D< T > | operator* (const TVector3D< T > &) const |
Applies matrix on the passed 3D vector. | |
value_type * | data () |
Gets the pointer to the array of this matrix. | |
const value_type * | data () const |
Gets the pointer to the array of this matrix. | |
operator T* () | |
Cast operator to pointer of type 'T'. | |
operator const T * () const | |
Cast operator to pointer of type 'T'. | |
bool | isEqual (const TMatrix44 &m, T tol=tolerance) const |
Compares the passed matrix within the set tolerance. | |
bool | isRotational () const |
Determines if the matrix is a rotation matrix. | |
bool | operator== (const TMatrix44 &) const |
Compare equal operator using the tolerance when comparing. | |
bool | operator!= (const TMatrix44 &) const |
Compare unequal operator using the tolerance when comparing. | |
void | copyTo (T[4][4]) const |
Copies the matrix to a 4x4 array. | |
void | copyTo (T *) const |
Copies the matrix to a 16 deep array. | |
void | transposeCopyTo (T[4][4]) const |
Transposed copy to a 4x4 array for compatibility with OpenGL. | |
TMatrix44 & | setTiltPanRoll (T tilt, T pan, T roll) |
Sets/resets rotation part of the matrix according to tilt pan roll and does not touch the translation or scaling part. | |
void | getTiltPanRoll (T &tilt, T &pan, T &roll) const |
Translates rotation part of matrix to tilt, pan and roll values. | |
TMatrix44 & | rotate (T angle, const TVector3D< T > &vec, bool only=true) |
Applies rotation on the current matrix around a vector. | |
TMatrix44 & | rotate (T angle, T x, T y, T z, bool only=true) |
Applies rotation on the current matrix. | |
TMatrix44 | rotated (T angle, T x, T y, T z, bool only=true) const |
Same as rotate() but only returns the changed matrix and does not affect this matrix. | |
TMatrix44 | rotated (T angle, const TVector3D< T > &vec, bool only=true) const |
Same as rotate() but only returns the changed matrix and does not affect this matrix. | |
void | setPerspectiveProjection (T near_plane, T far_plane, T fov) |
Sets the projection for this matrix. | |
TMatrix44 & | multiply (const TMatrix44 &m) |
Multiplies this matrix with the passed one so that the given matrix is applied on the matrix axes. | |
TMatrix44 | multiplied (const TMatrix44 &m) const |
Same as multiply() but returns the changed matrix and does not affect this matrix. | |
TMatrix44 & | rotate (const TMatrix44 &m) |
Multiplies this matrix only with the 3x3 part of the given matrix applying only rotation and scaling. | |
TMatrix44 | rotated (const TMatrix44 &m) const |
Same as rotate() but returns the changed matrix and does not affect this matrix. | |
TVector3D< T > | transformed (const TVector3D< T > &v) const |
Applies the matrix rotation up on a 3D-vector. | |
void | clearTranslation () |
Zero's or clears translation part of this instance. | |
TMatrix44 & | translate (const TVector3D< T > &v) |
Adds a translation vector of this instance using a 3D vector. | |
TMatrix44 & | translate (T x, T y, T z) |
Adds the translation vector of this instance using individual. | |
TMatrix44 | translated (const TVector3D< T > &v) const |
Same as translate() but does not change this matrix only returns the translated one. | |
TMatrix44 | translated (T x, T y, T z) const |
Same as translate() but does not change this matrix only returns the translated one. | |
TVector3D< T > | getTranslation () const |
Gets translation part of matrix. | |
TMatrix44 | setTranslation (const TVector3D< T > &v) |
Sets translation part of this matrix. | |
TVector3D< T > | getAxis (EAxis axis) const |
Gets given axis of matrix as a 3D vector. | |
TMatrix44 | orbit (T horizontal, T vertical) const |
Gets transformation of rotation around local x- and y-axis of current matrix. | |
TMatrix44 | orientation () const |
Gets the orientation part of matrix. | |
void | setElement (unsigned int column, unsigned int row, T value) |
Sets the element specified by the row and column. | |
T | element (unsigned int column, unsigned int row) const |
Gets the element specified by the row and column. | |
T & | element (unsigned int column, unsigned int row) |
Gets the element reference specified by the row and column. | |
T & | operator() (int row, int column) |
Function operator for row column value manipulations. This is different from the element() method. | |
T | operator() (int row, int column) const |
Gets the element from row and column index. This is different from the element() method. | |
template<typename R > | |
void | toOpenGL (R *matrix) const |
Copies this matrix to a column-major matrix array compatible with OpenGL standard. A one on one copy is not possible and a transpose of the 3x3 matrix part within is needed. | |
template<typename R > | |
std::array< R, 16 > | toOpenGL () const |
Gets a column-major matrix array buffer compatible with OpenGL standard. Essentially converts from a row-major to column-major and OpenGL compatible matrix. Useful when calling OpenGL functions glLoadMatrix[fd]() and glMultMatrix[fd](). | |
template<typename R > | |
TMatrix44 & | assignOpenGL (const R *matrix) |
Assigns a row-major matrix array compatible with OpenGL standard to this instance. A one on one copy is not possible and a transpose of the 3x3 matrix part within is needed. Essentially converts from a OpenGL column-major to this row-major matrix. | |
TQuaternion< T > | quaternion () const |
Convert rotation matrix part to identity or unit quaternion. Calls sf::TQuaternion::fromMatrix() | |
TMatrix44 & | resetOrientation () |
Resets the orientation and leaves the translation as is. | |
TMatrix44 & | setOrientationXY (const TVector3D< T > &x_axis, const TVector3D< T > &y_axis) |
Set orientation using 2 direction vectors. y-axis direction dominates x-axis (x-axis is corrected if x-axis and y-axis not perpendicular) | |
TMatrix44 & | setOrientationZY (const TVector3D< T > &z_axis, const TVector3D< T > &y_axis) |
Set orientation using 2 direction vectors. The z-axis direction dominates y-axis (y-axis is corrected if y & z not perpendicular) | |
TMatrix44 & | insertGIGRotXYZ (T rx, T ry, T rz) |
Another way of applying rotation to the matrix. | |
std::string | toString () const |
Gets the string representation of the matrix formed like '({m00,m01,m02,m03},{m10,m11,m12,m13},{m20,m21,m22,m23},{m30,m31,m32,m33})'. | |
TMatrix44 & | fromString (const std::string &s) noexcept(false) |
Gets matrix values from the string representation formed like '({1,2,3,4},{11,12,13,14},{21,22,23,24},{31,32,33,34})'. Throws an exception when the string is not in the correct format. | |
Static Public Member Functions | |
template<typename R > | |
static TMatrix44 | fromOpenGL (const R *matrix) |
Creates a instance from a row-major matrix array compatible with OpenGL standard. Essentially converts from a OpenGL column-major to this row-major matrix. | |
Static Public Attributes | |
static constexpr auto | tolerance = TVector3D<T>::tolerance |
Tolerance for when comparing in the equal operator. | |
Protected Attributes | |
union sf::TMatrix44::data_type | _data = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1} |
Generic 4 x 4 matrix template.
typedef T sf::TMatrix44< T >::value_type |
Type accessible when implemented.
enum sf::TMatrix44::EAxis : unsigned int |
|
default |
Default constructor which is by default a unit-matrix.
sf::TMatrix44< T >::TMatrix44 | ( | T | m00, |
T | m01, | ||
T | m02, | ||
T | m03, | ||
T | m10, | ||
T | m11, | ||
T | m12, | ||
T | m13, | ||
T | m20, | ||
T | m21, | ||
T | m22, | ||
T | m23, | ||
T | m30, | ||
T | m31, | ||
T | m32, | ||
T | m33 | ||
) |
Initialization constructor for 16 single floating point values.
sf::TMatrix44< T >::TMatrix44 | ( | std::initializer_list< T[4]> | list | ) |
Constructor using an initializer list.
|
explicit |
Initialization constructor for 4x4 floating point values.
|
explicit |
Initialization constructor for 16 floating point values.
|
explicit |
Construct from a translation vector. Construct a translation transformation from a given 3D Vector.
sf::TMatrix44< T >::TMatrix44 | ( | T | tilt, |
T | pan, | ||
T | roll | ||
) |
Construct from rotations.
|
explicit |
Construct from quaternion rotation.
sf::TMatrix44< T >::TMatrix44 | ( | const TMatrix44< T > & | ) |
Copy constructor.
|
noexcept |
Move constructor.
TMatrix44 & sf::TMatrix44< T >::assign | ( | const T * | ) |
Assigns the 16 values from pointer to this matrix.
TMatrix44 & sf::TMatrix44< T >::assign | ( | const T | [4][4] | ) |
Assigns the 4x4 array structure to this matrix.
TMatrix44 & sf::TMatrix44< T >::assignOpenGL | ( | const R * | matrix | ) |
Assigns a row-major matrix array compatible with OpenGL standard to this instance. A one on one copy is not possible and a transpose of the 3x3 matrix part within is needed. Essentially converts from a OpenGL column-major to this row-major matrix.
R | Type of the array pointer. |
void sf::TMatrix44< T >::clearTranslation | ( | ) |
Zero's or clears translation part of this instance.
void sf::TMatrix44< T >::copyTo | ( | T * | ) | const |
Copies the matrix to a 16 deep array.
void sf::TMatrix44< T >::copyTo | ( | T | [4][4] | ) | const |
Copies the matrix to a 4x4 array.
value_type * sf::TMatrix44< T >::data | ( | ) |
Gets the pointer to the array of this matrix.
const value_type * sf::TMatrix44< T >::data | ( | ) | const |
Gets the pointer to the array of this matrix.
T sf::TMatrix44< T >::determinant | ( | ) | const |
Gets the 3x3 determinant from this instance.
T & sf::TMatrix44< T >::element | ( | unsigned int | column, |
unsigned int | row | ||
) |
Gets the element reference specified by the row and column.
column | Row number between 0 and 3. |
row | Column number between 0 and 3. |
T sf::TMatrix44< T >::element | ( | unsigned int | column, |
unsigned int | row | ||
) | const |
Gets the element specified by the row and column.
column | Row number between 0 and 3. |
row | Column number between 0 and 3. |
|
static |
Creates a instance from a row-major matrix array compatible with OpenGL standard. Essentially converts from a OpenGL column-major to this row-major matrix.
R | Type of the array pointer. |
matrix | Array pointer expected to be at least of 16 length. |
TMatrix44 & sf::TMatrix44< T >::fromString | ( | const std::string & | s | ) |
Gets matrix values from the string representation formed like '({1,2,3,4},{11,12,13,14},{21,22,23,24},{31,32,33,34})'. Throws an exception when the string is not in the correct format.
std::invalid_argument |
TVector3D< T > sf::TMatrix44< T >::getAxis | ( | EAxis | axis | ) | const |
Gets given axis of matrix as a 3D vector.
axis | Requested axis. |
void sf::TMatrix44< T >::getTiltPanRoll | ( | T & | tilt, |
T & | pan, | ||
T & | roll | ||
) | const |
Translates rotation part of matrix to tilt, pan and roll values.
tilt | Tilt angle in radians. |
pan | Pan angle in radians. |
roll | Roll angle in radians. |
TVector3D< T > sf::TMatrix44< T >::getTranslation | ( | ) | const |
Gets translation part of matrix.
TMatrix44 & sf::TMatrix44< T >::insertGIGRotXYZ | ( | T | rx, |
T | ry, | ||
T | rz | ||
) |
Another way of applying rotation to the matrix.
rx | X in Radians. |
ry | Y in Radians |
rz | Z in Radians. |
TMatrix44 sf::TMatrix44< T >::inverse | ( | ) | const |
TMatrix44 & sf::TMatrix44< T >::invert | ( | ) |
Inverts this matrix.
std::range_error |
bool sf::TMatrix44< T >::isEqual | ( | const TMatrix44< T > & | m, |
T | tol = tolerance |
||
) | const |
Compares the passed matrix within the set tolerance.
m | Matrix to compare with. |
tol | The tolerance when comparing which has a default. |
bool sf::TMatrix44< T >::isRotational | ( | ) | const |
Determines if the matrix is a rotation matrix.
TMatrix44 sf::TMatrix44< T >::multiplied | ( | const TMatrix44< T > & | m | ) | const |
Same as multiply() but returns the changed matrix and does not affect this matrix.
TMatrix44 & sf::TMatrix44< T >::multiply | ( | const TMatrix44< T > & | m | ) |
Multiplies this matrix with the passed one so that the given matrix is applied on the matrix axes.
sf::TMatrix44< T >::operator const T * | ( | ) | const |
Cast operator to pointer of type 'T'.
sf::TMatrix44< T >::operator T* | ( | ) |
Cast operator to pointer of type 'T'.
bool sf::TMatrix44< T >::operator!= | ( | const TMatrix44< T > & | ) | const |
Compare unequal operator using the tolerance when comparing.
T & sf::TMatrix44< T >::operator() | ( | int | row, |
int | column | ||
) |
Function operator for row column value manipulations. This is different from the element() method.
row | Row index. |
column | Column index. |
T sf::TMatrix44< T >::operator() | ( | int | row, |
int | column | ||
) | const |
TVector3D< T > sf::TMatrix44< T >::operator* | ( | const TVector3D< T > & | ) | const |
Applies matrix on the passed 3D vector.
TMatrix44 & sf::TMatrix44< T >::operator*= | ( | const TMatrix44< T > & | ) |
Applies passed matrix on the axes of this matrix.
TMatrix44 & sf::TMatrix44< T >::operator= | ( | const TMatrix44< T > & | ) |
Assignment operator.
|
noexcept |
Assignment move operator.
bool sf::TMatrix44< T >::operator== | ( | const TMatrix44< T > & | ) | const |
Compare equal operator using the tolerance when comparing.
TMatrix44 sf::TMatrix44< T >::orbit | ( | T | horizontal, |
T | vertical | ||
) | const |
Gets transformation of rotation around local x- and y-axis of current matrix.
horizontal | |
vertical |
TMatrix44 sf::TMatrix44< T >::orientation | ( | ) | const |
Gets the orientation part of matrix.
TQuaternion< T > sf::TMatrix44< T >::quaternion | ( | ) | const |
Convert rotation matrix part to identity or unit quaternion. Calls sf::TQuaternion::fromMatrix()
TMatrix44 & sf::TMatrix44< T >::resetOrientation | ( | ) |
Resets the orientation and leaves the translation as is.
TMatrix44 & sf::TMatrix44< T >::rotate | ( | const TMatrix44< T > & | m | ) |
Multiplies this matrix only with the 3x3 part of the given matrix applying only rotation and scaling.
TMatrix44 & sf::TMatrix44< T >::rotate | ( | T | angle, |
const TVector3D< T > & | vec, | ||
bool | only = true |
||
) |
Applies rotation on the current matrix around a vector.
angle | Angle f rotation in radians. |
vec | Vector to rotating around. |
only | When true it only rotates and leaves the translation untouched. |
TMatrix44 & sf::TMatrix44< T >::rotate | ( | T | angle, |
T | x, | ||
T | y, | ||
T | z, | ||
bool | only = true |
||
) |
Applies rotation on the current matrix.
angle | Angle of rotation in radians. |
x | Rotation around the horizontal (x-axis). |
y | Rotation around the vertical (y-axis). |
z | Rotation around the forward (z-axis). |
only | When true it only rotates and leaves the translation untouched. |
TMatrix44 sf::TMatrix44< T >::rotated | ( | const TMatrix44< T > & | m | ) | const |
Same as rotate() but returns the changed matrix and does not affect this matrix.
TMatrix44 sf::TMatrix44< T >::rotated | ( | T | angle, |
const TVector3D< T > & | vec, | ||
bool | only = true |
||
) | const |
Same as rotate() but only returns the changed matrix and does not affect this matrix.
angle | Angle of rotation. |
vec | Vector to rotating around. |
only | When true it only rotates and leaves the translation untouched. |
TMatrix44 sf::TMatrix44< T >::rotated | ( | T | angle, |
T | x, | ||
T | y, | ||
T | z, | ||
bool | only = true |
||
) | const |
Same as rotate() but only returns the changed matrix and does not affect this matrix.
angle | Angle of rotation. |
x | Rotation around the horizontal (x-axis). |
y | Rotation around the vertical (y-axis). |
z | Rotation around the forward (z-axis). |
only | When true it only rotates and leaves the translation untouched. |
void sf::TMatrix44< T >::setElement | ( | unsigned int | column, |
unsigned int | row, | ||
T | value | ||
) |
Sets the element specified by the row and column.
column | Row number between 0 and 3. |
row | Column number between 0 and 3. |
value | Element value. |
TMatrix44 & sf::TMatrix44< T >::setOrientationXY | ( | const TVector3D< T > & | x_axis, |
const TVector3D< T > & | y_axis | ||
) |
Set orientation using 2 direction vectors. y-axis direction dominates x-axis (x-axis is corrected if x-axis and y-axis not perpendicular)
x_axis | |
y_axis |
std::invalid_argument |
TMatrix44 & sf::TMatrix44< T >::setOrientationZY | ( | const TVector3D< T > & | z_axis, |
const TVector3D< T > & | y_axis | ||
) |
Set orientation using 2 direction vectors. The z-axis direction dominates y-axis (y-axis is corrected if y & z not perpendicular)
z_axis | |
y_axis |
std::invalid_argument |
void sf::TMatrix44< T >::setPerspectiveProjection | ( | T | near_plane, |
T | far_plane, | ||
T | fov | ||
) |
Sets the projection for this matrix.
near_plane | Near plane of the camera frustum. |
far_plane | Far plane of the camera frustum. |
fov | Field of view in radians. |
TMatrix44 & sf::TMatrix44< T >::setTiltPanRoll | ( | T | tilt, |
T | pan, | ||
T | roll | ||
) |
Sets/resets rotation part of the matrix according to tilt pan roll and does not touch the translation or scaling part.
tilt | Tilt is a rotation around the horizontal (x-axis). |
pan | Pan is a rotation around the vertical (y-axis). |
roll | Roll is a rotation around the forward (z-axis). |
TMatrix44 sf::TMatrix44< T >::setTranslation | ( | const TVector3D< T > & | v | ) |
Sets translation part of this matrix.
std::array< R, 16 > sf::TMatrix44< T >::toOpenGL | ( | ) | const |
Gets a column-major matrix array buffer compatible with OpenGL standard. Essentially converts from a row-major to column-major and OpenGL compatible matrix. Useful when calling OpenGL functions glLoadMatrix[fd]() and glMultMatrix[fd]().
R | Type of the array. |
Copies this matrix to a column-major matrix array compatible with OpenGL standard. A one on one copy is not possible and a transpose of the 3x3 matrix part within is needed.
R | Type of the pointer. |
matrix | Array pointer expected to be at least of 16 length. |
std::string sf::TMatrix44< T >::toString | ( | ) | const |
Gets the string representation of the matrix formed like '({m00,m01,m02,m03},{m10,m11,m12,m13},{m20,m21,m22,m23},{m30,m31,m32,m33})'.
TVector3D< T > sf::TMatrix44< T >::transformed | ( | const TVector3D< T > & | v | ) | const |
Applies the matrix rotation up on a 3D-vector.
v | 3D vector. |
TMatrix44 & sf::TMatrix44< T >::translate | ( | const TVector3D< T > & | v | ) |
Adds a translation vector of this instance using a 3D vector.
TMatrix44 & sf::TMatrix44< T >::translate | ( | T | x, |
T | y, | ||
T | z | ||
) |
Adds the translation vector of this instance using individual.
TMatrix44 sf::TMatrix44< T >::translated | ( | const TVector3D< T > & | v | ) | const |
Same as translate() but does not change this matrix only returns the translated one.
TMatrix44 sf::TMatrix44< T >::translated | ( | T | x, |
T | y, | ||
T | z | ||
) | const |
Same as translate() but does not change this matrix only returns the translated one.
TMatrix44 & sf::TMatrix44< T >::transpose | ( | ) |
Transpose this matrix.
TMatrix44 & sf::TMatrix44< T >::transposeAssign | ( | const T | [4][4] | ) |
Assigns the transposed 4x4 array structure to this matrix.
void sf::TMatrix44< T >::transposeCopyTo | ( | T | [4][4] | ) | const |
Transposed copy to a 4x4 array for compatibility with OpenGL.
TMatrix44 sf::TMatrix44< T >::transposed | ( | ) | const |
Get a transposed matrix of this instance.
TMatrix44 & sf::TMatrix44< T >::unit | ( | ) |
Set or resets this instance as unit/identity matrix. A unit matrix, also known as the identity matrix, is a square matrix in which all the elements along the main diagonal (from the top-left to the bottom-right) are 1, and all other elements are 0. It acts as the multiplicative identity in matrix algebra, meaning that multiplying any matrix by the identity matrix results in the original matrix itself.
|
protected |
|
staticconstexpr |
Tolerance for when comparing in the equal operator.
Used as: std::fabs(x1 - x2) < tolerance