Mat3.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _MAT3_H_
  2. #define _MAT3_H_
  3. #include "Common.h"
  4. #include "MathForwardDecls.h"
  5. namespace M {
  6. /// Mainly used for rotations. It includes many helpful member functions
  7. class Mat3
  8. {
  9. private:
  10. // data members
  11. union
  12. {
  13. float arr1[9];
  14. float arr2[3][3];
  15. };
  16. public:
  17. // accessors
  18. float& operator ()(const uint i, const uint j);
  19. const float& operator ()(const uint i, const uint j) const;
  20. float& operator [](const uint i);
  21. const float& operator [](const uint i) const;
  22. // constructors & distructors
  23. explicit Mat3() {};
  24. explicit Mat3(float f);
  25. explicit Mat3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22);
  26. explicit Mat3(float arr []);
  27. Mat3(const Mat3& b);
  28. explicit Mat3(const Quat& q); ///< @ref Quat to @ref Mat3. 12 muls, 12 adds
  29. explicit Mat3(const Euler& eu);
  30. explicit Mat3(const Axisang& axisang);
  31. // ops with mat3
  32. Mat3 operator + (const Mat3& b) const;
  33. Mat3& operator +=(const Mat3& b);
  34. Mat3 operator - (const Mat3& b) const;
  35. Mat3& operator -=(const Mat3& b);
  36. Mat3 operator * (const Mat3& b) const; ///< 27 muls, 18 adds
  37. Mat3& operator *=(const Mat3& b);
  38. Mat3 operator / (const Mat3& b) const;
  39. Mat3& operator /=(const Mat3& b);
  40. // ops with float
  41. Mat3 operator + (float f) const;
  42. Mat3& operator +=(float f);
  43. Mat3 operator - (float f) const;
  44. Mat3& operator -=(float f);
  45. Mat3 operator * (float f) const;
  46. Mat3& operator *=(float f);
  47. Mat3 operator / (float f) const;
  48. Mat3& operator /=(float f);
  49. // ops with others
  50. Vec3 operator * (const Vec3& b) const; ///< 9 muls, 6 adds
  51. // comparision
  52. bool operator ==(const Mat3& b) const;
  53. bool operator !=(const Mat3& b) const;
  54. // other
  55. void setRows(const Vec3& a, const Vec3& b, const Vec3& c);
  56. void setRow(const uint i, const Vec3& v);
  57. void getRows(Vec3& a, Vec3& b, Vec3& c) const;
  58. Vec3 getRow(const uint i) const;
  59. void setColumns(const Vec3& a, const Vec3& b, const Vec3& c);
  60. void setColumn(const uint i, const Vec3& v);
  61. void getColumns(Vec3& a, Vec3& b, Vec3& c) const;
  62. Vec3 getColumn(const uint i) const;
  63. Vec3 getXAxis() const;
  64. Vec3 getYAxis() const;
  65. Vec3 getZAxis() const;
  66. void setXAxis(const Vec3& v3);
  67. void setYAxis(const Vec3& v3);
  68. void setZAxis(const Vec3& v3);
  69. void setRotationX(float rad);
  70. void setRotationY(float rad);
  71. void setRotationZ(float rad);
  72. void rotateXAxis(float rad); ///< It rotates "this" in the axis defined by the rotation AND not the world axis
  73. void rotateYAxis(float rad);
  74. void rotateZAxis(float rad);
  75. void transpose();
  76. Mat3 getTransposed() const;
  77. void reorthogonalize();
  78. void print() const;
  79. float getDet() const;
  80. void invert();
  81. Mat3 getInverse() const;
  82. void setIdentity();
  83. static const Mat3& getZero();
  84. static const Mat3& getIdentity();
  85. };
  86. // other operators
  87. extern Mat3 operator +(float f, const Mat3& m3);
  88. extern Mat3 operator -(float f, const Mat3& m3);
  89. extern Mat3 operator *(float f, const Mat3& m3);
  90. extern Mat3 operator /(float f, const Mat3& m3);
  91. extern ostream& operator<<(ostream& s, const Mat3& m);
  92. } // end namespace
  93. #include "Mat3.inl.h"
  94. #endif