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