Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TMatrix44.h
Go to the documentation of this file.
1
21#pragma once
22#include <math/TVector3D.h>
23#include <string>
24
25namespace sf
26{
27
28// Forward declaration.
29template<typename T>
30class TQuaternion;
31
35template<typename T>
37{
38 public:
42 typedef T value_type;
43
47 TMatrix44() = default;
48
52 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);
53
57 TMatrix44(std::initializer_list<T[4]> list);
58
62 // ReSharper disable once CppNonExplicitConvertingConstructor
63 TMatrix44(const std::string& str);
64
68 explicit TMatrix44(const T[4][4]);
69
73 explicit TMatrix44(const T*);
74
79 explicit TMatrix44(const TVector3D<T>& v);
80
85 TMatrix44(T tilt, T pan, T roll);
86
91
95 TMatrix44(TMatrix44&&) noexcept;
96
106
111 T determinant() const;
112
118
126
132
138
143 TMatrix44& assign(const T[4][4]);
144
149 TMatrix44& assign(const T*);
150
155 TMatrix44& transposeAssign(const T[4][4]);
156
160 TMatrix44& operator=(const TMatrix44&);
164 TMatrix44& operator=(TMatrix44&& m) noexcept;
165
171 TMatrix44& operator*=(const TMatrix44&);
172
178 TVector3D<T> operator^(const TVector3D<T>&) const;
179
185 TVector3D<T> operator*(const TVector3D<T>&) const;
186
192
197 const value_type* data() const;
198
203 // ReSharper disable once CppNonExplicitConversionOperator
204 operator T*();
205
210 // ReSharper disable once CppNonExplicitConversionOperator
211 operator const T*() const;
212
219 bool isEqual(const TMatrix44& m, T tol = tolerance) const;
220
225 bool isRotational() const;
226
231 bool operator==(const TMatrix44&) const;
232
237 bool operator!=(const TMatrix44&) const;
238
242 void copyTo(T[4][4], bool column_order = false) const;
243
247 void copyTo(T*, bool column_order = false) const;
248
256 TMatrix44& setTiltPanRoll(T tilt, T pan, T roll);
257
265 void getTiltPanRoll(T& tilt, T& pan, T& roll) const;
266
274 TMatrix44& rotate(T angle, const TVector3D<T>& vec, bool only = true);
275
285 TMatrix44& rotate(T angle, T x, T y, T z, bool only = true);
286
296 TMatrix44 rotated(T angle, T x, T y, T z, bool only = true) const;
297
305 TMatrix44 rotated(T angle, const TVector3D<T>& vec, bool only = true) const;
306
314 void setPerspectiveProjection(T near_plane, T far_plane, T fov);
315
321
327
333
338 TMatrix44 rotated(const TMatrix44& m) const;
339
346 TVector3D<T> transformed(const TVector3D<T>& v, bool translate) const;
347
352
359 TMatrix44& translate(const TVector3D<T>& v, bool only = true);
360
369 TMatrix44& translate(T x, T y, T z, bool only = true);
370
377 TMatrix44 translated(const TVector3D<T>& v, bool only = true) const;
378
387 TMatrix44 translated(T x, T y, T z, bool only = true) const;
388
394
400
405 TMatrix44& setTranslation(T x, T y, T z);
406
414 TMatrix44& scale(T factor, bool translation = true);
415
425 TMatrix44& scale(T x, T y, T z, bool translation = true);
426
434 TMatrix44& scale(TVector3D<T> factor, bool translation = true);
435
439 enum EAxis : unsigned int
440 {
442 axisX = 0,
444 axisY = 1,
446 axisZ = 2,
448 axisT = 3
449 };
450
457
464 TMatrix44 orbit(T horizontal, T vertical) const;
465
470
477 void setElement(unsigned int row, unsigned int column, T value);
478
485 T element(unsigned int row, unsigned int column) const;
486
493 T& element(unsigned int row, unsigned int column);
494
502 T& operator()(int row, int column);
503
511 T operator()(int row, int column) const;
512
518 template<typename R>
519 void toOpenGL(R* matrix) const;
520
528 template<typename R>
529 std::array<R, 16> toOpenGL() const;
530
538 template<typename R>
539 TMatrix44& fromOpenGL(const R* matrix);
540
547
553
563 TMatrix44& setOrientationXY(const TVector3D<T>& x_axis, const TVector3D<T>& y_axis, bool x_dominant = false);
564
574 TMatrix44& setOrientationZY(const TVector3D<T>& z_axis, const TVector3D<T>& y_axis, bool z_dominant = false);
575
582 TMatrix44& insertGIGRotXYZ(T rx, T ry, T rz);
583
587 std::string toString(int digits = 0) const;
588
597 TMatrix44& fromString(const std::string& s, bool ignore_err = false) noexcept(false);
598
604 static constexpr auto tolerance = TVector3D<T>::tolerance;
605
606 protected:
612 {
613 T array[4 * 4];
614 T mtx[4][4];
615 } _data = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
616};
617
625template<typename T>
627
635template<typename T>
636std::ostream& operator<<(std::ostream& os, const TMatrix44<T>& mtx);
637
645template<typename T>
646std::istream& operator>>(std::istream& is, TMatrix44<T>& mtx) noexcept(false);
647
648}// namespace sf
649
650#ifndef __JETBRAINS_IDE__
651 // Include all inlined functions and template implementations.
652 #include <math/TMatrix44.hpp>
653#endif
Generic 4 x 4 matrix template.
Definition TMatrix44.h:37
TVector3D< T > getTranslation() const
Gets translation part of matrix.
TMatrix44 translated(const TVector3D< T > &v, bool only=true) const
Same as translate() but does not change this matrix only returns the translated one.
TMatrix44 orbit(T horizontal, T vertical) const
Gets transformation of rotation around the local x- and y-axis of the current matrix.
TMatrix44 & rotate(T angle, const TVector3D< T > &vec, bool only=true)
Applies rotation on the current matrix around a vector.
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...
TMatrix44 multiplied(const TMatrix44 &m) const
Same as multiply() but returns the changed matrix and does not affect this 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 & insertGIGRotXYZ(T rx, T ry, T rz)
Another way of applying rotation to the matrix.
TMatrix44 & translate(const TVector3D< T > &v, bool only=true)
Adds a translation to this instance using a 3D vector.
bool isEqual(const TMatrix44 &m, T tol=tolerance) const
Compares the passed matrix within the set tolerance.
TMatrix44 & assign(const T[4][4])
Assigns the 4x4 array structure to this matrix.
TMatrix44 transposed() const
Get a transposed matrix of this instance.
TMatrix44 & transpose()
Transpose this matrix.
TMatrix44(std::initializer_list< T[4]> list)
Constructor using an initializer list.
T & operator()(int row, int column)
Function operator for row column value manipulations. This is different from the element() method.
TMatrix44(const T *)
Initialization constructor for 16 floating point values.
TMatrix44 & fromOpenGL(const R *matrix)
Assigns a column-major matrix array compatible with the OpenGL standard. Essentially converts from an...
TMatrix44 & multiply(const TMatrix44 &m)
Multiplies this matrix with the passed one so that the given matrix is applied on the matrix axes.
T value_type
Type accessible when implemented.
Definition TMatrix44.h:42
TMatrix44(const TVector3D< T > &v)
Construct from a translation vector. Construct a translation transformation from a given 3D Vector.
TMatrix44 & resetOrientation()
Resets the orientation and leaves the translation as is.
TMatrix44 & unit()
Set or resets this instance as a unit/identity matrix. A unit matrix, also known as the identity matr...
T & element(unsigned int row, unsigned int column)
Gets the element reference specified by the row and column.
TMatrix44(T tilt, T pan, T roll)
Constructs a matrix from rotations for each axis.
value_type * data()
Gets the pointer to the array of this matrix.
TMatrix44 & transposeAssign(const T[4][4])
Assigns the transposed 4x4 array structure to this matrix.
T element(unsigned int row, unsigned int column) const
Gets the element specified by the row and column.
TVector3D< T > transformed(const TVector3D< T > &v, bool translate) const
Applies the matrix rotation up on a 3D-vector.
void copyTo(T[4][4], bool column_order=false) const
Copies the matrix to a 4x4 array in row or column order.
TMatrix44 inverse() const
Gets the inverted version of this instance. Call the method invert() to do this.
TMatrix44(const std::string &str)
Constructor using a string as function TMatrix44::fromString().
T operator()(int row, int column) const
Gets the element from row and column index. This is different from the element() method.
EAxis
Enumerate for identifying a matrix axis.
Definition TMatrix44.h:440
@ axisZ
Z-axis of the matrix.
Definition TMatrix44.h:446
@ axisX
X-axis of the matrix.
Definition TMatrix44.h:442
@ axisT
Translation axis of the matrix.
Definition TMatrix44.h:448
@ axisY
Y-axis of the matrix.
Definition TMatrix44.h:444
T determinant() const
Gets the 3x3 determinant from this instance.
void toOpenGL(R *matrix) const
Copies this matrix to a column-major matrix array compatible with OpenGL standard....
TMatrix44 & scale(T factor, bool translation=true)
Multiplies this matrix by the given factor. Leave the matrix translation vector alone.
TQuaternion< T > quaternion() const
Convert the rotation matrix part to identity/unit quaternion. Calls TQuaternion::fromMatrix()
TMatrix44 & fromString(const std::string &s, bool ignore_err=false) noexcept(false)
Gets matrix values from the string representation formed like '({1,2,3,4},{11,12,13,...
TVector3D< T > getAxis(EAxis axis) const
Gets the given axis of matrix as a 3D vector.
void setPerspectiveProjection(T near_plane, T far_plane, T fov)
Sets the projection for this matrix.
bool isRotational() const
Determines if the matrix is a rotation matrix.
std::array< R, 16 > toOpenGL() const
Gets a column-major matrix array buffer compatible with OpenGL standard. Essentially converts from a ...
void getTiltPanRoll(T &tilt, T &pan, T &roll) const
Translates rotation part of matrix to tilt, pan and roll values.
TMatrix44 & clearTranslation()
Zero's or clears translation part of this instance.
TMatrix44 & setOrientationXY(const TVector3D< T > &x_axis, const TVector3D< T > &y_axis, bool x_dominant=false)
Set orientation using two vectors X and Y which spans a surface having a dominant axis....
TMatrix44(const TMatrix44 &)
Copy constructor.
TMatrix44 & invert()
Inverts this matrix.
TMatrix44(const T[4][4])
Initialization constructor for 4x4 floating point values.
TMatrix44 & setOrientationZY(const TVector3D< T > &z_axis, const TVector3D< T > &y_axis, bool z_dominant=false)
Set orientation using two vectors Z and Y which spans a surface having a dominant axis....
TMatrix44()=default
Default constructor which is by default a unit-matrix.
TMatrix44 & setTranslation(const TVector3D< T > &v)
Sets translation part of this matrix.
std::string toString(int digits=0) const
Gets the string representation of the matrix formed like '({m00,m01,m02,m03},{m10,...
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(TMatrix44 &&) noexcept
Move constructor.
void setElement(unsigned int row, unsigned int column, T value)
Sets the element specified by the row and column.
union sf::TMatrix44::data_type _data
static constexpr auto tolerance
Tolerance for when comparing in the equal operator.
Definition TMatrix44.h:604
TMatrix44 orientation() const
Gets the orientation part of matrix.
Generic type Quaternion.
Definition TQuaternion.h:14
3-dimensional vector for math operations.
Definition TVector3D.h:17
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
TMatrix44< T > operator*(const TMatrix44< T > &lm, const TMatrix44< T > &rm)
Multiplies to matrices into a single one.
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
_MISC_FUNC int digits(double value)
Returns the amount of digits which are significant for the value. When the value is 12300....
Storage union of the 4x4 matrix as array and 4 x4 array. It is initialized as a unit-matrix.
Definition TMatrix44.h:612