g4tools  5.4.0
mat4
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_mat4
5 #define tools_mat4
6 
7 #include "mat"
8 
9 //#include <cmath>
10 
11 namespace tools {
12 
13 template <class T>
14 class mat4 : public mat<T,4> {
15  typedef mat<T,4> parent;
16  typedef mat<T,4> pr;
17 public:
18 #ifdef TOOLS_MEM
19  mat4(bool a_inc = true):parent(a_inc) {}
20 #else
21  mat4():parent() {}
22 #endif
23  mat4(const mat<T,4>& a_from):parent(a_from){}
24  virtual ~mat4() {}
25 public:
26  mat4(const mat4& a_from):parent(a_from){}
27  mat4& operator=(const mat4& a_from){
28  parent::operator=(a_from);
29  return *this;
30  }
31 public:
32  mat4(const T& a_00,const T& a_01,const T& a_02,const T& a_03, //first row
33  const T& a_10,const T& a_11,const T& a_12,const T& a_13, //second row
34  const T& a_20,const T& a_21,const T& a_22,const T& a_23, //third row
35  const T& a_30,const T& a_31,const T& a_32,const T& a_33) //fourth row
36  {
37  set_matrix(a_00,a_01,a_02,a_03,
38  a_10,a_11,a_12,a_13,
39  a_20,a_21,a_22,a_23,
40  a_30,a_31,a_32,a_33);
41  }
42 public:
43  void set_matrix(const mat4<T>& a_m) {parent::set_matrix(a_m);}
44  void set_matrix(
45  const T& a_00,const T& a_01,const T& a_02,const T& a_03, //1 row
46  const T& a_10,const T& a_11,const T& a_12,const T& a_13, //2 row
47  const T& a_20,const T& a_21,const T& a_22,const T& a_23, //3 row
48  const T& a_30,const T& a_31,const T& a_32,const T& a_33) //4 row
49  {
50  //a_<R><C>
51  //pr::m_vec[R + C * 4];
52  pr::m_vec[0] = a_00;pr::m_vec[4] = a_01;pr::m_vec[ 8] = a_02;pr::m_vec[12] = a_03;
53  pr::m_vec[1] = a_10;pr::m_vec[5] = a_11;pr::m_vec[ 9] = a_12;pr::m_vec[13] = a_13;
54  pr::m_vec[2] = a_20;pr::m_vec[6] = a_21;pr::m_vec[10] = a_22;pr::m_vec[14] = a_23;
55  pr::m_vec[3] = a_30;pr::m_vec[7] = a_31;pr::m_vec[11] = a_32;pr::m_vec[15] = a_33;
56  }
57 
58  void set_scale(const T& a_s) {_set_scale(a_s,a_s,a_s,pr::m_vec);}
59  void set_scale(const T& a_1,const T& a_2,const T& a_3) {_set_scale(a_1,a_2,a_3,pr::m_vec);}
60  void set_translate(const T& a_x,const T& a_y,const T& a_z) {_set_translate(a_x,a_y,a_z,pr::m_vec);}
61  void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
62  _set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
63  }
64  void set_ortho(const T& a_l,const T& a_r, //left,right
65  const T& a_b,const T& a_t, //bottom,top
66  const T& a_n,const T& a_f) { //znear,zfar
67  // from man glOrtho.
68  T tx = -(a_r+a_l)/(a_r-a_l);
69  T ty = -(a_t+a_b)/(a_t-a_b);
70  T tz = -(a_f+a_n)/(a_f-a_n);
71 
72  T a_00,a_01,a_02,a_03;
73  T a_10,a_11,a_12,a_13;
74  T a_20,a_21,a_22,a_23;
75  T a_30,a_31,a_32,a_33;
76  a_00 = 2/(a_r-a_l);a_01 = 0;a_02 = 0;a_03 = tx;
77  a_10 = 0;a_11 = 2/(a_t-a_b);a_12 = 0;a_13 = ty;
78  a_20 = 0;a_21 = 0;a_22 = -2/(a_f-a_n);a_23 = tz;
79  a_30 = 0;a_31 = 0;a_32 = 0;a_33 = 1;
80  set_matrix(a_00,a_01,a_02,a_03, //1 row
81  a_10,a_11,a_12,a_13, //2 row
82  a_20,a_21,a_22,a_23, //3 row
83  a_30,a_31,a_32,a_33); //4 row
84 
85  //NOTE : Z(x,y, z,1) = -2z/(f-n)+tz = [-2z-f-n]/(f-n)
86  // W(x,y, z,1) = 1 -> Z/W = Z
87  // Z(x,y,-n,1) = -1
88  // Z(x,y,-f,1) = 1
89 
90  // Z(x,y,-(f+n)/2,1) = 0
91 
92  // X(x,0, z,1) = 2x/(r-l)+tx = [2x-r-l]/(r-l)
93  // X(r,0, z,1) = 1
94 
95  // the view direction is then (0,0,1) in the final projection.
96  }
97  void set_frustum(const T& a_l,const T& a_r, //left,right
98  const T& a_b,const T& a_t, //bottom,top
99  const T& a_n,const T& a_f) { //znear,zfar
100  // from man glFrustum.
101  T A = (a_r+a_l)/(a_r-a_l);
102  T B = (a_t+a_b)/(a_t-a_b);
103  T C = -(a_f+a_n)/(a_f-a_n);
104  T D = -(2*a_f*a_n)/(a_f-a_n);
105 
106  T a_00,a_01,a_02,a_03;
107  T a_10,a_11,a_12,a_13;
108  T a_20,a_21,a_22,a_23;
109  T a_30,a_31,a_32,a_33;
110  a_00 = (2*a_n)/(a_r-a_l);a_01 = 0;a_02 = A;a_03 = 0;
111  a_10 = 0;a_11 = (2*a_n)/(a_t-a_b);a_12 = B;a_13 = 0;
112  a_20 = 0;a_21 = 0;a_22 = C;a_23 = D;
113  a_30 = 0;a_31 = 0;a_32 = -1;a_33 = 0;
114  set_matrix(a_00,a_01,a_02,a_03, //1 row
115  a_10,a_11,a_12,a_13, //2 row
116  a_20,a_21,a_22,a_23, //3 row
117  a_30,a_31,a_32,a_33); //4 row
118 
119  //NOTE : Z(x,y, z,1) = C*z+D = -[(f+n)*z+2*f*n]/(f-n)
120 
121  // Z(x,y,-n,1) = -[-fn-nn+2fn]/(f-n) = -[fn-nn]/(f-n) = -n
122  // W(x,y,-n,1) = n
123  // -> Z/W(x,y,-n,1) = -1
124 
125  // Z(x,y,-2fn/(f+n),1) = 0
126  // -> Z/W = 0
127 
128  // Z(x,y,-f,1) = -[-ff-fn+2fn]/(f-n) = -[fn-ff]/(f-n) = f
129  // W(x,y,-f,1) = f
130  // -> Z/W(x,y,-f,1) = 1
131 
132  // X(x,0, z,1) = 2nx/(r-l)+z(r+l)/(r-l) = [2nx+zr+zl]/(r-l)
133  // X(r,0,-n,1) = [nr-nl]/(r-l) = n
134  // W(r,0,-n,1) = n
135  // -> X/W(r,0,-n,1) = 1
136 
137  // X(l,0,-n,1) = (2nl-n(r+l))/(r-l) = -n
138  // W(l,0,-n,1) = n
139  // -> X/W(l,0,-n,1) = -1
140 
141  // lrbt corners are in plane z=-1 at xy=+/-1.
142 
143  // eye ?
144  // eye before ? (0,0,z,1) -> (zA,zB,zC+D,-z) /W -> (-A,-B,-(C+D/z),1)
145  // z=0 -> (0,0,D=-2fn(f-n),0)
146 
147  }
148 
149  void get_translate(T& a_x,T& a_y,T& a_z) const {
150  a_x = pr::m_vec[12];
151  a_y = pr::m_vec[13];
152  a_z = pr::m_vec[14];
153  }
154 
155  void no_translate() {
156  pr::m_vec[12] = 0;
157  pr::m_vec[13] = 0;
158  pr::m_vec[14] = 0;
159  }
160 
161 //void set_translate_only(const T& a_x,const T& a_y,const T& a_z) {
162 // pr::m_vec[12] = a_x;
163 // pr::m_vec[13] = a_y;
164 // pr::m_vec[14] = a_z;
165 //}
166 
167 public:
168  void mul_4(T& a_x,T& a_y,T& a_z,T& a_p) const {
169  // a_[x,y,z,p] = this * a_[x,y,z,p]
170  //pr::m_vec[R + C * 4];
171  //pr::m_vec[0]= 00;pr::m_vec[4] = 01;pr::m_vec[ 8] = 02;pr::m_vec[12] = 03;
172  //pr::m_vec[1]= 10;pr::m_vec[5] = 11;pr::m_vec[ 9] = 12;pr::m_vec[13] = 13;
173  //pr::m_vec[2]= 20;pr::m_vec[6] = 21;pr::m_vec[10] = 22;pr::m_vec[14] = 23;
174  //pr::m_vec[3]= 30;pr::m_vec[7] = 31;pr::m_vec[11] = 32;pr::m_vec[15] = 33;
175  T x= pr::m_vec[0]*a_x+pr::m_vec[4]*a_y+pr::m_vec[ 8]*a_z+pr::m_vec[12]*a_p;
176  T y= pr::m_vec[1]*a_x+pr::m_vec[5]*a_y+pr::m_vec[ 9]*a_z+pr::m_vec[13]*a_p;
177  T z= pr::m_vec[2]*a_x+pr::m_vec[6]*a_y+pr::m_vec[10]*a_z+pr::m_vec[14]*a_p;
178  T p= pr::m_vec[3]*a_x+pr::m_vec[7]*a_y+pr::m_vec[11]*a_z+pr::m_vec[15]*a_p;
179  a_x = x;
180  a_y = y;
181  a_z = z;
182  a_p = p;
183  }
184  void mul_3(T& a_x,T& a_y,T& a_z) const {
185  // a_[x,y,z] = this * a_[x,y,z]
186  //pr::m_vec[R + C * 4];
187  //pr::m_vec[0]= 00;pr::m_vec[4] = 01;pr::m_vec[ 8] = 02;pr::m_vec[12] = 03;
188  //pr::m_vec[1]= 10;pr::m_vec[5] = 11;pr::m_vec[ 9] = 12;pr::m_vec[13] = 13;
189  //pr::m_vec[2]= 20;pr::m_vec[6] = 21;pr::m_vec[10] = 22;pr::m_vec[14] = 23;
190  //pr::m_vec[3]= 30;pr::m_vec[7] = 31;pr::m_vec[11] = 32;pr::m_vec[15] = 33;
191  T x = pr::m_vec[0]*a_x+pr::m_vec[4]*a_y+pr::m_vec[ 8]*a_z+pr::m_vec[12];
192  T y = pr::m_vec[1]*a_x+pr::m_vec[5]*a_y+pr::m_vec[ 9]*a_z+pr::m_vec[13];
193  T z = pr::m_vec[2]*a_x+pr::m_vec[6]*a_y+pr::m_vec[10]*a_z+pr::m_vec[14];
194  a_x = x;
195  a_y = y;
196  a_z = z;
197  }
198  void mul_2(T& a_x,T& a_y) const {
199  // a_[x,y] = this * a_[x,y]
200  //pr::m_vec[R + C * 4];
201  //pr::m_vec[0]= 00;pr::m_vec[4] = 01;pr::m_vec[ 8] = 02;pr::m_vec[12] = 03;
202  //pr::m_vec[1]= 10;pr::m_vec[5] = 11;pr::m_vec[ 9] = 12;pr::m_vec[13] = 13;
203  //pr::m_vec[2]= 20;pr::m_vec[6] = 21;pr::m_vec[10] = 22;pr::m_vec[14] = 23;
204  //pr::m_vec[3]= 30;pr::m_vec[7] = 31;pr::m_vec[11] = 32;pr::m_vec[15] = 33;
205  T x = pr::m_vec[0]*a_x+pr::m_vec[4]*a_y+pr::m_vec[12];
206  T y = pr::m_vec[1]*a_x+pr::m_vec[5]*a_y+pr::m_vec[13];
207  a_x = x;
208  a_y = y;
209  }
210 
211  void mul_dir_3(T& a_x,T& a_y,T& a_z) const {
212  // used to multiply normals.
213  // a_[x,y,z] = rot_part(this) * a_[x,y,z]
214 
215  T x = pr::m_vec[0]*a_x+pr::m_vec[4]*a_y+pr::m_vec[ 8]*a_z;
216  T y = pr::m_vec[1]*a_x+pr::m_vec[5]*a_y+pr::m_vec[ 9]*a_z;
217  T z = pr::m_vec[2]*a_x+pr::m_vec[6]*a_y+pr::m_vec[10]*a_z;
218  a_x = x;
219  a_y = y;
220  a_z = z;
221  }
222 
223  void mul_trans_3(T& a_x,T& a_y,T& a_z) const {
224  // used in sg::healpix.
225  // a_[x,y,z] = trans_part(this) * a_[x,y,z]
226  a_x += pr::m_vec[12];
227  a_y += pr::m_vec[13];
228  a_z += pr::m_vec[14];
229  }
230 
231  template <class VEC>
232  void mul_dir_3(VEC& a_dir) const {mul_dir_3(a_dir[0],a_dir[1],a_dir[2]);}
233 
234  void mul_scale(const T& a_sx,const T& a_sy,const T& a_sz) {
235  // this = this * mat4_scale(a_s[x,y,z]
236  //pr::m_vec[R + C * 4];
237  //pr::m_vec[0]= 00;pr::m_vec[4] = 01;pr::m_vec[ 8] = 02;pr::m_vec[12] = 03;
238  //pr::m_vec[1]= 10;pr::m_vec[5] = 11;pr::m_vec[ 9] = 12;pr::m_vec[13] = 13;
239  //pr::m_vec[2]= 20;pr::m_vec[6] = 21;pr::m_vec[10] = 22;pr::m_vec[14] = 23;
240  //pr::m_vec[3]= 30;pr::m_vec[7] = 31;pr::m_vec[11] = 32;pr::m_vec[15] = 33;
241  pr::m_vec[0] *= a_sx;
242  pr::m_vec[1] *= a_sx;
243  pr::m_vec[2] *= a_sx;
244  pr::m_vec[3] *= a_sx;
245 
246  pr::m_vec[4] *= a_sy;
247  pr::m_vec[5] *= a_sy;
248  pr::m_vec[6] *= a_sy;
249  pr::m_vec[7] *= a_sy;
250 
251  pr::m_vec[ 8] *= a_sz;
252  pr::m_vec[ 9] *= a_sz;
253  pr::m_vec[10] *= a_sz;
254  pr::m_vec[11] *= a_sz;
255  }
256  void mul_scale(const T& a_s) {
257  pr::m_vec[0] *= a_s;
258  pr::m_vec[1] *= a_s;
259  pr::m_vec[2] *= a_s;
260  pr::m_vec[3] *= a_s;
261 
262  pr::m_vec[4] *= a_s;
263  pr::m_vec[5] *= a_s;
264  pr::m_vec[6] *= a_s;
265  pr::m_vec[7] *= a_s;
266 
267  pr::m_vec[ 8] *= a_s;
268  pr::m_vec[ 9] *= a_s;
269  pr::m_vec[10] *= a_s;
270  pr::m_vec[11] *= a_s;
271  }
272  void mul_translate(const T& a_x,const T& a_y,const T& a_z) {
273  pr::m_vec[12] = pr::m_vec[0]*a_x+pr::m_vec[4]*a_y+pr::m_vec[ 8]*a_z+pr::m_vec[12];
274  pr::m_vec[13] = pr::m_vec[1]*a_x+pr::m_vec[5]*a_y+pr::m_vec[ 9]*a_z+pr::m_vec[13];
275  pr::m_vec[14] = pr::m_vec[2]*a_x+pr::m_vec[6]*a_y+pr::m_vec[10]*a_z+pr::m_vec[14];
276  pr::m_vec[15] = pr::m_vec[3]*a_x+pr::m_vec[7]*a_y+pr::m_vec[11]*a_z+pr::m_vec[15];
277  }
278 
279  void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
280  T rot[16];
281  _set_rotate(a_x,a_y,a_z,a_angle,rot,a_sin,a_cos);
282  parent::_mul_mtx(rot);
283  }
284 
285  void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
286  T _m[16];
287  _set_rotate(a_x,a_y,a_z,a_angle,_m,a_sin,a_cos);
288  parent::_left_mul_mtx(_m);
289  }
290 
291  void left_mul_scale(const T& a_x,const T& a_y,const T& a_z) {
292  T _m[16];
293  _set_scale(a_x,a_y,a_z,_m);
294  parent::_left_mul_mtx(_m);
295  }
296 
297  void left_mul_translate(const T& a_x,const T& a_y,const T& a_z) {
298  T _m[16];
299  _set_translate(a_x,a_y,a_z,_m);
300  parent::_left_mul_mtx(_m);
301  }
302 
303  void v00(const T& a_value){pr::m_vec[0+0*4] = a_value;}
304  void v10(const T& a_value){pr::m_vec[1+0*4] = a_value;}
305  void v20(const T& a_value){pr::m_vec[2+0*4] = a_value;}
306  void v30(const T& a_value){pr::m_vec[3+0*4] = a_value;}
307 
308  void v01(const T& a_value){pr::m_vec[0+1*4] = a_value;}
309  void v11(const T& a_value){pr::m_vec[1+1*4] = a_value;}
310  void v21(const T& a_value){pr::m_vec[2+1*4] = a_value;}
311  void v31(const T& a_value){pr::m_vec[3+1*4] = a_value;}
312 
313  void v02(const T& a_value){pr::m_vec[0+2*4] = a_value;}
314  void v12(const T& a_value){pr::m_vec[1+2*4] = a_value;}
315  void v22(const T& a_value){pr::m_vec[2+2*4] = a_value;}
316  void v32(const T& a_value){pr::m_vec[3+2*4] = a_value;}
317 
318  void v03(const T& a_value){pr::m_vec[0+3*4] = a_value;}
319  void v13(const T& a_value){pr::m_vec[1+3*4] = a_value;}
320  void v23(const T& a_value){pr::m_vec[2+3*4] = a_value;}
321  void v33(const T& a_value){pr::m_vec[3+3*4] = a_value;}
322 
323  const T& v00() const {return pr::m_vec[0+0*4];}
324  const T& v10() const {return pr::m_vec[1+0*4];}
325  const T& v20() const {return pr::m_vec[2+0*4];}
326  const T& v30() const {return pr::m_vec[3+0*4];}
327 
328  const T& v01() const {return pr::m_vec[0+1*4];}
329  const T& v11() const {return pr::m_vec[1+1*4];}
330  const T& v21() const {return pr::m_vec[2+1*4];}
331  const T& v31() const {return pr::m_vec[3+1*4];}
332 
333  const T& v02() const {return pr::m_vec[0+2*4];}
334  const T& v12() const {return pr::m_vec[1+2*4];}
335  const T& v22() const {return pr::m_vec[2+2*4];}
336  const T& v32() const {return pr::m_vec[3+2*4];}
337 
338  const T& v03() const {return pr::m_vec[0+3*4];}
339  const T& v13() const {return pr::m_vec[1+3*4];}
340  const T& v23() const {return pr::m_vec[2+3*4];}
341  const T& v33() const {return pr::m_vec[3+3*4];}
342 
343 protected:
344  static void _set_translate(const T& a_x,const T& a_y,const T& a_z,T v[]) {
345  v[0] = T(1);v[4] = 0;v[ 8] = 0;v[12] = a_x;
346  v[1] = 0;v[5] = T(1);v[ 9] = 0;v[13] = a_y;
347  v[2] = 0;v[6] = 0;v[10] = T(1);v[14] = a_z;
348  v[3] = 0;v[7] = 0;v[11] = 0;v[15] = T(1);
349  }
350 
351  static void _set_scale(const T& a_1,const T& a_2,const T& a_3,T v[]) {
352  v[0] = a_1;v[4] = 0;v[ 8] = 0;v[12] = 0;
353  v[1] = 0;v[5] = a_2;v[ 9] = 0;v[13] = 0;
354  v[2] = 0;v[6] = 0;v[10] = a_3;v[14] = 0;
355  v[3] = 0;v[7] = 0;v[11] = 0;v[15] = T(1);
356  }
357 
358  static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T v[],T(*a_sin)(T),T(*a_cos)(T)) {
359  //WARNING : (a_x,a_y,a_z) must be a normalized vector.
360  // v[] = exp(-a_angle*n(a_x,a_y,a_z)*Rs). It models the rotation of an object in the same coordinate system (active rotation).
361  T si = a_sin(a_angle);
362  T co = a_cos(a_angle);
363  T x = a_x;
364  T y = a_y;
365  T z = a_z;
366  T x2 = x*x;
367  T y2 = y*y;
368  T z2 = z*z;
369  T xy = x*y;
370  T xz = x*z;
371  T yz = y*z;
372  v[0] = x2+(1-x2)*co;v[4] = xy*(1-co)-z*si;v[ 8] = xz*(1-co)+y*si;v[12] = 0;
373  v[1] = xy*(1-co)+z*si;v[5] = y2+(1-y2)*co;v[ 9] = yz*(1-co)-x*si;v[13] = 0;
374  v[2] = xz*(1-co)-y*si;v[6] = yz*(1-co)+x*si;v[10] = z2+(1-z2)*co;v[14] = 0;
375  v[3] = 0;v[7] = 0;v[11] = 0;v[15] = 1;
376 
377  // If :
378  // n =(x,y,z)
379  // n2 = x2+y2+z2 = 1
380  // n.E = x*E1+y*E2+z*E3
381  // with :
382  // E1 E2 E3
383  // 0 0 0 0 0 -1 0 1 0
384  // 0 0 1 0 0 0 -1 0 0
385  // 0 -1 0 1 0 0 0 0 0
386  //
387  // R(r,c) = cos(theta)*Id(r,c)+(1-cos(theta))*nr*nc-sin(theta)*(n.E)(r,c)
388  //
389  // R = exp(-theta*(n.E)) // active rotation (it models the rotation of an object by theta along n).
390 
391  }
392 
393 public:
394  void mul_mtx_rot_root(const T& a_00,const T& a_01,const T& a_02, //1 row
395  const T& a_10,const T& a_11,const T& a_12, //2 row
396  const T& a_20,const T& a_21,const T& a_22) //3 row
397  {
398  T* tv = pr::m_vec;
399  //pr::m_vec[0] = 00;pr::m_vec[4] = 01;pr::m_vec[ 8] = 02;pr::m_vec[12] = 03;
400  //pr::m_vec[1] = 10;pr::m_vec[5] = 11;pr::m_vec[ 9] = 12;pr::m_vec[13] = 13;
401  //pr::m_vec[2] = 20;pr::m_vec[6] = 21;pr::m_vec[10] = 22;pr::m_vec[14] = 23;
402  //pr::m_vec[3] = 30;pr::m_vec[7] = 31;pr::m_vec[11] = 32;pr::m_vec[15] = 33;
403 
404  T tv_0 = tv[0];
405  T tv_1 = tv[1];
406  T tv_2 = tv[2];
407  T tv_3 = tv[3];
408  T tv_4 = tv[4];
409  T tv_5 = tv[5];
410  T tv_6 = tv[6];
411  T tv_7 = tv[7];
412  T tv_8 = tv[8];
413  T tv_9 = tv[9];
414  T tv_10 = tv[10];
415  T tv_11 = tv[11];
416  T tv_12 = tv[12];
417  T tv_13 = tv[13];
418  T tv_14 = tv[14];
419  T tv_15 = tv[15];
420 
421  T fv_0 = a_00;
422  T fv_1 = a_10;
423  T fv_2 = a_20;
424  //T fv_3 = 0;
425 
426  T fv_4 = a_01;
427  T fv_5 = a_11;
428  T fv_6 = a_21;
429  //T fv_7 = 0;
430 
431  T fv_8 = a_02;
432  T fv_9 = a_12;
433  T fv_10 = a_22;
434  //T fv_11 = 0;
435 
436  //T fv_12 = 0;
437  //T fv_13 = 0;
438  //T fv_14 = 0;
439  //T fv_15 = 1;
440 
441  tv[0] = tv_0*fv_0+tv_4*fv_1+ tv_8*fv_2;
442  tv[1] = tv_1*fv_0+tv_5*fv_1+ tv_9*fv_2;
443  tv[2] = tv_2*fv_0+tv_6*fv_1+tv_10*fv_2;
444  tv[3] = tv_3*fv_0+tv_7*fv_1+tv_11*fv_2;
445 
446  tv[4] = tv_0*fv_4+tv_4*fv_5+ tv_8*fv_6;
447  tv[5] = tv_1*fv_4+tv_5*fv_5+ tv_9*fv_6;
448  tv[6] = tv_2*fv_4+tv_6*fv_5+tv_10*fv_6;
449  tv[7] = tv_3*fv_4+tv_7*fv_5+tv_11*fv_6;
450 
451  tv[8] = tv_0*fv_8+tv_4*fv_9+ tv_8*fv_10;
452  tv[9] = tv_1*fv_8+tv_5*fv_9+ tv_9*fv_10;
453  tv[10] = tv_2*fv_8+tv_6*fv_9+tv_10*fv_10;
454  tv[11] = tv_3*fv_8+tv_7*fv_9+tv_11*fv_10;
455 
456  tv[12] = tv_12;
457  tv[13] = tv_13;
458  tv[14] = tv_14;
459  tv[15] = tv_15;
460  }
461 
462  template <class MAT3>
463  void set_mat3(MAT3& a_m3) {
464  a_m3.set_matrix(pr::m_vec[0],pr::m_vec[4],pr::m_vec[ 8], //1 row
465  pr::m_vec[1],pr::m_vec[5],pr::m_vec[ 9], //2 row
466  pr::m_vec[2],pr::m_vec[6],pr::m_vec[10]); //3 row
467  }
468 
469 private:static void check_instantiation() {mat4<float> dummy;}
470 };
471 
475 
476 #ifdef TOOLS_MEM
477 template <class T> inline const mat4<T>& mat4_zero() {static const mat4<T> s_v(false);return s_v;}
478 #else
479 template <class T> inline const mat4<T>& mat4_zero() {static const mat4<T> s_v;return s_v;}
480 #endif
481 
482 /*
483 template <class T>
484 inline const mat4<T>& mat4_identity() {
485  static mat4<T> s_v(false);
486  static bool s_first = true;
487  if(s_first) {s_v.set_identity();s_first=false;}
488  return s_v;
489 }
490 */
491 
492 //for sf, mf :
493 template <class T>
494 inline const T* get_data(const mat4<T>& a_v) {return a_v.data();}
495 
496 }
497 
498 #include <ostream>
499 
500 namespace tools {
501 
502 template <class T>
503 inline std::ostream& operator<<(std::ostream& a_out,const mat4<T>& a_mtx){
504  const T* v = a_mtx.data();
505  a_out << v[0] << "," << v[4] << "," << v[ 8] << "," << v[12] << std::endl
506  << v[1] << "," << v[5] << "," << v[ 9] << "," << v[13] << std::endl
507  << v[2] << "," << v[6] << "," << v[10] << "," << v[14] << std::endl
508  << v[3] << "," << v[7] << "," << v[11] << "," << v[15] << std::endl;
509  return a_out;
510 }
511 
512 }
513 
514 #endif
tools::mat4::v11
const T & v11() const
Definition: mat4:329
tools::mat4::v13
const T & v13() const
Definition: mat4:339
tools::mat4::v33
void v33(const T &a_value)
Definition: mat4:321
tools::mat4::set_translate
void set_translate(const T &a_x, const T &a_y, const T &a_z)
Definition: mat4:60
tools::mat4::mat4
mat4(const mat< T, 4 > &a_from)
Definition: mat4:23
tools::mat4::left_mul_translate
void left_mul_translate(const T &a_x, const T &a_y, const T &a_z)
Definition: mat4:297
tools::mat4::v12
const T & v12() const
Definition: mat4:334
tools::mat4::mat4
mat4(const mat4 &a_from)
Definition: mat4:26
tools::mat4::v23
const T & v23() const
Definition: mat4:340
tools::mat4::v10
void v10(const T &a_value)
Definition: mat4:304
tools::mat4::mul_2
void mul_2(T &a_x, T &a_y) const
Definition: mat4:198
tools::mat4::left_mul_scale
void left_mul_scale(const T &a_x, const T &a_y, const T &a_z)
Definition: mat4:291
tools::mat< T, 4 >::m_vec
T m_vec[D *D]
Definition: mat:85
tools::mat4::v22
void v22(const T &a_value)
Definition: mat4:315
tools::mat4::v11
void v11(const T &a_value)
Definition: mat4:309
tools::mat4::v03
const T & v03() const
Definition: mat4:338
tools::mat4::v23
void v23(const T &a_value)
Definition: mat4:320
tools::mat4::set_mat3
void set_mat3(MAT3 &a_m3)
Definition: mat4:463
tools::mat4::left_mul_rotate
void left_mul_rotate(const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
Definition: mat4:285
tools::mat4::v02
void v02(const T &a_value)
Definition: mat4:313
tools::mat4::v03
void v03(const T &a_value)
Definition: mat4:318
tools::mat4::mul_dir_3
void mul_dir_3(VEC &a_dir) const
Definition: mat4:232
tools::mat4::v30
void v30(const T &a_value)
Definition: mat4:306
tools::mat4::set_frustum
void set_frustum(const T &a_l, const T &a_r, const T &a_b, const T &a_t, const T &a_n, const T &a_f)
Definition: mat4:97
tools::mat4::mul_translate
void mul_translate(const T &a_x, const T &a_y, const T &a_z)
Definition: mat4:272
tools::mat4::set_matrix
void set_matrix(const mat4< T > &a_m)
Definition: mat4:43
tools::mat4::v20
void v20(const T &a_value)
Definition: mat4:305
tools::mat4::set_rotate
void set_rotate(const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
Definition: mat4:61
tools::mat4::mul_scale
void mul_scale(const T &a_s)
Definition: mat4:256
tools::get_data
const T * get_data(const mat4< T > &a_v)
Definition: mat4:494
tools::mat4::operator=
mat4 & operator=(const mat4 &a_from)
Definition: mat4:27
tools::mat4::v32
const T & v32() const
Definition: mat4:336
tools::mat4::v10
const T & v10() const
Definition: mat4:324
tools::mat4::mul_4
void mul_4(T &a_x, T &a_y, T &a_z, T &a_p) const
Definition: mat4:168
tools::mat4::v33
const T & v33() const
Definition: mat4:341
tools::mat4::mat4
mat4(const T &a_00, const T &a_01, const T &a_02, const T &a_03, const T &a_10, const T &a_11, const T &a_12, const T &a_13, const T &a_20, const T &a_21, const T &a_22, const T &a_23, const T &a_30, const T &a_31, const T &a_32, const T &a_33)
Definition: mat4:32
tools::mat4::v21
const T & v21() const
Definition: mat4:330
tools::mat4::v31
const T & v31() const
Definition: mat4:331
tools::mat4::v02
const T & v02() const
Definition: mat4:333
tools::mat4::v01
void v01(const T &a_value)
Definition: mat4:308
tools::mat4::mat4
mat4()
Definition: mat4:21
tools::mat4::v20
const T & v20() const
Definition: mat4:325
tools::mat4::mul_3
void mul_3(T &a_x, T &a_y, T &a_z) const
Definition: mat4:184
tools::mat4::v22
const T & v22() const
Definition: mat4:335
tools::mat4::mul_dir_3
void mul_dir_3(T &a_x, T &a_y, T &a_z) const
Definition: mat4:211
tools::mat4::v30
const T & v30() const
Definition: mat4:326
tools::mat4::set_ortho
void set_ortho(const T &a_l, const T &a_r, const T &a_b, const T &a_t, const T &a_n, const T &a_f)
Definition: mat4:64
tools::mat4::v00
void v00(const T &a_value)
Definition: mat4:303
tools::mat4
Definition: mat4:14
tools::mat4::mul_trans_3
void mul_trans_3(T &a_x, T &a_y, T &a_z) const
Definition: mat4:223
tools::set_matrix
void set_matrix(MATRIX &a_matrix, const std::string &a_fmt)
Definition: sprintf:100
tools::mat4::_set_translate
static void _set_translate(const T &a_x, const T &a_y, const T &a_z, T v[])
Definition: mat4:344
tools::mat4::v12
void v12(const T &a_value)
Definition: mat4:314
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::mat4::mul_scale
void mul_scale(const T &a_sx, const T &a_sy, const T &a_sz)
Definition: mat4:234
tools::mat4::~mat4
virtual ~mat4()
Definition: mat4:24
mat
tools::mat4::v31
void v31(const T &a_value)
Definition: mat4:311
tools::mat
Definition: mat:19
tools::mat4_zero
const mat4< T > & mat4_zero()
common matrices : //////////////////////////
Definition: mat4:479
tools::mat4::v21
void v21(const T &a_value)
Definition: mat4:310
tools::mat4::v00
const T & v00() const
Definition: mat4:323
tools::mat4::v01
const T & v01() const
Definition: mat4:328
tools::mat4::_set_scale
static void _set_scale(const T &a_1, const T &a_2, const T &a_3, T v[])
Definition: mat4:351
tools::operator<<
std::ostream & operator<<(std::ostream &a_out, const mat3< T > &a_mtx)
Definition: mat3:226
tools::mat4::mul_rotate
void mul_rotate(const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
Definition: mat4:279
tools::mat4::set_scale
void set_scale(const T &a_s)
Definition: mat4:58
tools::mat4::mul_mtx_rot_root
void mul_mtx_rot_root(const T &a_00, const T &a_01, const T &a_02, const T &a_10, const T &a_11, const T &a_12, const T &a_20, const T &a_21, const T &a_22)
Definition: mat4:394
tools::mat4::set_scale
void set_scale(const T &a_1, const T &a_2, const T &a_3)
Definition: mat4:59
tools::mat< T, 4 >::operator=
mat & operator=(const mat &a_from)
Definition: mat:64
tools::mat4::no_translate
void no_translate()
Definition: mat4:155
tools::mat4::v32
void v32(const T &a_value)
Definition: mat4:316
tools::mat4::v13
void v13(const T &a_value)
Definition: mat4:319
tools::mat4::get_translate
void get_translate(T &a_x, T &a_y, T &a_z) const
Definition: mat4:149
tools::mat4::set_matrix
void set_matrix(const T &a_00, const T &a_01, const T &a_02, const T &a_03, const T &a_10, const T &a_11, const T &a_12, const T &a_13, const T &a_20, const T &a_21, const T &a_22, const T &a_23, const T &a_30, const T &a_31, const T &a_32, const T &a_33)
Definition: mat4:44
tools::mat4::_set_rotate
static void _set_rotate(const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T v[], T(*a_sin)(T), T(*a_cos)(T))
Definition: mat4:358