Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-09 02:50:37

0001 #ifndef DQM_TRACKERREMAPPER_MAT4_H
0002 #define DQM_TRACKERREMAPPER_MAT4_H
0003 
0004 // helper class for matrix operations
0005 // - 4 rows
0006 // - 3 columns
0007 // in math operations behaves like 4x4 matrix with 4th row equal to: [0, 0, 0, 1]
0008 // ! it's just the minimum implementation !
0009 class mat4 {
0010 public:
0011   float data[12];
0012 
0013   mat4() {}
0014 
0015   mat4(float r00,
0016        float r10,
0017        float r20,
0018        float r01,
0019        float r11,
0020        float r21,
0021        float r02,
0022        float r12,
0023        float r22,
0024        float x,
0025        float y,
0026        float z) {
0027     data[0] = r00;
0028     data[1] = r10;
0029     data[2] = r20;
0030 
0031     data[3] = r01;
0032     data[4] = r11;
0033     data[5] = r21;
0034 
0035     data[6] = r02;
0036     data[7] = r12;
0037     data[8] = r22;
0038 
0039     data[9] = x;
0040     data[10] = y;
0041     data[11] = z;
0042   }
0043 
0044   mat4(const mat4& mat) {
0045     for (unsigned i = 0; i < 12; ++i)
0046       data[i] = mat[i];
0047   }
0048 
0049   mat4& operator&(const mat4& mat) {
0050     if (this != &mat) {
0051       for (unsigned i = 0; i < 12; ++i)
0052         data[i] = mat[i];
0053     }
0054     return *this;
0055   }
0056 
0057   mat4 operator+(const mat4& mat) const {
0058     mat4 tmp;
0059     for (unsigned i = 0; i < 12; ++i)
0060       tmp[i] = (*this)[i] + mat[i];
0061 
0062     return tmp;
0063   }
0064 
0065   mat4 operator*(float s) const {
0066     mat4 tmp;
0067     for (unsigned i = 0; i < 12; ++i)
0068       tmp[i] = (*this)[i] * s;
0069 
0070     return tmp;
0071   }
0072 
0073   float& operator[](unsigned i) { return data[i]; }
0074 
0075   float operator[](unsigned i) const { return data[i]; }
0076 
0077   void MulVec(const float* vecIn, float* vecOut) {
0078     for (unsigned i = 0; i < 3; ++i) {
0079       float temp = 0;
0080       for (unsigned j = 0; j < 3; ++j) {
0081         temp += data[3 * j + i] * vecIn[j];
0082       }
0083       vecOut[i] = temp + data[9 + i];
0084     }
0085   }
0086   void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far) {
0087     float rmli = 1.0f / (right - left);
0088     float rpl = right + left;
0089 
0090     float tmbi = 1.0f / (top - bottom);
0091     float tpb = top + bottom;
0092 
0093     float fmni = 1.0f / (far - near);
0094     float fpn = far + near;
0095 
0096     data[0] = 2.0f * rmli;
0097     data[1] = 0.0f;
0098     data[2] = 0.0f;
0099 
0100     data[3] = 0.0f;
0101     data[4] = 2.0f * tmbi;
0102     data[5] = 0.0f;
0103 
0104     data[6] = 0.0f;
0105     data[7] = 0.0f;
0106     data[8] = -2.0f * fmni;
0107 
0108     data[9] = -rpl * rmli;
0109     data[10] = -tpb * tmbi;
0110     data[11] = -fpn * fmni;
0111   }
0112 };
0113 
0114 #endif