Posted to tcl by auriocus at Sun Nov 26 14:39:12 GMT 2017view raw

  1. #include "cl.hpp" // OpenCL, here cl_float4 is defined
  2. typedef std::array<cl_float4, 4> mat4;
  3.  
  4. // Diagonal matrix
  5. mat4 diag(float xs, float ys, float zs, float ws) {
  6. return mat4 {{
  7. {xs, 0, 0, 0},
  8. {0, ys, 0, 0},
  9. {0, 0, zs, 0},
  10. {0, 0, 0, ws}
  11. }};
  12. }
  13.  
  14. // Unit matrix
  15. mat4 eye() {
  16. return diag(1, 1, 1, 1);
  17. }
  18.  
  19.  
  20. // Isotropic scaling
  21. mat4 scale(float s) {
  22. return diag(s, s, s, 1);
  23. }
  24.  
  25.  
  26. // Euler rotation matrices
  27. mat4 eulerz(float alpha) {
  28. float c = cos(alpha);
  29. float s = sin(alpha);
  30. return mat4 {{
  31. { c, s, 0, 0},
  32. {-s, c, 0, 0},
  33. { 0, 0, 1, 0},
  34. { 0, 0, 0, 1}
  35. }};
  36. }
  37.  
  38.