TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Matrix2.h
Go to the documentation of this file.
1 #ifndef G3D_Matrix2_h
2 #define G3D_Matrix2_h
3 
4 #include "G3D/platform.h"
5 #include "G3D/Vector2.h"
6 
7 namespace G3D {
8 
10 class Matrix2 {
11 private:
12  // Row, column
13  float data[2][2];
14 
15 public:
16 
17  Matrix2() {
18  data[0][0] = 1.0f; data[0][1] = 0.0f;
19  data[1][0] = 0.0f; data[1][1] = 1.0f;
20  }
21 
22  Matrix2(float v00, float v01, float v10, float v11) {
23  data[0][0] = v00; data[0][1] = v01;
24  data[1][0] = v10; data[1][1] = v11;
25  }
26 
27  static Matrix2 identity() {
28  return Matrix2(1.0f, 0.0f, 0.0f, 1.0f);
29  }
30 
31  Vector2 operator*(const Vector2& v) const {
32  return Vector2(data[0][0] * v[0] + data[0][1] * v[1],
33  data[1][0] * v[0] + data[1][1] * v[1]);
34  }
35 
36  Matrix2 inverse() const {
37  return Matrix2(data[1][1], -data[0][1],
38  -data[1][0], data[0][0]) * (1.0f / determinant());
39  }
40 
41  Matrix2 transpose() const {
42  return Matrix2(data[0][0], data[1][0],
43  data[0][1], data[1][1]);
44  }
45 
46  float determinant() const {
47  return data[0][0] * data[1][1] - data[0][1] * data[1][0];
48  }
49 
50  Matrix2 operator*(float f) const {
51  return Matrix2(data[0][0] * f, data[0][1] * f,
52  data[1][0] * f, data[1][1] * f);
53  }
54 
55  Matrix2 operator/(float f) const {
56  return Matrix2(data[0][0] / f, data[0][1] / f,
57  data[1][0] / f, data[1][1] / f);
58  }
59 
60  inline float* operator[] (int i) {
61  debugAssert(i >= 0 && i <= 1);
62  return (float*)&data[i][0];
63  }
64 
65  inline const float* operator[] (int i) const {
66  debugAssert(i >= 0 && i <= 1);
67  return (const float*)&data[i][0];
68  }
69 
70  inline operator float* () {
71  return (float*)&data[0][0];
72  }
73 
74  inline operator const float* () const{
75  return (const float*)&data[0][0];
76  }
77 
78 };
79 
80 }
81 
82 #endif
Definition: Matrix2.h:10
Definition: Vector2.h:40
float determinant() const
Definition: Matrix2.h:46
float data[2][2]
Definition: Matrix2.h:13
Definition: AABox.h:25
Matrix2(float v00, float v01, float v10, float v11)
Definition: Matrix2.h:22
Vector2 operator*(const Vector2 &v) const
Definition: Matrix2.h:31
float * operator[](int i)
Definition: Matrix2.h:60
#define debugAssert(exp)
Definition: debugAssert.h:160
Matrix2 inverse() const
Definition: Matrix2.h:36
Matrix2 operator/(float f) const
Definition: Matrix2.h:55
Matrix2 operator*(float f) const
Definition: Matrix2.h:50
Matrix2 transpose() const
Definition: Matrix2.h:41
static Matrix2 identity()
Definition: Matrix2.h:27
Matrix2()
Definition: Matrix2.h:17