Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:03

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) = default;
0050 
0051   mat4& operator&(const mat4& mat) {
0052     if (this != &mat) {
0053       for (unsigned i = 0; i < 12; ++i)
0054         data[i] = mat[i];
0055     }
0056     return *this;
0057   }
0058 
0059   mat4 operator+(const mat4& mat) const {
0060     mat4 tmp;
0061     for (unsigned i = 0; i < 12; ++i)
0062       tmp[i] = (*this)[i] + mat[i];
0063 
0064     return tmp;
0065   }
0066 
0067   mat4 operator*(float s) const {
0068     mat4 tmp;
0069     for (unsigned i = 0; i < 12; ++i)
0070       tmp[i] = (*this)[i] * s;
0071 
0072     return tmp;
0073   }
0074 
0075   float& operator[](unsigned i) { return data[i]; }
0076 
0077   float operator[](unsigned i) const { return data[i]; }
0078 
0079   void MulVec(const float* vecIn, float* vecOut) {
0080     for (unsigned i = 0; i < 3; ++i) {
0081       float temp = 0;
0082       for (unsigned j = 0; j < 3; ++j) {
0083         temp += data[3 * j + i] * vecIn[j];
0084       }
0085       vecOut[i] = temp + data[9 + i];
0086     }
0087   }
0088   void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far) {
0089     float rmli = 1.0f / (right - left);
0090     float rpl = right + left;
0091 
0092     float tmbi = 1.0f / (top - bottom);
0093     float tpb = top + bottom;
0094 
0095     float fmni = 1.0f / (far - near);
0096     float fpn = far + near;
0097 
0098     data[0] = 2.0f * rmli;
0099     data[1] = 0.0f;
0100     data[2] = 0.0f;
0101 
0102     data[3] = 0.0f;
0103     data[4] = 2.0f * tmbi;
0104     data[5] = 0.0f;
0105 
0106     data[6] = 0.0f;
0107     data[7] = 0.0f;
0108     data[8] = -2.0f * fmni;
0109 
0110     data[9] = -rpl * rmli;
0111     data[10] = -tpb * tmbi;
0112     data[11] = -fpn * fmni;
0113   }
0114 };
0115 
0116 #endif