Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TMatrix44.h
Go to the documentation of this file.
1
22#pragma once
23#include <math/TVector3D.h>
24#include <string>
25
26namespace sf
27{
28
29// Forward declaration.
30template<typename T>
31class TQuaternion;
32
36template<typename T>
38{
39 public:
43 typedef T value_type;
44
48 TMatrix44() = default;
49
53 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);
54
58 TMatrix44(std::initializer_list<T[4]> list);
59
63 explicit TMatrix44(const T[4][4]);
64
68 explicit TMatrix44(const T*);
69
74 explicit TMatrix44(const TVector3D<T>& tv);
75
80 TMatrix44(T tilt, T pan, T roll);
81
85 explicit TMatrix44(const TQuaternion<T>& q);
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
170 TMatrix44& operator*=(const TMatrix44&);
171
176 TVector3D<T> operator*(const TVector3D<T>&) const;
177
183
188 const value_type* data() const;
189
194 // ReSharper disable once CppNonExplicitConversionOperator
195 operator T*();
196
201 // ReSharper disable once CppNonExplicitConversionOperator
202 operator const T*() const;
203
210 bool isEqual(const TMatrix44& m, T tol = tolerance) const;
211
216 bool isRotational() const;
217
222 bool operator==(const TMatrix44&) const;
223
228 bool operator!=(const TMatrix44&) const;
229
233 void copyTo(T[4][4]) const;
234
238 void copyTo(T*) const;
239
243 void transposeCopyTo(T[4][4]) const;
244
252 TMatrix44& setTiltPanRoll(T tilt, T pan, T roll);
253
261 void getTiltPanRoll(T& tilt, T& pan, T& roll) const;
262
270 TMatrix44& rotate(T angle, const TVector3D<T>& vec, bool only = true);
271
281 TMatrix44& rotate(T angle, T x, T y, T z, bool only = true);
282
292 TMatrix44 rotated(T angle, T x, T y, T z, bool only = true) const;
293
301 TMatrix44 rotated(T angle, const TVector3D<T>& vec, bool only = true) const;
302
310 void setPerspectiveProjection(T near_plane, T far_plane, T fov);
311
317
323
329
334 TMatrix44 rotated(const TMatrix44& m) const;
335
341 TVector3D<T> transformed(const TVector3D<T>& v) const;
342
347
352
356 TMatrix44& translate(T x, T y, T z);
357
361 TMatrix44 translated(const TVector3D<T>& v) const;
362
366 TMatrix44 translated(T x, T y, T z) const;
367
373
379
384 TMatrix44& setTranslation(T x, T y, T z);
385
389 enum EAxis : unsigned int
390 {
392 axisX = 0,
394 axisY = 1,
396 axisZ = 2,
398 axisT = 3
399 };
400
407
414 TMatrix44 orbit(T horizontal, T vertical) const;
415
420
427 void setElement(unsigned int column, unsigned int row, T value);
428
435 T element(unsigned int column, unsigned int row) const;
436
443 T& element(unsigned int column, unsigned int row);
444
452 T& operator()(int row, int column);
453
461 T operator()(int row, int column) const;
462
468 template<typename R>
469 void toOpenGL(R* matrix) const;
470
478 template<typename R>
479 std::array<R, 16> toOpenGL() const;
480
488 template<typename R>
489 TMatrix44& assignOpenGL(const R* matrix);
490
498 template<typename R>
499 static TMatrix44 fromOpenGL(const R* matrix);
500
507
513
522 TMatrix44& setOrientationXY(const TVector3D<T>& x_axis, const TVector3D<T>& y_axis);
523
532 TMatrix44& setOrientationZY(const TVector3D<T>& z_axis, const TVector3D<T>& y_axis);
533
540 TMatrix44& insertGIGRotXYZ(T rx, T ry, T rz);
541
545 std::string toString() const;
546
555 TMatrix44& fromString(const std::string& s, bool ignore_err = false) noexcept(false);
556
562 static constexpr auto tolerance = TVector3D<T>::tolerance;
563
564 protected:
570 {
571 T array[4 * 4];
572 T mtx[4][4];
573 } _data = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
574};
575
583template<typename T>
585
593template<typename T>
594std::ostream& operator<<(std::ostream& os, const TMatrix44<T>& mtx);
595
603template<typename T>
604std::istream& operator>>(std::istream& is, TMatrix44<T>& mtx) noexcept(false);
605
606}// namespace sf
607
608// Include all inlined functions and template implementations.
609#include <math/TMatrix44.hpp>
Generic 4 x 4 matrix template.
Definition TMatrix44.h:38
TVector3D< T > getTranslation() const
Gets translation part of matrix.
TMatrix44 orbit(T horizontal, T vertical) const
Gets transformation of rotation around local x- and y-axis of 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.
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 & multiply(const TMatrix44 &m)
Multiplies this matrix with the passed one so that the given matrix is applied on the matrix axes.
std::string toString() const
Gets the string representation of the matrix formed like '({m00,m01,m02,m03},{m10,...
T & element(unsigned int column, unsigned int row)
Gets the element reference specified by the row and column.
T value_type
Type accessible when implemented.
Definition TMatrix44.h:43
void copyTo(T[4][4]) const
Copies the matrix to a 4x4 array.
TMatrix44 & resetOrientation()
Resets the orientation and leaves the translation as is.
TMatrix44 & unit()
Set or resets this instance as unit/identity matrix. A unit matrix, also known as the identity matrix...
void setElement(unsigned int column, unsigned int row, T value)
Sets the element specified by the row and column.
TMatrix44(T tilt, T pan, T roll)
Construct from rotations.
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.
TMatrix44 & assignOpenGL(const R *matrix)
Assigns a row-major matrix array compatible with OpenGL standard to this instance....
TMatrix44 inverse() const
Gets the inverted version of this instance. Call the method invert() to do this.
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:390
@ axisZ
Z-axis of the matrix.
Definition TMatrix44.h:396
@ axisX
X-axis of the matrix.
Definition TMatrix44.h:392
@ axisT
Translation axis of the matrix.
Definition TMatrix44.h:398
@ axisY
Y-axis of the matrix.
Definition TMatrix44.h:394
T determinant() const
Gets the 3x3 determinant from this instance.
TVector3D< T > transformed(const TVector3D< T > &v) const
Applies the matrix rotation up on a 3D-vector.
void toOpenGL(R *matrix) const
Copies this matrix to a column-major matrix array compatible with OpenGL standard....
TQuaternion< T > quaternion() const
Convert rotation matrix part to identity or unit quaternion. Calls sf::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 given axis of matrix as a 3D vector.
void transposeCopyTo(T[4][4]) const
Transposed copy to a 4x4 array for compatibility with OpenGL.
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...
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.
TMatrix44(const TVector3D< T > &tv)
Construct from a translation vector. Construct a translation transformation from a given 3D Vector.
static TMatrix44 fromOpenGL(const R *matrix)
Creates a instance from a row-major matrix array compatible with OpenGL standard. Essentially convert...
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(const TQuaternion< T > &q)
Construct from quaternion rotation.
TMatrix44 & clearTranslation()
Zero's or clears translation part of this instance.
T element(unsigned int column, unsigned int row) const
Gets the element specified by the row and column.
TMatrix44(const TMatrix44 &)
Copy constructor.
TMatrix44 & translate(const TVector3D< T > &v)
Adds a translation vector of this instance using a 3D vector.
TMatrix44 & invert()
Inverts this matrix.
TMatrix44(const T[4][4])
Initialization constructor for 4x4 floating point values.
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 ...
TMatrix44()=default
Default constructor which is by default a unit-matrix.
TMatrix44 & setTranslation(const TVector3D< T > &v)
Sets translation part of this 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(TMatrix44 &&) noexcept
Move constructor.
union sf::TMatrix44::data_type _data
static constexpr auto tolerance
Tolerance for when comparing in the equal operator.
Definition TMatrix44.h:562
TMatrix44 translated(const TVector3D< T > &v) const
Same as translate() but does not change this matrix only returns the translated one.
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.
Storage union of the 4x4 matrix as array and 4 x4 array. It is initialized as a unit-matrix.
Definition TMatrix44.h:570