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.

244 lines
6.4 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2005-12-21
  5. // Updated : 2007-08-14
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/euler_angles.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename valType>
  12. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleX
  13. (
  14. valType const & angleX
  15. )
  16. {
  17. valType cosX = glm::cos(angleX);
  18. valType sinX = glm::sin(angleX);
  19. return detail::tmat4x4<valType>(
  20. valType(1), valType(0), valType(0), valType(0),
  21. valType(0), cosX, sinX, valType(0),
  22. valType(0),-sinX, cosX, valType(0),
  23. valType(0), valType(0), valType(0), valType(1));
  24. }
  25. template <typename valType>
  26. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleY
  27. (
  28. valType const & angleY
  29. )
  30. {
  31. valType cosY = glm::cos(angleY);
  32. valType sinY = glm::sin(angleY);
  33. return detail::tmat4x4<valType>(
  34. cosY, valType(0),-sinY, valType(0),
  35. valType(0), valType(1), valType(0), valType(0),
  36. sinY, valType(0), cosY, valType(0),
  37. valType(0), valType(0), valType(0), valType(1));
  38. }
  39. template <typename valType>
  40. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleZ
  41. (
  42. valType const & angleZ
  43. )
  44. {
  45. valType cosZ = glm::cos(angleZ);
  46. valType sinZ = glm::sin(angleZ);
  47. return detail::tmat4x4<valType>(
  48. cosZ, sinZ, valType(0), valType(0),
  49. -sinZ, cosZ, valType(0), valType(0),
  50. valType(0), valType(0), valType(1), valType(0),
  51. valType(0), valType(0), valType(0), valType(1));
  52. }
  53. template <typename valType>
  54. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleXY
  55. (
  56. valType const & angleX,
  57. valType const & angleY
  58. )
  59. {
  60. valType cosX = glm::cos(angleX);
  61. valType sinX = glm::sin(angleX);
  62. valType cosY = glm::cos(angleY);
  63. valType sinY = glm::sin(angleY);
  64. return detail::tmat4x4<valType>(
  65. cosY, -sinX * sinY, cosX * sinY, valType(0),
  66. valType(0), cosX, sinX, valType(0),
  67. -sinY , -sinX * cosY, cosX * cosY, valType(0),
  68. valType(0), valType(0), valType(0), valType(1));
  69. }
  70. template <typename valType>
  71. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleYX
  72. (
  73. valType const & angleY,
  74. valType const & angleX
  75. )
  76. {
  77. valType cosX = glm::cos(angleX);
  78. valType sinX = glm::sin(angleX);
  79. valType cosY = glm::cos(angleY);
  80. valType sinY = glm::sin(angleY);
  81. return detail::tmat4x4<valType>(
  82. cosY, valType(0), sinY, valType(0),
  83. -sinX * sinY, cosX, sinX * cosY, valType(0),
  84. -cosX * sinY, -sinX, cosX * cosY, valType(0),
  85. valType(0), valType(0), valType(0), valType(1));
  86. }
  87. template <typename valType>
  88. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleXZ
  89. (
  90. valType const & angleX,
  91. valType const & angleZ
  92. )
  93. {
  94. return eulerAngleX(angleX) * eulerAngleZ(angleZ);
  95. }
  96. template <typename valType>
  97. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleZX
  98. (
  99. valType const & angleZ,
  100. valType const & angleX
  101. )
  102. {
  103. return eulerAngleZ(angleZ) * eulerAngleX(angleX);
  104. }
  105. template <typename valType>
  106. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> eulerAngleYXZ
  107. (
  108. valType const & yaw,
  109. valType const & pitch,
  110. valType const & roll
  111. )
  112. {
  113. valType tmp_ch = glm::cos(yaw);
  114. valType tmp_sh = glm::sin(yaw);
  115. valType tmp_cp = glm::cos(pitch);
  116. valType tmp_sp = glm::sin(pitch);
  117. valType tmp_cb = glm::cos(roll);
  118. valType tmp_sb = glm::sin(roll);
  119. detail::tmat4x4<valType> Result;
  120. Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb;
  121. Result[0][1] = tmp_sb * tmp_cp;
  122. Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb;
  123. Result[0][3] = valType(0);
  124. Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb;
  125. Result[1][1] = tmp_cb * tmp_cp;
  126. Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb;
  127. Result[1][3] = valType(0);
  128. Result[2][0] = tmp_sh * tmp_cp;
  129. Result[2][1] = -tmp_sp;
  130. Result[2][2] = tmp_ch * tmp_cp;
  131. Result[2][3] = valType(0);
  132. Result[3][0] = valType(0);
  133. Result[3][1] = valType(0);
  134. Result[3][2] = valType(0);
  135. Result[3][3] = valType(1);
  136. return Result;
  137. }
  138. template <typename valType>
  139. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> yawPitchRoll
  140. (
  141. valType const & yaw,
  142. valType const & pitch,
  143. valType const & roll
  144. )
  145. {
  146. valType tmp_ch = glm::cos(yaw);
  147. valType tmp_sh = glm::sin(yaw);
  148. valType tmp_cp = glm::cos(pitch);
  149. valType tmp_sp = glm::sin(pitch);
  150. valType tmp_cb = glm::cos(roll);
  151. valType tmp_sb = glm::sin(roll);
  152. detail::tmat4x4<valType> Result;
  153. Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb;
  154. Result[0][1] = tmp_sb * tmp_cp;
  155. Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb;
  156. Result[0][3] = valType(0);
  157. Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb;
  158. Result[1][1] = tmp_cb * tmp_cp;
  159. Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb;
  160. Result[1][3] = valType(0);
  161. Result[2][0] = tmp_sh * tmp_cp;
  162. Result[2][1] = -tmp_sp;
  163. Result[2][2] = tmp_ch * tmp_cp;
  164. Result[2][3] = valType(0);
  165. Result[3][0] = valType(0);
  166. Result[3][1] = valType(0);
  167. Result[3][2] = valType(0);
  168. Result[3][3] = valType(1);
  169. return Result;
  170. }
  171. template <typename valType>
  172. GLM_FUNC_QUALIFIER detail::tmat2x2<valType> orientate2
  173. (
  174. valType const & angle
  175. )
  176. {
  177. valType c = glm::cos(angle);
  178. valType s = glm::sin(angle);
  179. detail::tmat2x2<valType> Result;
  180. Result[0][0] = c;
  181. Result[0][1] = s;
  182. Result[1][0] = -s;
  183. Result[1][1] = c;
  184. return Result;
  185. }
  186. template <typename valType>
  187. GLM_FUNC_QUALIFIER detail::tmat3x3<valType> orientate3
  188. (
  189. valType const & angle
  190. )
  191. {
  192. valType c = glm::cos(angle);
  193. valType s = glm::sin(angle);
  194. detail::tmat3x3<valType> Result;
  195. Result[0][0] = c;
  196. Result[0][1] = s;
  197. Result[0][2] = 0.0f;
  198. Result[1][0] = -s;
  199. Result[1][1] = c;
  200. Result[1][2] = 0.0f;
  201. Result[2][0] = 0.0f;
  202. Result[2][1] = 0.0f;
  203. Result[2][2] = 1.0f;
  204. return Result;
  205. }
  206. template <typename valType>
  207. GLM_FUNC_QUALIFIER detail::tmat3x3<valType> orientate3
  208. (
  209. detail::tvec3<valType> const & angles
  210. )
  211. {
  212. return detail::tmat3x3<valType>(yawPitchRoll(angles.x, angles.y, angles.z));
  213. }
  214. template <typename valType>
  215. GLM_FUNC_QUALIFIER detail::tmat4x4<valType> orientate4
  216. (
  217. detail::tvec3<valType> const & angles
  218. )
  219. {
  220. return yawPitchRoll(angles.z, angles.x, angles.y);
  221. }
  222. }//namespace glm