transform2.inl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /// @ref gtx_transform2
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> shearX2D(mat<3, 3, T, Q> const& m, T s)
  6. {
  7. mat<3, 3, T, Q> r(1);
  8. r[1][0] = s;
  9. return m * r;
  10. }
  11. template<typename T, qualifier Q>
  12. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> shearY2D(mat<3, 3, T, Q> const& m, T s)
  13. {
  14. mat<3, 3, T, Q> r(1);
  15. r[0][1] = s;
  16. return m * r;
  17. }
  18. template<typename T, qualifier Q>
  19. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shearX3D(mat<4, 4, T, Q> const& m, T s, T t)
  20. {
  21. mat<4, 4, T, Q> r(1);
  22. r[0][1] = s;
  23. r[0][2] = t;
  24. return m * r;
  25. }
  26. template<typename T, qualifier Q>
  27. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shearY3D(mat<4, 4, T, Q> const& m, T s, T t)
  28. {
  29. mat<4, 4, T, Q> r(1);
  30. r[1][0] = s;
  31. r[1][2] = t;
  32. return m * r;
  33. }
  34. template<typename T, qualifier Q>
  35. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shearZ3D(mat<4, 4, T, Q> const& m, T s, T t)
  36. {
  37. mat<4, 4, T, Q> r(1);
  38. r[2][0] = s;
  39. r[2][1] = t;
  40. return m * r;
  41. }
  42. template<typename T, qualifier Q>
  43. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> reflect2D(mat<3, 3, T, Q> const& m, vec<3, T, Q> const& normal)
  44. {
  45. mat<3, 3, T, Q> r(static_cast<T>(1));
  46. r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
  47. r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
  48. r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
  49. r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
  50. return m * r;
  51. }
  52. template<typename T, qualifier Q>
  53. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> reflect3D(mat<4, 4, T, Q> const& m, vec<3, T, Q> const& normal)
  54. {
  55. mat<4, 4, T, Q> r(static_cast<T>(1));
  56. r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
  57. r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
  58. r[0][2] = -static_cast<T>(2) * normal.x * normal.z;
  59. r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
  60. r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
  61. r[1][2] = -static_cast<T>(2) * normal.y * normal.z;
  62. r[2][0] = -static_cast<T>(2) * normal.x * normal.z;
  63. r[2][1] = -static_cast<T>(2) * normal.y * normal.z;
  64. r[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
  65. return m * r;
  66. }
  67. template<typename T, qualifier Q>
  68. GLM_FUNC_QUALIFIER mat<3, 3, T, Q> proj2D(
  69. const mat<3, 3, T, Q>& m,
  70. const vec<3, T, Q>& normal)
  71. {
  72. mat<3, 3, T, Q> r(static_cast<T>(1));
  73. r[0][0] = static_cast<T>(1) - normal.x * normal.x;
  74. r[0][1] = - normal.x * normal.y;
  75. r[1][0] = - normal.x * normal.y;
  76. r[1][1] = static_cast<T>(1) - normal.y * normal.y;
  77. return m * r;
  78. }
  79. template<typename T, qualifier Q>
  80. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> proj3D(
  81. const mat<4, 4, T, Q>& m,
  82. const vec<3, T, Q>& normal)
  83. {
  84. mat<4, 4, T, Q> r(static_cast<T>(1));
  85. r[0][0] = static_cast<T>(1) - normal.x * normal.x;
  86. r[0][1] = - normal.x * normal.y;
  87. r[0][2] = - normal.x * normal.z;
  88. r[1][0] = - normal.x * normal.y;
  89. r[1][1] = static_cast<T>(1) - normal.y * normal.y;
  90. r[1][2] = - normal.y * normal.z;
  91. r[2][0] = - normal.x * normal.z;
  92. r[2][1] = - normal.y * normal.z;
  93. r[2][2] = static_cast<T>(1) - normal.z * normal.z;
  94. return m * r;
  95. }
  96. template<typename T, qualifier Q>
  97. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> scaleBias(T scale, T bias)
  98. {
  99. mat<4, 4, T, Q> result;
  100. result[3] = vec<4, T, Q>(vec<3, T, Q>(bias), static_cast<T>(1));
  101. result[0][0] = scale;
  102. result[1][1] = scale;
  103. result[2][2] = scale;
  104. return result;
  105. }
  106. template<typename T, qualifier Q>
  107. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> scaleBias(mat<4, 4, T, Q> const& m, T scale, T bias)
  108. {
  109. return m * scaleBias(scale, bias);
  110. }
  111. }//namespace glm