////////////////////////////////////////////////////////////////////// 2x2 matrix //////////////////////////////////////////////////////////////////////
| 27 | // 2x2 matrix |
| 28 | /////////////////////////////////////////////////////////////////////////// |
| 29 | class Matrix2 |
| 30 | { |
| 31 | public: |
| 32 | // constructors |
| 33 | Matrix2(); // init with identity |
| 34 | Matrix2(const float src[4]); |
| 35 | Matrix2(float m0, float m1, float m2, float m3); |
| 36 | |
| 37 | void set(const float src[4]); |
| 38 | void set(float m0, float m1, float m2, float m3); |
| 39 | void setRow(int index, const float row[2]); |
| 40 | void setRow(int index, const Vector2& v); |
| 41 | void setColumn(int index, const float col[2]); |
| 42 | void setColumn(int index, const Vector2& v); |
| 43 | |
| 44 | const float* get() const; |
| 45 | float getDeterminant(); |
| 46 | |
| 47 | Matrix2& identity(); |
| 48 | Matrix2& transpose(); // transpose itself and return reference |
| 49 | Matrix2& invert(); |
| 50 | |
| 51 | // operators |
| 52 | Matrix2 operator+(const Matrix2& rhs) const; // add rhs |
| 53 | Matrix2 operator-(const Matrix2& rhs) const; // subtract rhs |
| 54 | Matrix2& operator+=(const Matrix2& rhs); // add rhs and update this object |
| 55 | Matrix2& operator-=(const Matrix2& rhs); // subtract rhs and update this object |
| 56 | Vector2 operator*(const Vector2& rhs) const; // multiplication: v' = M * v |
| 57 | Matrix2 operator*(const Matrix2& rhs) const; // multiplication: M3 = M1 * M2 |
| 58 | Matrix2& operator*=(const Matrix2& rhs); // multiplication: M1' = M1 * M2 |
| 59 | bool operator==(const Matrix2& rhs) const; // exact compare, no epsilon |
| 60 | bool operator!=(const Matrix2& rhs) const; // exact compare, no epsilon |
| 61 | float operator[](int index) const; // subscript operator v[0], v[1] |
| 62 | float& operator[](int index); // subscript operator v[0], v[1] |
| 63 | |
| 64 | friend Matrix2 operator-(const Matrix2& m); // unary operator (-) |
| 65 | friend Matrix2 operator*(float scalar, const Matrix2& m); // pre-multiplication |
| 66 | friend Vector2 operator*(const Vector2& vec, const Matrix2& m); // pre-multiplication |
| 67 | friend std::ostream& operator<<(std::ostream& os, const Matrix2& m); |
| 68 | |
| 69 | protected: |
| 70 | |
| 71 | private: |
| 72 | float m[4]; |
| 73 | |
| 74 | }; |
| 75 | |
| 76 | |
| 77 |