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.

291 lines
11 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref gtc_matrix_transform
  24. /// @file glm/gtc/matrix_transform.hpp
  25. /// @date 2009-04-29 / 2011-05-16
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see core (dependence)
  29. /// @see gtx_transform
  30. /// @see gtx_transform2
  31. ///
  32. /// @defgroup gtc_matrix_transform GLM_GTC_matrix_transform
  33. /// @ingroup gtc
  34. ///
  35. /// @brief Defines functions that generate common transformation matrices.
  36. ///
  37. /// The matrices generated by this extension use standard OpenGL fixed-function
  38. /// conventions. For example, the lookAt function generates a transform from world
  39. /// space into the specific eye space that the projective matrix functions
  40. /// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility
  41. /// specifications defines the particular layout of this eye space.
  42. ///
  43. /// <glm/gtc/matrix_transform.hpp> need to be included to use these functionalities.
  44. ///////////////////////////////////////////////////////////////////////////////////
  45. #ifndef GLM_GTC_matrix_transform
  46. #define GLM_GTC_matrix_transform GLM_VERSION
  47. // Dependency:
  48. #include "../glm.hpp"
  49. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  50. # pragma message("GLM: GLM_GTC_matrix_transform extension included")
  51. #endif
  52. namespace glm
  53. {
  54. /// @addtogroup gtc_matrix_transform
  55. /// @{
  56. /// Builds a translation 4 * 4 matrix created from a vector of 3 components.
  57. ///
  58. /// @param m Input matrix multiplied by this translation matrix.
  59. /// @param v Coordinates of a translation vector.
  60. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  61. /// @code
  62. /// #include <glm/glm.hpp>
  63. /// #include <glm/gtc/matrix_transform.hpp>
  64. /// ...
  65. /// glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));
  66. /// // m[0][0] == 1.0f, m[0][1] == 0.0f, m[0][2] == 0.0f, m[0][3] == 0.0f
  67. /// // m[1][0] == 0.0f, m[1][1] == 1.0f, m[1][2] == 0.0f, m[1][3] == 0.0f
  68. /// // m[2][0] == 0.0f, m[2][1] == 0.0f, m[2][2] == 1.0f, m[2][3] == 0.0f
  69. /// // m[3][0] == 1.0f, m[3][1] == 1.0f, m[3][2] == 1.0f, m[3][3] == 1.0f
  70. /// @endcode
  71. /// @see gtc_matrix_transform
  72. /// @see gtx_transform
  73. /// @see - translate(T x, T y, T z)
  74. /// @see - translate(detail::tmat4x4<T> const & m, T x, T y, T z)
  75. /// @see - translate(detail::tvec3<T> const & v)
  76. template <typename T>
  77. detail::tmat4x4<T> translate(
  78. detail::tmat4x4<T> const & m,
  79. detail::tvec3<T> const & v);
  80. /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
  81. ///
  82. /// @param m Input matrix multiplied by this rotation matrix.
  83. /// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
  84. /// @param axis Rotation axis, recommanded to be normalized.
  85. /// @tparam T Value type used to build the matrix. Supported: half, float or double.
  86. /// @see gtc_matrix_transform
  87. /// @see gtx_transform
  88. /// @see - rotate(T angle, T x, T y, T z)
  89. /// @see - rotate(detail::tmat4x4<T> const & m, T angle, T x, T y, T z)
  90. /// @see - rotate(T angle, detail::tvec3<T> const & v)
  91. template <typename T>
  92. detail::tmat4x4<T> rotate(
  93. detail::tmat4x4<T> const & m,
  94. T const & angle,
  95. detail::tvec3<T> const & axis);
  96. /// Builds a scale 4 * 4 matrix created from 3 scalars.
  97. ///
  98. /// @param m Input matrix multiplied by this scale matrix.
  99. /// @param v Ratio of scaling for each axis.
  100. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  101. /// @see gtc_matrix_transform
  102. /// @see gtx_transform
  103. /// @see - scale(T x, T y, T z) scale(T const & x, T const & y, T const & z)
  104. /// @see - scale(detail::tmat4x4<T> const & m, T x, T y, T z)
  105. /// @see - scale(detail::tvec3<T> const & v)
  106. template <typename T>
  107. detail::tmat4x4<T> scale(
  108. detail::tmat4x4<T> const & m,
  109. detail::tvec3<T> const & v);
  110. /// Creates a matrix for an orthographic parallel viewing volume.
  111. ///
  112. /// @param left
  113. /// @param right
  114. /// @param bottom
  115. /// @param top
  116. /// @param zNear
  117. /// @param zFar
  118. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  119. /// @see gtc_matrix_transform
  120. /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top)
  121. template <typename T>
  122. detail::tmat4x4<T> ortho(
  123. T const & left,
  124. T const & right,
  125. T const & bottom,
  126. T const & top,
  127. T const & zNear,
  128. T const & zFar);
  129. /// Creates a matrix for projecting two-dimensional coordinates onto the screen.
  130. ///
  131. /// @param left
  132. /// @param right
  133. /// @param bottom
  134. /// @param top
  135. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  136. /// @see gtc_matrix_transform
  137. /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top, T const & zNear, T const & zFar)
  138. template <typename T>
  139. detail::tmat4x4<T> ortho(
  140. T const & left,
  141. T const & right,
  142. T const & bottom,
  143. T const & top);
  144. /// Creates a frustum matrix.
  145. ///
  146. /// @param left
  147. /// @param right
  148. /// @param bottom
  149. /// @param top
  150. /// @param near
  151. /// @param far
  152. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  153. /// @see gtc_matrix_transform
  154. template <typename T>
  155. detail::tmat4x4<T> frustum(
  156. T const & left,
  157. T const & right,
  158. T const & bottom,
  159. T const & top,
  160. T const & near,
  161. T const & far);
  162. /// Creates a matrix for a symetric perspective-view frustum.
  163. ///
  164. /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
  165. /// @param aspect
  166. /// @param near
  167. /// @param far
  168. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  169. /// @see gtc_matrix_transform
  170. template <typename T>
  171. detail::tmat4x4<T> perspective(
  172. T const & fovy,
  173. T const & aspect,
  174. T const & near,
  175. T const & far);
  176. /// Builds a perspective projection matrix based on a field of view.
  177. ///
  178. /// @param fov Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
  179. /// @param width
  180. /// @param height
  181. /// @param near
  182. /// @param far
  183. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  184. /// @see gtc_matrix_transform
  185. template <typename valType>
  186. detail::tmat4x4<valType> perspectiveFov(
  187. valType const & fov,
  188. valType const & width,
  189. valType const & height,
  190. valType const & near,
  191. valType const & far);
  192. /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite.
  193. ///
  194. /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
  195. /// @param aspect
  196. /// @param near
  197. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  198. /// @see gtc_matrix_transform
  199. template <typename T>
  200. detail::tmat4x4<T> infinitePerspective(
  201. T fovy, T aspect, T near);
  202. /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping.
  203. ///
  204. /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
  205. /// @param aspect
  206. /// @param near
  207. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
  208. /// @see gtc_matrix_transform
  209. template <typename T>
  210. detail::tmat4x4<T> tweakedInfinitePerspective(
  211. T fovy, T aspect, T near);
  212. /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
  213. ///
  214. /// @param obj
  215. /// @param model
  216. /// @param proj
  217. /// @param viewport
  218. /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
  219. /// @tparam U Currently supported: Floating-point types and integer types.
  220. /// @see gtc_matrix_transform
  221. template <typename T, typename U>
  222. detail::tvec3<T> project(
  223. detail::tvec3<T> const & obj,
  224. detail::tmat4x4<T> const & model,
  225. detail::tmat4x4<T> const & proj,
  226. detail::tvec4<U> const & viewport);
  227. /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
  228. ///
  229. /// @param win
  230. /// @param model
  231. /// @param proj
  232. /// @param viewport
  233. /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
  234. /// @tparam U Currently supported: Floating-point types and integer types.
  235. /// @see gtc_matrix_transform
  236. template <typename T, typename U>
  237. detail::tvec3<T> unProject(
  238. detail::tvec3<T> const & win,
  239. detail::tmat4x4<T> const & model,
  240. detail::tmat4x4<T> const & proj,
  241. detail::tvec4<U> const & viewport);
  242. /// Define a picking region
  243. ///
  244. /// @param center
  245. /// @param delta
  246. /// @param viewport
  247. /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
  248. /// @tparam U Currently supported: Floating-point types and integer types.
  249. /// @see gtc_matrix_transform
  250. template <typename T, typename U>
  251. detail::tmat4x4<T> pickMatrix(
  252. detail::tvec2<T> const & center,
  253. detail::tvec2<T> const & delta,
  254. detail::tvec4<U> const & viewport);
  255. /// Build a look at view matrix.
  256. ///
  257. /// @param eye Position of the camera
  258. /// @param center Position where the camera is looking at
  259. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  260. /// @see gtc_matrix_transform
  261. /// @see - frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal)
  262. template <typename T>
  263. detail::tmat4x4<T> lookAt(
  264. detail::tvec3<T> const & eye,
  265. detail::tvec3<T> const & center,
  266. detail::tvec3<T> const & up);
  267. /// @}
  268. }//namespace glm
  269. #include "matrix_transform.inl"
  270. #endif//GLM_GTC_matrix_transform