matrix_transform.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 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. /// Build a right handed look at view matrix.
  90. ///
  91. /// @param eye Position of the camera
  92. /// @param center Position where the camera is looking at
  93. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  94. ///
  95. /// @tparam T A floating-point scalar type
  96. /// @tparam Q A value from qualifier enum
  97. ///
  98. /// @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)
  99. template<typename T, qualifier Q>
  100. GLM_FUNC_DECL mat<4, 4, T, Q> lookAtRH(
  101. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  102. /// Build a left handed look at view matrix.
  103. ///
  104. /// @param eye Position of the camera
  105. /// @param center Position where the camera is looking at
  106. /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
  107. ///
  108. /// @tparam T A floating-point scalar type
  109. /// @tparam Q A value from qualifier enum
  110. ///
  111. /// @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)
  112. template<typename T, qualifier Q>
  113. GLM_FUNC_DECL mat<4, 4, T, Q> lookAtLH(
  114. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  115. /// Build a look at view matrix based on the default handedness.
  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. /// @see <a href="https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml">gluLookAt man page</a>
  126. template<typename T, qualifier Q>
  127. GLM_FUNC_DECL mat<4, 4, T, Q> lookAt(
  128. vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up);
  129. /// @}
  130. }//namespace glm
  131. #include "matrix_transform.inl"