CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mat4.h
Go to the documentation of this file.
1 #ifndef DQM_TRACKERREMAPPER_MAT4_H
2 #define DQM_TRACKERREMAPPER_MAT4_H
3 
4 // helper class for matrix operations
5 // - 4 rows
6 // - 3 columns
7 // in math operations behaves like 4x4 matrix with 4th row equal to: [0, 0, 0, 1]
8 // ! it's just the minimum implementation !
9 class mat4 {
10 public:
11  float data[12];
12 
13  mat4() {}
14 
15  mat4(float r00,
16  float r10,
17  float r20,
18  float r01,
19  float r11,
20  float r21,
21  float r02,
22  float r12,
23  float r22,
24  float x,
25  float y,
26  float z) {
27  data[0] = r00;
28  data[1] = r10;
29  data[2] = r20;
30 
31  data[3] = r01;
32  data[4] = r11;
33  data[5] = r21;
34 
35  data[6] = r02;
36  data[7] = r12;
37  data[8] = r22;
38 
39  data[9] = x;
40  data[10] = y;
41  data[11] = z;
42  }
43 
44  mat4(const mat4& mat) {
45  for (unsigned i = 0; i < 12; ++i)
46  data[i] = mat[i];
47  }
48 
49  mat4& operator&(const mat4& mat) {
50  if (this != &mat) {
51  for (unsigned i = 0; i < 12; ++i)
52  data[i] = mat[i];
53  }
54  return *this;
55  }
56 
57  mat4 operator+(const mat4& mat) const {
58  mat4 tmp;
59  for (unsigned i = 0; i < 12; ++i)
60  tmp[i] = (*this)[i] + mat[i];
61 
62  return tmp;
63  }
64 
65  mat4 operator*(float s) const {
66  mat4 tmp;
67  for (unsigned i = 0; i < 12; ++i)
68  tmp[i] = (*this)[i] * s;
69 
70  return tmp;
71  }
72 
73  float& operator[](unsigned i) { return data[i]; }
74 
75  float operator[](unsigned i) const { return data[i]; }
76 
77  void MulVec(const float* vecIn, float* vecOut) {
78  for (unsigned i = 0; i < 3; ++i) {
79  float temp = 0;
80  for (unsigned j = 0; j < 3; ++j) {
81  temp += data[3 * j + i] * vecIn[j];
82  }
83  vecOut[i] = temp + data[9 + i];
84  }
85  }
86  void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far) {
87  float rmli = 1.0f / (right - left);
88  float rpl = right + left;
89 
90  float tmbi = 1.0f / (top - bottom);
91  float tpb = top + bottom;
92 
93  float fmni = 1.0f / (far - near);
94  float fpn = far + near;
95 
96  data[0] = 2.0f * rmli;
97  data[1] = 0.0f;
98  data[2] = 0.0f;
99 
100  data[3] = 0.0f;
101  data[4] = 2.0f * tmbi;
102  data[5] = 0.0f;
103 
104  data[6] = 0.0f;
105  data[7] = 0.0f;
106  data[8] = -2.0f * fmni;
107 
108  data[9] = -rpl * rmli;
109  data[10] = -tpb * tmbi;
110  data[11] = -fpn * fmni;
111  }
112 };
113 
114 #endif
Definition: mat4.h:9
mat4()
Definition: mat4.h:13
void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far)
Definition: mat4.h:86
float data[12]
Definition: mat4.h:11
mat4 operator*(float s) const
Definition: mat4.h:65
mat4(const mat4 &mat)
Definition: mat4.h:44
mat4 operator+(const mat4 &mat) const
Definition: mat4.h:57
float & operator[](unsigned i)
Definition: mat4.h:73
mat4 & operator&(const mat4 &mat)
Definition: mat4.h:49
mat4(float r00, float r10, float r20, float r01, float r11, float r21, float r02, float r12, float r22, float x, float y, float z)
Definition: mat4.h:15
float operator[](unsigned i) const
Definition: mat4.h:75
void MulVec(const float *vecIn, float *vecOut)
Definition: mat4.h:77
tmp
align.sh
Definition: createJobs.py:716