matrix_transform_2d.inl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /// @ref gtx_matrix_transform_2d
  2. /// @author Miguel Ángel Pérez Martínez
  3. #include "../trigonometric.hpp"
  4. namespace glm
  5. {
  6. template<typename T, qualifier Q>
  7. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> translate(
  8. mat<3, 3, T, Q> const& m,
  9. vec<2, T, Q> const& v)
  10. {
  11. mat<3, 3, T, Q> Result(m);
  12. Result[2] = m[0] * v[0] + m[1] * v[1] + m[2];
  13. return Result;
  14. }
  15. template<typename T, qualifier Q>
  16. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> rotate(
  17. mat<3, 3, T, Q> const& m,
  18. T angle)
  19. {
  20. T const a = angle;
  21. T const c = cos(a);
  22. T const s = sin(a);
  23. mat<3, 3, T, Q> Result;
  24. Result[0] = m[0] * c + m[1] * s;
  25. Result[1] = m[0] * -s + m[1] * c;
  26. Result[2] = m[2];
  27. return Result;
  28. }
  29. template<typename T, qualifier Q>
  30. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> scale(
  31. mat<3, 3, T, Q> const& m,
  32. vec<2, T, Q> const& v)
  33. {
  34. mat<3, 3, T, Q> Result;
  35. Result[0] = m[0] * v[0];
  36. Result[1] = m[1] * v[1];
  37. Result[2] = m[2];
  38. return Result;
  39. }
  40. template<typename T, qualifier Q>
  41. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> shearX(
  42. mat<3, 3, T, Q> const& m,
  43. T y)
  44. {
  45. mat<3, 3, T, Q> Result(1);
  46. Result[0][1] = y;
  47. return m * Result;
  48. }
  49. template<typename T, qualifier Q>
  50. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> shearY(
  51. mat<3, 3, T, Q> const& m,
  52. T x)
  53. {
  54. mat<3, 3, T, Q> Result(1);
  55. Result[1][0] = x;
  56. return m * Result;
  57. }
  58. }//namespace glm