Advertisement
WeltEnSTurm

Untitled

Sep 9th, 2011
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1.  
  2. template<typename T>
  3. struct matrix4 {
  4.     T
  5.         x1, y1, z1, w1,
  6.         x2, y2, z2, w2,
  7.         x3, y3, z3, w3,
  8.         x4, y4, z4, w4;
  9.  
  10.     matrix4(const T* f){
  11.         x1 = f[0],  y1 = f[1],  z1 = f[2],  w1 = f[3];
  12.         x2 = f[4],  y2 = f[5],  z2 = f[6],  w2 = f[7];
  13.         x3 = f[8],  y3 = f[9],  z3 = f[10], w3 = f[11];
  14.         x4 = f[12], y4 = f[13], z4 = f[14], w4 = f[15];
  15.     }
  16.  
  17.     static const matrix4<T> identity(){
  18.         static matrix4<T> id = {
  19.             1, 0, 0, 0,
  20.             0, 1, 0, 0,
  21.             0, 0, 1, 0,
  22.             0, 0, 0, 1
  23.         };
  24.         return id;
  25.     };
  26. };
  27.  
  28. // Does not work.. it can't convert initializer list with int to a float one
  29. // It also doesn't work if I use a call to matrix4<T>() instead of the initializer list
  30.  
  31.  
  32. template<typename T>
  33. struct matrix4 {
  34.     T
  35.         x1, y1, z1, w1,
  36.         x2, y2, z2, w2,
  37.         x3, y3, z3, w3,
  38.         x4, y4, z4, w4;
  39.  
  40.     matrix4(const T* f){
  41.         x1 = f[0],  y1 = f[1],  z1 = f[2],  w1 = f[3];
  42.         x2 = f[4],  y2 = f[5],  z2 = f[6],  w2 = f[7];
  43.         x3 = f[8],  y3 = f[9],  z3 = f[10], w3 = f[11];
  44.         x4 = f[12], y4 = f[13], z4 = f[14], w4 = f[15];
  45.     }
  46.  
  47.     static const matrix4<T> identity(){
  48.         static matrix4<T> id = matrix4<T>(
  49.             T(1), T(0), T(0), T(0),
  50.             T(0), T(1), T(0), T(0),
  51.             T(0), T(0), T(1), T(0),
  52.             T(0), T(0), T(0), T(1)
  53.         );
  54.         return id;
  55.     };
  56. };
  57.  
  58. // This also doesn't work. Neither with initializer list or 'constructor'.
  59. // Complains that it doesn't know a constructor that takes lots of floats
  60.  
  61.  
  62. template<typename T>
  63. struct matrix4 {
  64.     T
  65.         x1, y1, z1, w1,
  66.         x2, y2, z2, w2,
  67.         x3, y3, z3, w3,
  68.         x4, y4, z4, w4;
  69.  
  70.     matrix4(const T* f){
  71.         x1 = f[0],  y1 = f[1],  z1 = f[2],  w1 = f[3];
  72.         x2 = f[4],  y2 = f[5],  z2 = f[6],  w2 = f[7];
  73.         x3 = f[8],  y3 = f[9],  z3 = f[10], w3 = f[11];
  74.         x4 = f[12], y4 = f[13], z4 = f[14], w4 = f[15];
  75.     }
  76.  
  77.     static const matrix4<T> identity = {
  78.         1, 0, 0, 0,
  79.         0, 1, 0, 0,
  80.         0, 0, 1, 0,
  81.         0, 0, 0, 1 
  82.     };
  83. };
  84.  
  85. // Would of course be the most elegant solution, but guess what.. This one gives the most errors.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement