Merge branch 'mat-devel'
[ProjetInfo.git] / math / inc / sqmatrix3.h
blob3ab46d7375344a848b0df5823cfd544595a30f73
1 #ifndef SQMATRIX3_H
2 #define SQMATRIX3_H
4 #include <iostream>
5 #include <iomanip>
6 #include <cmath>
7 #include <vector>
8 #include <exception>
9 #include <stdexcept>
11 #include "vector3.h"
13 class SqMatrix3;
14 SqMatrix3 operator* (double scalar, const SqMatrix3 &other);
15 std::ostream& operator<< (std::ostream &out, const SqMatrix3 &matrix);
17 class SqMatrix3
19 public:
21 enum MatType
23 Mat_Null, // the 0 matrix
24 Mat_Identity
27 SqMatrix3 (MatType type = Mat_Identity); // the identity I3 or the null matrix
28 SqMatrix3 (const SqMatrix3 &other);
29 SqMatrix3 (const Vector3 &col1, const Vector3 &col2, const Vector3 &col3);
30 virtual ~SqMatrix3 ();
32 SqMatrix3& operator= (const SqMatrix3 &other);
34 // addition/substraction operators
35 SqMatrix3 operator+ (const SqMatrix3 &other) const;
36 SqMatrix3& operator+= (const SqMatrix3 &other);
37 SqMatrix3 operator- (const SqMatrix3 &other) const;
38 SqMatrix3& operator-= (const SqMatrix3 &other);
40 // multiplication operators
41 SqMatrix3 operator* (const SqMatrix3 &other) const;
42 SqMatrix3& operator*= (const SqMatrix3 &other);
43 SqMatrix3 operator* (double scalar) const;
44 SqMatrix3& operator*= (double scalar);
45 friend SqMatrix3 operator* (double scalar, const SqMatrix3 &other);
46 Vector3 operator* (const Vector3& vector) const;
48 // comparison operator
49 bool operator== (const SqMatrix3 &other) const;
50 bool operator!= (const SqMatrix3 &other) const;
52 // transpose matrix
53 SqMatrix3 transpose() const;
54 SqMatrix3& setToTransposed();
56 // determinant, inverse
57 double determinant() const;
58 double det() const; // this is an alias
60 SqMatrix3 inverse() const;
61 SqMatrix3& setToInverse();
63 // index operators
64 // math-like setter/getter
65 double& operator() (unsigned int row, unsigned int col);
66 double operator() (unsigned int row, unsigned int col) const;
67 // C++ like setter/getter : indexes start at 0
68 double& at (unsigned int row, unsigned int col);
69 double at (unsigned int row, unsigned int col) const;
71 // show matrix using cout by default
72 void show(std::ostream &out = std::cout) const;
74 private:
75 void _setCols (const Vector3 *cols); // call only from another SqMatrix3 : cols is intended to be a 3-dim array
77 protected:
78 Vector3 *m_cols;
79 static const unsigned int m_SIZE = 3; // size of the column vectors representing the matrix
82 #endif //SQMATRIX3_H