matrix_transform.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /// @ref ext_matrix_transform
  2. /// @file glm/ext/matrix_transform.hpp
  3. ///
  4. /// @defgroup ext_matrix_transform GLM_EXT_matrix_transform
  5. /// @ingroup ext
  6. ///
  7. /// Defines functions that generate common transformation matrices.
  8. ///
  9. /// The matrices generated by this extension use standard OpenGL fixed-function
  10. /// conventions. For example, the lookAt function generates a transform from world
  11. /// space into the specific eye space that the projective matrix functions
  12. /// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility
  13. /// specifications defines the particular layout of this eye space.
  14. ///
  15. /// Include <glm/ext/matrix_transform.hpp> to use the features of this extension.
  16. ///
  17. /// @see ext_matrix_projection
  18. /// @see ext_matrix_clip_space
  19. #pragma once
  20. // Dependencies
  21. #include "../gtc/constants.hpp"
  22. #include "../geometric.hpp"
  23. #include "../trigonometric.hpp"
  24. #include "../matrix.hpp"
  25. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  26. # pragma message("GLM: GLM_EXT_matrix_transform extension included")
  27. #endif
  28. namespace glm
  29. {
  30. /// @addtogroup ext_matrix_transform
  31. /// @{
  32. /// Builds an identity matrix.
  33. template<typename genType>
  34. GLM_FUNC_DECL GLM_CONSTEXPR genType identity();
  35. /// Builds a translation 4 * 4 matrix created from a vector of 3 components.
  36. ///
  37. /// @param m Input matrix multiplied by this translation matrix.
  38. /// @param v Coordinates of a translation vector.
  39. ///
  40. /// @tparam T A floating-point scalar type
  41. /// @tparam Q A value from qualifier enum
  42. ///
  43. /// @code
  44. /// #include <glm/glm.hpp>
  45. /// #include <glm/gtc/matrix_transform.hpp>
  46. /// ...
  47. /// glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));
  48. /// // m[0][0] == 1.0f, m[0][1] == 0.0f, m[0][2] == 0.0f, m[0][3] == 0.0f
  49. /// // m[1][0] == 0.0f, m[1][1] == 1.0f, m[1][2] == 0.0f, m[1][3] == 0.0f
  50. /// // m[2][0] == 0.0f, m[2][1] == 0.0f, m[2][2] == 1.0f, m[2][3] == 0.0f
  51. /// // m[3][0] == 1.0f, m[3][1] == 1.0f, m[3][2] == 1.0f, m[3][3] == 1.0f
  52. /// @endcode
  53. ///
  54. /// @see - translate(mat<4, 4, T, Q> const& m, T x, T y, T z)
  55. /// @see - translate(vec<3, T, Q> const& v)
  56. /// @see <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml">glTranslate man page</a>
  57. template<typename T, qualifier Q>
  58. GLM_FUNC_DECL GLM_CONSTEXPR mat<4, 4, T, Q> translate(
  59. mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v);
  60. /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
  61. ///
  62. /// @param m Input matrix multiplied by this rotation matrix.
  63. /// @param angle Rotation angle expressed in radians.
  64. /// @param axis Rotation axis, recommended to be normalized.
  65. ///
  66. /// @tparam T A floating-point scalar type
  67. /// @tparam Q A value from qualifier enum
  68. ///
  69. /// @see - rotate(mat<4, 4, T, Q> const& m, T angle, T x, T y, T z)
  70. /// @see - rotate(T angle, vec<3, T, Q> const& v)
  71. /// @see <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glRotate.xml">glRotate man page</a>
  72. template<typename T, qualifier Q>
  73. GLM_FUNC_DECL mat<4, 4, T, Q> rotate(
  74. mat<4, 4, T, Q> const& m, T angle, vec<3, T, Q> const& axis);
  75. /// Builds a scale 4 * 4 matrix created from 3 scalars.
  76. ///
  77. /// @param m Input matrix multiplied by this scale matrix.
  78. /// @param v Ratio of scaling for each axis.
  79. ///
  80. /// @tparam T A floating-point scalar type
  81. /// @tparam Q A value from qualifier enum
  82. ///
  83. /// @see - scale(mat<4, 4, T, Q> const& m, T x, T y, T z)
  84. /// @see - scale(vec<3, T, Q> const& v)
  85. /// @see <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glScale.xml">glScale man page</a>
  86. template<typename T, qualifier Q>
  87. GLM_FUNC_DECL mat<4, 4, T, Q> scale(
  88. mat<4, 4, T, Q> const& m, vec<3, T, Q> const& v);
  89. /// Builds a scale 4 * 4 matrix created from point referent 3 shearers.
  90. ///
  91. /// @param m Input matrix multiplied by this shear matrix.
  92. /// @param p Point of shearing as reference.
  93. /// @param l_x Ratio of matrix.x projection in YZ plane relative to the y-axis/z-axis.
  94. /// @param l_y Ratio of matrix.y projection in XZ plane relative to the x-axis/z-axis.
  95. /// @param l_z Ratio of matrix.z projection in XY plane relative to the x-axis/y-axis.
  96. ///
  97. /// as example:
  98. /// [1 , l_xy, l_xz, -(l_xy+l_xz) * p_x] [x] T
  99. /// [x`, y`, z`, w`] = [x`, y`, z`, w`] * [l_yx, 1 , l_yz, -(l_yx+l_yz) * p_y] [y]
  100. /// [l_zx, l_zy, 1 , -(l_zx+l_zy) * p_z] [z]
  101. /// [0 , 0 , 0 , 1 ] [w]
  102. ///
  103. /// @tparam T A floating-point shear type
  104. /// @tparam Q A value from qualifier enum
  105. ///
  106. /// @see - shear(mat<4, 4, T, Q> const& m, T x, T y, T z)
  107. /// @see - shear(vec<3, T, Q> const& p)
  108. /// @see - shear(vec<2, T, Q> const& l_x)
  109. /// @see - shear(vec<2, T, Q> const& l_y)
  110. /// @see - shear(vec<2, T, Q> const& l_z)
  111. /// @see no resource...
  112. template <typename T, qualifier Q>
  113. GLM_FUNC_QUALIFIER mat<4, 4, T, Q> shear(
  114. mat<4, 4, T, Q> const &m, vec<3, T, Q> const& p, vec<2, T, Q> const &l_x, vec<2, T, Q> const &l_y, vec<2, T, Q> const &l_z);
  115. /// Build a right handed look at view matrix.
  116. ///
  117. /// @param eye Position of the camera
  118. /// @param center Position where the camera is looking at
  119. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  120. ///
  121. /// @tparam T A floating-point scalar type
  122. /// @tparam Q A value from qualifier enum
  123. ///
  124. /// @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)
  125. template<typename T, qualifier Q>
  126. GLM_FUNC_DECL mat<4, 4, T, Q> lookAtRH(
  127. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  128. /// Build a left handed look at view matrix.
  129. ///
  130. /// @param eye Position of the camera
  131. /// @param center Position where the camera is looking at
  132. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  133. ///
  134. /// @tparam T A floating-point scalar type
  135. /// @tparam Q A value from qualifier enum
  136. ///
  137. /// @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)
  138. template<typename T, qualifier Q>
  139. GLM_FUNC_DECL mat<4, 4, T, Q> lookAtLH(
  140. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  141. /// Build a look at view matrix based on the default handedness.
  142. ///
  143. /// @param eye Position of the camera
  144. /// @param center Position where the camera is looking at
  145. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  146. ///
  147. /// @tparam T A floating-point scalar type
  148. /// @tparam Q A value from qualifier enum
  149. ///
  150. /// @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)
  151. /// @see <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml">gluLookAt man page</a>
  152. template<typename T, qualifier Q>
  153. GLM_FUNC_DECL mat<4, 4, T, Q> lookAt(
  154. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  155. /// @}
  156. }//namespace glm
  157. #include "matrix_transform.inl"