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