You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.6 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2005-02-28
  5. // Updated : 2005-04-23
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/transform2.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename T>
  12. GLM_FUNC_QUALIFIER detail::tmat3x3<T> shearX2D(
  13. const detail::tmat3x3<T>& m,
  14. T s)
  15. {
  16. detail::tmat3x3<T> r(1);
  17. r[0][1] = s;
  18. return m * r;
  19. }
  20. template <typename T>
  21. GLM_FUNC_QUALIFIER detail::tmat3x3<T> shearY2D(
  22. const detail::tmat3x3<T>& m,
  23. T s)
  24. {
  25. detail::tmat3x3<T> r(1);
  26. r[1][0] = s;
  27. return m * r;
  28. }
  29. template <typename T>
  30. GLM_FUNC_QUALIFIER detail::tmat4x4<T> shearX3D(
  31. const detail::tmat4x4<T>& m,
  32. T s,
  33. T t)
  34. {
  35. detail::tmat4x4<T> r(1);
  36. r[1][0] = s;
  37. r[2][0] = t;
  38. return m * r;
  39. }
  40. template <typename T>
  41. GLM_FUNC_QUALIFIER detail::tmat4x4<T> shearY3D(
  42. const detail::tmat4x4<T>& m,
  43. T s,
  44. T t)
  45. {
  46. detail::tmat4x4<T> r(1);
  47. r[0][1] = s;
  48. r[2][1] = t;
  49. return m * r;
  50. }
  51. template <typename T>
  52. GLM_FUNC_QUALIFIER detail::tmat4x4<T> shearZ3D(
  53. const detail::tmat4x4<T>& m,
  54. T s,
  55. T t)
  56. {
  57. detail::tmat4x4<T> r(1);
  58. r[0][2] = s;
  59. r[1][2] = t;
  60. return m * r;
  61. }
  62. template <typename T>
  63. GLM_FUNC_QUALIFIER detail::tmat3x3<T> reflect2D(
  64. const detail::tmat3x3<T>& m,
  65. const detail::tvec3<T>& normal)
  66. {
  67. detail::tmat3x3<T> r(1);
  68. r[0][0] = 1 - 2 * normal.x * normal.x;
  69. r[0][1] = -2 * normal.x * normal.y;
  70. r[1][0] = -2 * normal.x * normal.y;
  71. r[1][1] = 1 - 2 * normal.y * normal.y;
  72. return m * r;
  73. }
  74. template <typename T>
  75. GLM_FUNC_QUALIFIER detail::tmat4x4<T> reflect3D(
  76. const detail::tmat4x4<T>& m,
  77. const detail::tvec3<T>& normal)
  78. {
  79. detail::tmat4x4<T> r(1);
  80. r[0][0] = 1 - 2 * normal.x * normal.x;
  81. r[0][1] = -2 * normal.x * normal.y;
  82. r[0][2] = -2 * normal.x * normal.z;
  83. r[1][0] = -2 * normal.x * normal.y;
  84. r[1][1] = 1 - 2 * normal.y * normal.y;
  85. r[1][2] = -2 * normal.y * normal.z;
  86. r[2][0] = -2 * normal.x * normal.z;
  87. r[2][1] = -2 * normal.y * normal.z;
  88. r[2][2] = 1 - 2 * normal.z * normal.z;
  89. return m * r;
  90. }
  91. template <typename T>
  92. GLM_FUNC_QUALIFIER detail::tmat3x3<T> proj2D(
  93. const detail::tmat3x3<T>& m,
  94. const detail::tvec3<T>& normal)
  95. {
  96. detail::tmat3x3<T> r(1);
  97. r[0][0] = 1 - normal.x * normal.x;
  98. r[0][1] = - normal.x * normal.y;
  99. r[1][0] = - normal.x * normal.y;
  100. r[1][1] = 1 - normal.y * normal.y;
  101. return m * r;
  102. }
  103. template <typename T>
  104. GLM_FUNC_QUALIFIER detail::tmat4x4<T> proj3D(
  105. const detail::tmat4x4<T>& m,
  106. const detail::tvec3<T>& normal)
  107. {
  108. detail::tmat4x4<T> r(1);
  109. r[0][0] = 1 - normal.x * normal.x;
  110. r[0][1] = - normal.x * normal.y;
  111. r[0][2] = - normal.x * normal.z;
  112. r[1][0] = - normal.x * normal.y;
  113. r[1][1] = 1 - normal.y * normal.y;
  114. r[1][2] = - normal.y * normal.z;
  115. r[2][0] = - normal.x * normal.z;
  116. r[2][1] = - normal.y * normal.z;
  117. r[2][2] = 1 - normal.z * normal.z;
  118. return m * r;
  119. }
  120. template <typename T>
  121. GLM_FUNC_QUALIFIER detail::tmat4x4<T> scaleBias(
  122. T scale,
  123. T bias)
  124. {
  125. detail::tmat4x4<T> result;
  126. result[3] = detail::tvec4<T>(detail::tvec3<T>(bias), T(1));
  127. result[0][0] = scale;
  128. result[1][1] = scale;
  129. result[2][2] = scale;
  130. return result;
  131. }
  132. template <typename T>
  133. GLM_FUNC_QUALIFIER detail::tmat4x4<T> scaleBias(
  134. const detail::tmat4x4<T>& m,
  135. T scale,
  136. T bias)
  137. {
  138. return m * scaleBias(scale, bias);
  139. }
  140. }//namespace glm