Artec 3D Scanning SDK  2.0
Matrix.h
Go to the documentation of this file.
1 /********************************************************************
2  *
3  * Project Artec 3D Scanning SDK
4  *
5  * Purpose: Definition of template matrix classes to use in
6  * geometric transformations
7  *
8  * Copyright: Artec Group
9  *
10  ********************************************************************/
11 
12 #ifndef _MATRIX_H_
13 #define _MATRIX_H_
14 
16 
17 namespace artec { namespace sdk { namespace base
18 {
19 
20 // Suppress 'nameless struct/union' warning
21 #pragma warning(push)
22 #pragma warning(disable: 4201)
23 
24 template< typename Type = double >
25 /// Transformation matrix
26 class Matrix4x4
27 {
28 public:
29  typedef Type value_type;
30 
31  Matrix4x4(){ }
32 
33  Matrix4x4(Type _00, Type _01, Type _02, Type _03,
34  Type _10, Type _11, Type _12, Type _13,
35  Type _20, Type _21, Type _22, Type _23,
36  Type _30, Type _31, Type _32, Type _33)
37  {
38  m[0][0] = _00; m[0][1] = _01; m[0][2] = _02; m[0][3] = _03;
39  m[1][0] = _10; m[1][1] = _11; m[1][2] = _12; m[1][3] = _13;
40  m[2][0] = _20; m[2][1] = _21; m[2][2] = _22; m[2][3] = _23;
41  m[3][0] = _30; m[3][1] = _31; m[3][2] = _32; m[3][3] = _33;
42  }
43 
44  template< typename Type2, std::size_t sizeOfArray >
45  explicit Matrix4x4(const Type2 (&values)[sizeOfArray])
46  {
47  int c_assert[size_ == sizeOfArray ? 1 : -1];
48  (c_assert);
49  for(int i = 0; i < size_; i++)
50  data[i] = values[i];
51  }
52 
53  template <typename It>
54  Matrix4x4(It begin, It end)
55  {
56  int i = 0;
57  for(; i < size() && begin != end; ++begin, ++i)
58  {
59  data[i] = *begin;
60  }
61  if(i < size() - 1)
62  {
63  for(; i < size(); ++i)
64  {
65  data[i] = Type();
66  }
67  }
68  }
69 
70  template< typename Type2 >
71  Matrix4x4(const Type2 * values, int rows2, int cols2)
72  {
73  for (int matrixRow = 0; matrixRow < rows_; ++matrixRow) {
74  for (int matrixCol = 0; matrixCol < cols_; ++matrixCol) {
75  if (matrixCol < cols2 && matrixRow < rows2)
76  m[matrixRow][matrixCol] = values[matrixRow * cols2 + matrixCol];
77  else if (matrixCol == matrixRow)
78  m[matrixRow][matrixCol] = Type(1);
79  else
80  m[matrixRow][matrixCol] = Type(0);
81  }
82  }
83  }
84 
85  /// Copying constructor
86  Matrix4x4(const Matrix4x4 & second) { *this = second; }
87 
88  /// Copying constructor with the size_ conversion
89  template< int rows2, int cols2, typename Type2 >
90  explicit Matrix4x4(const GenericMatrix< rows2, cols2, Type2 > & second) { *this = second; }
91 
92  /// Copying constructor with the type conversion
93  template< typename Type2 >
94  explicit Matrix4x4(const Matrix4x4< Type2 > & second)
95  {
96  for(int i = 0; i < size_; i++) data[i] = static_cast<Type>(second[i]);
97  }
98 
99  ///@{
100  /// Assignment operators
101  template< int rows2, int cols2, typename Type2 >
103  {
104  for (int matrixRow = 0; matrixRow < rows_; ++matrixRow) {
105  for (int matrixCol = 0; matrixCol < cols_; ++matrixCol) {
106  if (matrixCol < cols2 && matrixRow < rows2)
107  m[matrixRow][matrixCol] = second.m[matrixRow][matrixCol];
108  else if (matrixCol == matrixRow)
109  m[matrixRow][matrixCol] = Type(1);
110  else
111  m[matrixRow][matrixCol] = Type(0);
112  }
113  }
114  return *this;
115  }
116 
117  Matrix4x4 & operator=(const Matrix4x4 & second)
118  {
119  memcpy(data, second.data, size_*sizeof(Type));
120  return *this;
121  }
122  ///@}
123 
124  ///@{
125  /// Convert matrix4x4 to generic matrix
126  template <int rows, int cols>
128  {
129  return toGenericMatrix<rows, cols, Type>();
130  }
131 
132  template <int rows, int cols, typename Type2>
134  {
136  for (int matrixRow = 0; matrixRow < rows; ++matrixRow) {
137  for (int matrixCol = 0; matrixCol < cols; ++matrixCol) {
138  if (matrixRow < 4 && matrixCol < 4)
139  result.m[matrixRow][matrixCol] = m[matrixRow][matrixCol];
140  else if (matrixCol == matrixRow)
141  result.m[matrixRow][matrixCol] = Type2(1);
142  else
143  result.m[matrixRow][matrixCol] = Type2(0);
144  }
145  }
146  return result;
147  }
148  ///@}
149 
150  /// Fill in the matrix with value
151  void fill(const Type value)
152  {
153  for(int i = 0; i < size_; i++)
154  data[i] = value;
155  }
156 
157  ///@{
158  /// Arithmetical operations
159  /// Matrix-Matrix (element-wise)
161  {
162  for(int i = 0; i < size_; i++) data[i] += mat.data[i];
163  return *this;
164  }
166  {
167  for(int i = 0; i < size_; i++) data[i] -= mat.data[i];
168  return *this;
169  }
170  Matrix4x4 & operator*=(const Matrix4x4 & other)
171  {
172  *this = *this * other;
173  return *this;
174  }
175 
176  Matrix4x4 operator+(const Matrix4x4 & mat) const
177  {
178  Matrix4x4 m = *this;
179  for(int i = 0; i < size_; i++) m.data[i] = m.data[i] + mat.data[i];
180  return m;
181  }
182 
183  Matrix4x4 operator-(const Matrix4x4 & mat) const
184  {
185  Matrix4x4 res = *this;
186  for(int i = 0; i < size_; i++) res.data[i] = res.data[i] - mat.data[i];
187  return res;
188  }
189  ///@}
190 
191  ///@{
192  /// Matrix-matrix multiplication
193  Matrix4x4 operator*(const Matrix4x4 & mat) const
194  {
195  Matrix4x4 res;
196  for(int i = 0; i < rows_; i++)
197  for(int j = 0; j < cols_; j++)
198  {
199  Type sum = 0;
200  for(int k = 0; k < cols_; k++)
201  sum += m[i][k]*mat.m[k][j];
202 
203  res.m[i][j] = sum;
204  }
205  return res;
206  }
207 
208  template< int cols2 >
210  {
212  for(int i = 0; i < rows_; i++)
213  for(int j = 0; j < cols2; j++)
214  {
215  Type sum = 0;
216  for(int k = 0; k < cols_; k++)
217  sum += m[i][k]*mat.m[k][j];
218 
219  res.m[i][j] = sum;
220  }
221  return res;
222  }
223  ///@}
224 
225  /// Matrix-point multiplication
226  template <typename Type2>
228  {
229  Point4<Type2> res;
230  for(int i = 0; i < 4; i++)
231  {
232  double sum = 0.0;
233  for(int j = 0; j < 4; j++)
234  sum += m[i][j]*point.data[j];
235 
236  res.data[i] = (Type2)sum;
237  }
238 
239  return res;
240  }
241 
242  /// Special case of the matrix-point multiplication: geometric transformation
243  template <typename Type2>
245  {
246  Point3< Type2 > res;
247  for(int i = 0; i < 3; i++)
248  {
249  double sum = 0.0;
250  for(int j = 0; j < 3; j++)
251  sum += m[i][j]*point.data[j];
252 
253  sum += m[i][3];
254  res.data[i] = (Type2)sum;
255  }
256 
257  return res;
258  }
259 
260  ///@{
261  /// Matrix-Scalar
262  Matrix4x4 & operator*=(const Type & val)
263  {
264  for(int i = 0; i < size_; i++) data[i] *= val;
265  return *this;
266  }
267  Matrix4x4 & operator/=(const Type & val)
268  {
269  for(int i = 0; i < size_; i++) data[i] /= val;
270  return *this;
271  }
272 
273  Matrix4x4 operator*(const Type & val) const
274  {
275  Matrix4x4 m = *this;
276  for(int i = 0; i < size_; i++) m.data[i] = m.data[i] * val;
277  return m;
278  }
279  Matrix4x4 operator/(const Type & val) const
280  {
281  Matrix4x4 m = *this;
282  for(int i = 0; i < size_; i++) m.data[i] = m.data[i] / val;
283  return m;
284  }
285  ///@}
286 
287  /// Unary minus
289  {
290  Matrix4x4 m = *this;
291  for(int i = 0; i < size_; i++) m.data[i] = -m.data[i];
292  return m;
293  }
294 
295  /// Check whether the matrices are equal
296  bool operator==(const Matrix4x4& other) const
297  {
298  for (int i = 0; i < size_; i++)
299  {
300  if (data[i] != other.data[i])
301  {
302  return false;
303  }
304  }
305  return true;
306  }
307 
308  /// Check whether the matrices are not equal
309  bool operator!=(const Matrix4x4& other) const
310  {
311  return !(*this == other);
312  }
313 
314  Type& operator()(int row, int col)
315  {
316  return m[row][col];
317  }
318 
319  const Type& operator()(int row, int col) const
320  {
321  return m[row][col];
322  }
323 
324  /// Identity matrix
326  {
327  Matrix4x4 m;
328  m.setToIdentity();
329  return m;
330  }
331  /// Turn current matrix to identity
333  {
334  for(int x = 0; x < rows_; x++)
335  for(int y = 0; y < cols_; y++)
336  {
337  m[x][y] = x != y ? Type() : Type(1.0);
338  }
339  }
340 
341  /// Check if the matrix is an identity one
342  bool isIdentity() const
343  {
344  if (m[0][0] != Type(1.0) || m[0][1] != Type() || m[0][2] != Type() || m[0][3] != Type() )
345  return false;
346 
347  if (m[1][0] != Type() || m[1][1] != Type(1.0) || m[1][2] != Type() || m[1][3] != Type() )
348  return false;
349 
350  if (m[2][0] != Type() || m[2][1] != Type() || m[2][2] != Type(1.0) || m[2][3] != Type() )
351  return false;
352 
353  if (m[3][0] != Type() || m[3][1] != Type() || m[3][2] != Type() || m[3][3] != Type(1.0) )
354  return false;
355 
356  return true;
357  }
358 
359  /// Return copy of transposed matrix
361  {
362  Matrix4x4 res;
363  for(size_t i = 0; i < rows_; i++)
364  for(size_t j = 0; j < cols_; j++)
365  res.m[i][j] = m[j][i];
366 
367  return res;
368  }
369 
370  /// Inversion
371  /// @return false if the matrix is singular and can't be inverted, otherwise the value is true
372  Matrix4x4< Type > inverted(bool *invertible = 0) const;
373 
374  Point3<Type> project(const Point3<Type> & point) const
375  {
376  Point3<Type> pr = *this * point;
377 
378  Type m4sum = 0;
379  for(size_t j = 0; j < 3; j++)
380  m4sum += m.m[3][j] * point.data[j];
381  m4sum += m.m[3][3];
382 
383  for(size_t j = 0; j < 3; j++)
384  pr.data[j] = Type(pr.data[j]/m4sum);
385 
386  return pr;
387  }
388 
389  ///@{
390  /// Rotations (* - all angles are in radians)
391  static Matrix4x4 rotationX(Type angle)
392  {
393  Matrix4x4 r;
394  r.fill(0);
395 
396  Type c = std::cos(angle);
397  Type s = std::sin(angle);
398 
399  r.m[1][1] = r.m[2][2] = c;
400  r.m[1][2] = -s; r.m[2][1] = s;
401  r.m[0][0] = r.m[3][3] = 1;
402 
403  return r;
404  }
405  static Matrix4x4 rotationY(Type angle)
406  {
407  Matrix4x4 r;
408  r.fill(0);
409 
410  Type c = std::cos(angle);
411  Type s = std::sin(angle);
412 
413  r.m[0][0] = r.m[2][2] = c;
414  r.m[0][2] = s; r.m[2][0] = -s;
415  r.m[1][1] = r.m[3][3] = 1;
416 
417  return r;
418  }
419  static Matrix4x4 rotationZ(Type angle)
420  {
421  Matrix4x4 r;
422  r.fill(0);
423 
424  Type c = std::cos(angle);
425  Type s = std::sin(angle);
426 
427  r.m[0][0] = r.m[1][1] = c;
428  r.m[0][1] = -s; r.m[1][0] = s;
429  r.m[2][2] = r.m[3][3] = 1;
430 
431  return r;
432  }
433 
434  static Matrix4x4 rotationX(Type angle, const Point3<Type> & center)
435  {
436  Matrix4x4 r = rotationX(angle);
437 
438  Point3<Type> t = -r*center+center;
439  r.m[0][3] = t.x; r.m[1][3] = t.y; r.m[2][3] = t.z;
440 
441  return r;
442  }
443  static Matrix4x4 rotationY(Type angle, const Point3<Type> & center)
444  {
445  Matrix4x4 r = rotationY(angle);
446 
447  Point3<Type> t = -r*center+center;
448  r.m[0][3] = t.x; r.m[1][3] = t.y; r.m[2][3] = t.z;
449 
450  return r;
451  }
452  static Matrix4x4 rotationZ(Type angle, const Point3<Type> & center)
453  {
454  Matrix4x4 r = rotationZ(angle);
455 
456  Point3<Type> t = -r*center+center;
457  r.m[0][3] = t.x; r.m[1][3] = t.y; r.m[2][3] = t.z;
458 
459  return r;
460  }
461  ///@}
462 
463  /// Important: Direction is a unit vector, don't forget to normalize it!
464  static Matrix4x4 rotation(Type angle, const Point3<Type> & direction)
465  {
466  Matrix4x4 r;
467 
468  Type c = std::cos(angle);
469  Type s = std::sin(angle);
470 
471  r.m[0][0] = c+(1-c)*direction.x*direction.x;
472  r.m[0][1] = (1-c)*direction.y*direction.x-s*direction.z;
473  r.m[0][2] = (1-c)*direction.z*direction.x+s*direction.y;
474 
475  r.m[1][0] = (1-c)*direction.x*direction.y+s*direction.z;
476  r.m[1][1] = c+(1-c)*direction.y*direction.y;
477  r.m[1][2] = (1-c)*direction.z*direction.y-s*direction.x;
478 
479  r.m[2][0] = (1-c)*direction.x*direction.z-s*direction.y;
480  r.m[2][1] = (1-c)*direction.y*direction.z+s*direction.x;
481  r.m[2][2] = c+(1-c)*direction.z*direction.z;
482 
483  r.m[0][3] = r.m[1][3] = r.m[2][3] = 0;
484  r.m[3][0] = r.m[3][1] = r.m[3][2] = 0; r.m[3][3] = 1;
485 
486  return r;
487  }
488 
489  /// Important: Direction is a unit vector, don't forget to normalize it!
490  static Matrix4x4 rotation(Type angle, const Point3<Type> & direction, const Point3<Type> & center)
491  {
492  Matrix4x4 r = rotation(angle, direction);
493 
494  Point3<Type> t = -r*center+center;
495  r.m[0][3] = t.x; r.m[1][3] = t.y; r.m[2][3] = t.z;
496 
497  return r;
498  }
499 
500  /// Translations
501  static Matrix4x4 translation(const Point3<Type> & direction)
502  {
503  Matrix4x4 t;
504  t.setToIdentity();
505 
506  t.m[0][3] = direction.x; t.m[1][3] = direction.y; t.m[2][3] = direction.z;
507 
508  return t;
509  }
510 
511  ///@{
512  /// Scale
513  static Matrix4x4 scale(Type factor)
514  {
515  Matrix4x4 s;
516  s.fill(Type(0.0));
517 
518  s.m[0][0] = s.m[1][1] = s.m[2][2] = factor;
519  s.m[3][3] = 1;
520 
521  return s;
522  }
523  static Matrix4x4 scale(Type factor, const Point3<Type> & center)
524  {
525  Matrix4x4 s = scale(factor);
526 
527  Point3<Type> t = -center*factor + center;
528  s.m[0][3] = t.x; s.m[1][3] = t.y; s.m[2][3] = t.z;
529 
530  return s;
531  }
532  ///@}
533 
534  /// Inverse transformation matrix
535  static Matrix4x4 inverseMotion(const Matrix4x4 &matrix)
536  {
537  /// Get rotation and translation components of motion
538  GenericMatrix<3,3,Type> r(matrix);
539  Point3<Type> t( matrix.m[0][3], matrix.m[1][3], matrix.m[2][3] );
540 
541  /// Inverse rotation
542  r = transpose(r);
543 
544  /// Assemble inverse motion matrix
545  Matrix4x4 i(r);
546  Point3<Type> it = -r*t;
547 
548  i.m[0][3] = it.x; i.m[1][3] = it.y; i.m[2][3] = it.z;
549  i.m[3][0] = i.m[3][1] = i.m[3][2] = 0; i.m[3][3] = 1;
550 
551  return i;
552  }
553 
554  /// Get perspective projection matrix
555  static Matrix4x4 perspective(Type left, Type right, Type bottom, Type top, Type nearVal, Type farVal)
556  {
557  Matrix4x4 res;
558  res.m[0][0] = 2.0f * nearVal / (right - left);
559  res.m[0][1] = 0.0;
560  res.m[0][2] = (right + left) / (right - left);
561  res.m[0][3] = 0.0;
562  res.m[1][0] = 0.0;
563  res.m[1][1] = 2.0f * nearVal / (top - bottom);
564  res.m[1][2] = (top + bottom) / (top - bottom);
565  res.m[1][3] = 0.0;
566  res.m[2][0] = 0.0;
567  res.m[2][1] = 0.0;
568  res.m[2][2] = -(farVal + nearVal) / (farVal - nearVal);
569  res.m[2][3] = -2.0f * farVal * nearVal / (farVal - nearVal);
570  res.m[3][0] = 0.0;
571  res.m[3][1] = 0.0;
572  res.m[3][2] = -1.0f;
573  res.m[3][3] = 0.0;
574  return res;
575  }
576 
577  /// Get perspective projection matrix
578  static Matrix4x4 perspectiveFov(float fovy, float aspect, float zNear, float zFar)
579  {
580  float f = 1.0f / tan(fovy * 0.5f);
581  float dneg = zNear - zFar;
582  return Matrix4x4( f / aspect, 0.0f, 0.0f, 0.0f,
583  0.0f, f, 0.0f, 0.0f,
584  0.0f, 0.0f, (zFar + zNear)/dneg, 2.0f*zNear*zFar/dneg,
585  0.0f, 0.0f, -1.0f, 0.0f );
586  }
587 
588  /// Get orthogonal matrix
589  static Matrix4x4 ortho(Type left, Type right, Type bottom, Type top, Type nearVal, Type farVal)
590  {
591  Matrix4x4 res;
592  res.m[0][0] = 2.0f / (right - left);
593  res.m[0][1] = 0.0;
594  res.m[0][2] = 0.0;
595  res.m[0][3] = -(right + left) / (right - left);
596  res.m[1][0] = 0.0;
597  res.m[1][1] = 2.0f / (top - bottom);
598  res.m[1][2] = 0.0;
599  res.m[1][3] = -(top + bottom) / (top - bottom);
600  res.m[2][0] = 0.0;
601  res.m[2][1] = 0.0;
602  res.m[2][2] = -2.0f / (farVal - nearVal);
603  res.m[2][3] = -(farVal + nearVal) / (farVal - nearVal);
604  res.m[3][0] = 0.0;
605  res.m[3][1] = 0.0;
606  res.m[3][2] = 0.0;
607  res.m[3][3] = 1.0f;
608  return res;
609  }
610 
611  ///@{
612  /// Conversion to plain data pointer operator
613  operator const Type * () const { return data; }
614  const Type * getData() const { return data; }
615  ///@}
616  /// Returns the number of elements in the matrix
617  int size() const { return size_; }
618 
619  ///@}
620  /// Plain data element access operator
621  /// Returns const reference to the element in the inner data array
622  const Type& operator [] (int index) const
623  {
624  return data[index];
625  }
626 
627  Type& operator [] (int index)
628  {
629  return data[index];
630  }
631 
632 protected:
633  /// Matrix data
634 
635  union
636  {
637  struct
638  {
639  Type m[4][4];
640  };
641 
642  Type data[4*4];
643  };
644 
645  static int const rows_;
646  static int const cols_;
647  static int const size_;
648 };
649 
650 template< typename Type > int const Matrix4x4<Type>::rows_ = 4;
651 template< typename Type > int const Matrix4x4<Type>::cols_ = 4;
652 template< typename Type > int const Matrix4x4<Type>::size_ = 4 * 4;
653 
654 template< int rows, typename Type >
656 {
658  for(int i = 0; i < rows; i++)
659  for(int j = 0; j < 4; j++)
660  {
661  Type sum = 0;
662  for(int k = 0; k < 4; k++)
663  sum += m1.m[i][k]*m2.m[k][j];
664 
665  res.m[i][j] = sum;
666  }
667  return res;
668 }
669 
670 /// Inversion
671 template< typename Type >
673 {
674  //Copy source matrix
675  Matrix4x4< Type > work = *this;
676 
677  //Build identity matrix
678  Matrix4x4< Type > result;
679  result.setToIdentity();
680 
681  const int size = 4;
682  for(int i = 0; i < size; i++)
683  {
684  int j;
685 
686  for(j = i; (j < size) && (isZero(work[j*size+i])); j++) {};
687 
688  // Matrix is singular
689  if (j == size)
690  {
691  if (invertible)
692  *invertible = false;
693  return result;
694  }
695 
696  if (i != j)
697  for(int k = 0; k < size; k++)
698  {
699  Type tmp = result[i*size+k]; result[i*size+k] = result[j*size+k]; result[j*size+k] = tmp;
700  tmp = work[i*size+k]; work[i*size+k] = work[j*size+k]; work[j*size+k] = tmp;
701  }
702 
703  Type d = 1/work[i*size+i];
704  for(j = 0; j < size; j++)
705  {
706  result[i*size+j] *= d;
707  work[i*size+j] *= d;
708  }
709 
710  for(j = i+1; j < size; j++)
711  {
712  d = work[j*size+i];
713  for(int k = 0; k < size; k++)
714  {
715  result[j*size+k] -= result[i*size+k] * d;
716  work[j*size+k] -= work[i*size+k] * d;
717  }
718  }
719  }
720 
721  for(int i = size-1; i > 0; i--)
722  for(int j = 0; j < i; j++)
723  {
724  Type d = work[j*size+i];
725  for(int k = 0; k < size; k++)
726  {
727  result[j*size+k] -= result[i*size+k] * d;
728  work[j*size+k] -= work[i*size+k] * d;
729  }
730  }
731 
732  if (invertible)
733  *invertible = true;
734  return result;
735 }
736 
737 /// Returns false if the matrix is singular and can't be inverted, otherwise returns true
738 template < typename Type > inline
739  bool invert(const Matrix4x4< Type >& matrix, Matrix4x4< Type >& result)
740 {
741  bool invertable = false;
742  result = matrix.inverted(&invertable);
743  return invertable;
744 }
745 
746 /// Inversion (another one form). The given matrix shouldn't be singular.
747 /// Throws std::runtime_error() if the matrix is singular, otherwise returns inverse matrix.
748 template < typename Type > inline
750 {
751  Matrix4x4< Type > res;
752  if (invert(matrix,res))
753  return res;
754  else
755  throw std::runtime_error("artec::sdk::base::invert: Try to invert singular matrix");
756 }
757 
758 template < typename Type > inline
760 {
761  Point3< Type > pr = (Matrix4x4< Type >)m * point;
762  return Point2< Type >(pr.x / pr.z, pr.y / pr.z);
763 }
764 
765 template < typename Type > inline
767 {
768  return m.project(point);
769 }
770 
771 // Selected matrices
778 
785 
786 #pragma warning(pop)
787 
788 } } } // namespace artec::sdk::base
789 
790 #endif //_MATRIX_H_
Point3< Type2 > operator*(const Point3< Type2 > &point) const
Special case of the matrix-point multiplication: geometric transformation.
Definition: Matrix.h:244
static Matrix4x4 perspective(Type left, Type right, Type bottom, Type top, Type nearVal, Type farVal)
Get perspective projection matrix.
Definition: Matrix.h:555
Matrix4x4(const Type2 *values, int rows2, int cols2)
Definition: Matrix.h:71
Matrix4x4 & operator/=(const Type &val)
Definition: Matrix.h:267
GenericMatrix< rows, cols, Type > toGenericMatrix() const
Definition: Matrix.h:127
Matrix4x4 & operator-=(const Matrix4x4 &mat)
Definition: Matrix.h:165
GenericMatrix< 2, 2, double > Matrix2x2D
Definition: Matrix.h:779
Matrix4x4 operator-(const Matrix4x4 &mat) const
Definition: Matrix.h:183
Matrix4x4< Type > inverted(bool *invertible=0) const
Inversion.
Definition: Matrix.h:672
static Matrix4x4 rotationX(Type angle, const Point3< Type > &center)
Definition: Matrix.h:434
Transformation matrix.
Definition: Matrix.h:26
Point3< Type2 > operator*(const GenericMatrix< 3, 3, Type > &matrix, const Point3< Type2 > &point)
static int const rows_
Definition: Matrix.h:645
static Matrix4x4 rotationZ(Type angle)
Definition: Matrix.h:419
Matrix4x4 & operator*=(const Type &val)
Definition: Matrix.h:262
static Matrix4x4 rotationY(Type angle)
Definition: Matrix.h:405
GenericMatrix< 3, 3, double > Matrix3x3D
Definition: Matrix.h:782
void setToIdentity()
Turn current matrix to identity.
Definition: Matrix.h:332
4-dimensional point class.
Definition: Point.h:26
Matrix4x4(Type _00, Type _01, Type _02, Type _03, Type _10, Type _11, Type _12, Type _13, Type _20, Type _21, Type _22, Type _23, Type _30, Type _31, Type _32, Type _33)
Definition: Matrix.h:33
GenericMatrix< 2, 3, float > Matrix2x3F
Definition: Matrix.h:773
Matrix4x4(const Type2(&values)[sizeOfArray])
Definition: Matrix.h:45
bool invert(const GenericMatrix< size, size, Type > &matrix, GenericMatrix< size, size, Type > &result)
Inversion It returns "false", if the matrix is singular and can't be inverted, otherwise the value is...
Matrix4x4 operator=(const GenericMatrix< rows2, cols2, Type2 > &second)
Definition: Matrix.h:102
Point3< Type > project(const Point3< Type > &point) const
Definition: Matrix.h:374
Matrix4x4 & operator*=(const Matrix4x4 &other)
Definition: Matrix.h:170
static Matrix4x4 scale(Type factor)
Definition: Matrix.h:513
static Matrix4x4 inverseMotion(const Matrix4x4 &matrix)
Inverse transformation matrix.
Definition: Matrix.h:535
static Matrix4x4 perspectiveFov(float fovy, float aspect, float zNear, float zFar)
Get perspective projection matrix.
Definition: Matrix.h:578
static Matrix4x4 rotationX(Type angle)
Definition: Matrix.h:391
Matrix4x4< double > Matrix4x4D
Definition: Matrix.h:784
Matrix4x4 operator*(const Type &val) const
Definition: Matrix.h:273
2-dimensional point class.
Definition: Point.h:40
bool operator!=(const Matrix4x4 &other) const
Check whether the matrices are not equal.
Definition: Matrix.h:309
static int const size_
Definition: Matrix.h:647
Matrix4x4 operator*(const Matrix4x4 &mat) const
Definition: Matrix.h:193
const Type & operator[](int index) const
Plain data element access operator Returns const reference to the element in the inner data array...
Definition: Matrix.h:622
static Matrix4x4 translation(const Point3< Type > &direction)
Translations.
Definition: Matrix.h:501
3-dimensional point class.
Definition: Point.h:25
int size() const
Returns the number of elements in the matrix.
Definition: Matrix.h:617
Matrix of unspecified size.
Definition: GenericMatrix.h:30
Matrix4x4 & operator+=(const Matrix4x4 &mat)
Definition: Matrix.h:160
void fill(const Type value)
Fill in the matrix with value.
Definition: Matrix.h:151
GenericMatrix< 2, 2, float > Matrix2x2F
Definition: Matrix.h:772
static Matrix4x4 rotationZ(Type angle, const Point3< Type > &center)
Definition: Matrix.h:452
GenericMatrix< 2, 3, double > Matrix2x3D
Definition: Matrix.h:780
Matrix4x4< float > Matrix4x4F
Definition: Matrix.h:777
bool isIdentity() const
Check if the matrix is an identity one.
Definition: Matrix.h:342
GenericMatrix< 3, 3, float > Matrix3x3F
Definition: Matrix.h:775
const Type & operator()(int row, int col) const
Definition: Matrix.h:319
Matrix4x4(const Matrix4x4 &second)
Copying constructor.
Definition: Matrix.h:86
GenericMatrix< 3, 4, float > Matrix3x4F
Definition: Matrix.h:776
Point4< Type2 > operator*(const Point4< Type2 > &point) const
Matrix-point multiplication.
Definition: Matrix.h:227
Matrix4x4 operator+(const Matrix4x4 &mat) const
Definition: Matrix.h:176
static Matrix4x4 rotation(Type angle, const Point3< Type > &direction)
Important: Direction is a unit vector, don't forget to normalize it!
Definition: Matrix.h:464
bool isZero(const Tf &some)
Equality expression for the types which are not exact.
Definition: Point.h:29
GenericMatrix< rows, cols, Type2 > toGenericMatrix() const
Definition: Matrix.h:133
Matrix4x4 transposed() const
Return copy of transposed matrix.
Definition: Matrix.h:360
static Matrix4x4 scale(Type factor, const Point3< Type > &center)
Definition: Matrix.h:523
Matrix4x4 operator-() const
Unary minus.
Definition: Matrix.h:288
static Matrix4x4 rotationY(Type angle, const Point3< Type > &center)
Definition: Matrix.h:443
const Type * getData() const
Definition: Matrix.h:614
GenericMatrix< 2, 4, float > Matrix2x4F
Definition: Matrix.h:774
Matrix4x4 & operator=(const Matrix4x4 &second)
Definition: Matrix.h:117
static int const cols_
Definition: Matrix.h:646
Point2< Type > project(const Point3< Type > &point, const GenericMatrix< 3, 4, Type > &m)
Definition: Matrix.h:759
Matrix4x4(const GenericMatrix< rows2, cols2, Type2 > &second)
Copying constructor with the size_ conversion.
Definition: Matrix.h:90
GenericMatrix< 3, 4, double > Matrix3x4D
Definition: Matrix.h:783
Matrix4x4(const Matrix4x4< Type2 > &second)
Copying constructor with the type conversion.
Definition: Matrix.h:94
static Matrix4x4 ortho(Type left, Type right, Type bottom, Type top, Type nearVal, Type farVal)
Get orthogonal matrix.
Definition: Matrix.h:589
GenericMatrix< 4, cols2, Type > operator*(const GenericMatrix< 4, cols2, Type > &mat) const
Definition: Matrix.h:209
static Matrix4x4 identity()
Identity matrix.
Definition: Matrix.h:325
Type & operator()(int row, int col)
Definition: Matrix.h:314
Matrix4x4(It begin, It end)
Definition: Matrix.h:54
bool operator==(const Matrix4x4 &other) const
Check whether the matrices are equal.
Definition: Matrix.h:296
GenericMatrix< 2, 4, double > Matrix2x4D
Definition: Matrix.h:781
static Matrix4x4 rotation(Type angle, const Point3< Type > &direction, const Point3< Type > &center)
Important: Direction is a unit vector, don't forget to normalize it!
Definition: Matrix.h:490
Matrix4x4 operator/(const Type &val) const
Definition: Matrix.h:279