Advertisement
nezvers

glmRip

Jun 1st, 2021
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. struct mat<4, 4, T, Q>
  2. {
  3. typedef vec<4, T, Q> col_type;
  4. typedef vec<4, T, Q> row_type;
  5. typedef mat<4, 4, T, Q> type;
  6. typedef mat<4, 4, T, Q> transpose_type;
  7. typedef T value_type;
  8. };
  9.  
  10. template<typename T, qualifier Q>
  11. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> rotate(mat<4, 4, T, Q> const& m, T angle, vec<3, T, Q> const& v)
  12. {
  13. T const a = angle;
  14. T const c = cos(a);
  15. T const s = sin(a);
  16.  
  17. vec<3, T, Q> axis(normalize(v));
  18. vec<3, T, Q> temp((T(1) - c) * axis);
  19.  
  20. mat<4, 4, T, Q> Rotate;
  21. Rotate[0][0] = c + temp[0] * axis[0];
  22. Rotate[0][1] = temp[0] * axis[1] + s * axis[2];
  23. Rotate[0][2] = temp[0] * axis[2] - s * axis[1];
  24.  
  25. Rotate[1][0] = temp[1] * axis[0] - s * axis[2];
  26. Rotate[1][1] = c + temp[1] * axis[1];
  27. Rotate[1][2] = temp[1] * axis[2] + s * axis[0];
  28.  
  29. Rotate[2][0] = temp[2] * axis[0] + s * axis[1];
  30. Rotate[2][1] = temp[2] * axis[1] - s * axis[0];
  31. Rotate[2][2] = c + temp[2] * axis[2];
  32.  
  33. mat<4, 4, T, Q> Result;
  34. Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
  35. Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
  36. Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
  37. Result[3] = m[3];
  38. return Result;
  39. }
  40.  
  41. struct compute_transpose<2, 2, T, Q, Aligned>
  42. {
  43. GLM_FUNC_QUALIFIER static mat<2, 2, T, Q> call(mat<2, 2, T, Q> const& m)
  44. {
  45. mat<2, 2, T, Q> Result;
  46. Result[0][0] = m[0][0];
  47. Result[0][1] = m[1][0];
  48. Result[1][0] = m[0][1];
  49. Result[1][1] = m[1][1];
  50. return Result;
  51. }
  52. };
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement