CMS 3D CMS Logo

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) = default;
50 
51  mat4& operator&(const mat4& mat) {
52  if (this != &mat) {
53  for (unsigned i = 0; i < 12; ++i)
54  data[i] = mat[i];
55  }
56  return *this;
57  }
58 
59  mat4 operator+(const mat4& mat) const {
60  mat4 tmp;
61  for (unsigned i = 0; i < 12; ++i)
62  tmp[i] = (*this)[i] + mat[i];
63 
64  return tmp;
65  }
66 
67  mat4 operator*(float s) const {
68  mat4 tmp;
69  for (unsigned i = 0; i < 12; ++i)
70  tmp[i] = (*this)[i] * s;
71 
72  return tmp;
73  }
74 
75  float& operator[](unsigned i) { return data[i]; }
76 
77  float operator[](unsigned i) const { return data[i]; }
78 
79  void MulVec(const float* vecIn, float* vecOut) {
80  for (unsigned i = 0; i < 3; ++i) {
81  float temp = 0;
82  for (unsigned j = 0; j < 3; ++j) {
83  temp += data[3 * j + i] * vecIn[j];
84  }
85  vecOut[i] = temp + data[9 + i];
86  }
87  }
88  void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far) {
89  float rmli = 1.0f / (right - left);
90  float rpl = right + left;
91 
92  float tmbi = 1.0f / (top - bottom);
93  float tpb = top + bottom;
94 
95  float fmni = 1.0f / (far - near);
96  float fpn = far + near;
97 
98  data[0] = 2.0f * rmli;
99  data[1] = 0.0f;
100  data[2] = 0.0f;
101 
102  data[3] = 0.0f;
103  data[4] = 2.0f * tmbi;
104  data[5] = 0.0f;
105 
106  data[6] = 0.0f;
107  data[7] = 0.0f;
108  data[8] = -2.0f * fmni;
109 
110  data[9] = -rpl * rmli;
111  data[10] = -tpb * tmbi;
112  data[11] = -fpn * fmni;
113  }
114 };
115 
116 #endif
Definition: mat4.h:9
float operator[](unsigned i) const
Definition: mat4.h:77
mat4()
Definition: mat4.h:13
void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far)
Definition: mat4.h:88
float data[12]
Definition: mat4.h:11
mat4(const mat4 &mat)
Definition: mat4.h:44
float & operator[](unsigned i)
Definition: mat4.h:75
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
void MulVec(const float *vecIn, float *vecOut)
Definition: mat4.h:79
mat4 operator+(const mat4 &mat) const
Definition: mat4.h:59
mat4 operator*(float s) const
Definition: mat4.h:67
mat4 & operator=(const mat4 &mat)=default
mat4 & operator &(const mat4 &mat)
Definition: mat4.h:51
tmp
align.sh
Definition: createJobs.py:716