matrix_transform_2d.inl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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