GLM_GTC_matrix_transform
Header: <glm/gtc/matrix_transform.hpp>
In this page, tmat4x4 stands for mat<4, 4, T, Q>, tvec3 stands for vec<3, T, Q> and tvec2 stands for vec<2, T, Q>.
Some notes on the convention
Coordinate system
Some functions use right handed coordinates by default. Define GLM_FORCE_LEFT_HANDED before including GLM to use left handed coordinate system by default.
Functions that are affected by this setting are:
lookAtfrustum,frustumNO,frustumZOortho(for 3-dim),orthoNO,orthoZOperspective,perspectiveNO,perspectiveZOperspectiveFov,perspectiveFovNO,perspectiveFovZOinfinitePerspective
Clip control
Some functions use the clip space \([-1,1]\) by default. Define GLM_FORCE_DEPTH_ZERO_TO_ONE to use \([0,1]\) clip space by default.
Functions that are affected by this setting are:
frustum,frustumRH,frustumLHortho(for 3-dim),orthoRH,orthoLHperspective,perspectiveRH,perspectiveLHperspectiveFov,perspectiveFovRH,perspectiveFovLHprojectunProject
Rotation, scaling, and translation
rotate(tmat4x4 m, T angle, tvec3 axis) -> tmat4x4scale(tmat4x4 m, tvec3 v) -> tmat4x4- Returns \(m\cdot\begin{pmatrix} v_x & 0 & 0 & 0 \\ 0 & v_y & 0 & 0 \\ 0 & 0 & v_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
translate(tmat4x4 m, tvec3 v) -> tmat4x4- Returns \(m\cdot\begin{pmatrix} 1 & 0 & 0 & v_x \\ 0 & 1 & 0 & v_y \\ 0 & 0 & 1 & v_z \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
Viewing Transformation (from world coordinates to view coordinates)
lookAt(tvec3 eye, tvec3 center, tvec3 up) -> tmat4x4- Alias for
lookAtRHorlookAtLH. - Legacy OpenGL counterpart: gluLookAt
- Alias for
lookAtRH(tvec3 eye, tvec3 center, tvec3 up) -> tmat4x4- Let \[\begin{aligned} f&:=\operatorname{normalize}(\mathrm{center}-\mathrm{eye}), \\ s&:=\operatorname{normalize}(f\times\mathrm{up}), \\ u&:=s\times f. \end{aligned}\]
- Returns \(\begin{pmatrix} s_x & s_y & s_z & -s\cdot \mathrm{eye} \\ u_x & u_y & u_z & -u\cdot \mathrm{eye} \\ -f_x & -f_y & -f_z & f\cdot \mathrm{eye} \\ 0 & 0 & 0 & 1 \end{pmatrix}\), which is the matrix representation of the affine map \[\begin{array}{ccc} \mathbf{R}^3 & \to & \mathbf{R}^3 \\ v & \mapsto & \begin{pmatrix}s\cdot(v-\mathrm{eye})\\u\cdot(v-\mathrm{eye})\\-f\cdot(v-\mathrm{eye})\end{pmatrix}. \end{array}\]
lookAtLH(tvec3 eye, tvec3 center, tvec3 up) -> tmat4x4- Let \[\begin{aligned} f&:=\operatorname{normalize}(\mathrm{center}-\mathrm{eye}), \\ s&:=\operatorname{normalize}(\mathrm{up}\times f), \\ u&:=f\times s. \end{aligned}\]
- Returns \(\begin{pmatrix} s_x & s_y & s_z & -s\cdot \mathrm{eye} \\ u_x & u_y & u_z & -u\cdot \mathrm{eye} \\ f_x & f_y & f_z & f\cdot \mathrm{eye} \\ 0 & 0 & 0 & 1 \end{pmatrix}\), which is the matrix representation of the affine map \[\begin{array}{ccc} \mathbf{R}^3 & \to & \mathbf{R}^3 \\ v & \mapsto & \begin{pmatrix}s\cdot(v-\mathrm{eye})\\u\cdot(v-\mathrm{eye})\\f\cdot(v-\mathrm{eye})\end{pmatrix}. \end{array}\]
Projection (from view coordinates to clip coordinates)
frustum(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>- Alias for
frustumRH_NO,frustumRH_ZO,frustumLH_NO, orfrustumLH_ZO. - Legacy OpenGL counterpart: glFrustum
- Alias for
frustumRH: Alias forfrustumRH_NOorfrustumRH_ZO.frustumLH: Alias forfrustumLH_NOorfrustumLH_ZO.frustumNO: Alias forfrustumRH_NOorfrustumLH_NO.frustumZO: Alias forfrustumRH_ZOorfrustumLH_ZO.frustumRH_NO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2\mathrm{near}}{\mathrm{right}-\mathrm{left}} & 0 & \frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} & 0 \\ 0 & \frac{2\mathrm{near}}{\mathrm{top}-\mathrm{bottom}} & \frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} & 0 \\ 0 & 0 & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} & -\frac{2\mathrm{far}\cdot\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
frustumRH_ZO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>frustumLH_NO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>frustumLH_ZO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>ortho(T left, T right, T bottom, T top) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathrm{right}-\mathrm{left}} & 0 & 0 & -\frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} \\ 0 & \frac{2}{\mathrm{top}-\mathrm{bottom}} & 0 & -\frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} \\ 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
- Legacy OpenGL counterpart: gluOrtho2D
ortho(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Alias for
orthoRH_NO,orthoRH_ZO,orthoLH_NO, ororthoLH_ZO. - Legacy OpenGL counterpart: glOrtho
- Alias for
orthoRH: Alias fororthoRH_NOororthoRH_ZO.orthoLH: Alias fororthoLH_NOororthoLH_ZO.orthoNO: Alias fororthoRH_NOororthoLH_NO.orthoZO: Alias fororthoRH_NOororthoLH_NO.orthoLH_NO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathrm{right}-\mathrm{left}} & 0 & 0 & -\frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} \\ 0 & \frac{2}{\mathrm{top}-\mathrm{bottom}} & 0 & -\frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} \\ 0 & 0 & \frac{2}{\mathrm{far}-\mathrm{near}} & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
orthoLH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathrm{right}-\mathrm{left}} & 0 & 0 & -\frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} \\ 0 & \frac{2}{\mathrm{top}-\mathrm{bottom}} & 0 & -\frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} \\ 0 & 0 & \frac{1}{\mathrm{far}-\mathrm{near}} & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathrm{right}-\mathrm{left}} & 0 & 0 & -\frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} \\ 0 & \frac{2}{\mathrm{top}-\mathrm{bottom}} & 0 & -\frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} \\ 0 & 0 & -\frac{2}{\mathrm{far}-\mathrm{near}} & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
orthoRH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathrm{right}-\mathrm{left}} & 0 & 0 & -\frac{\mathrm{right}+\mathrm{left}}{\mathrm{right}-\mathrm{left}} \\ 0 & \frac{2}{\mathrm{top}-\mathrm{bottom}} & 0 & -\frac{\mathrm{top}+\mathrm{bottom}}{\mathrm{top}-\mathrm{bottom}} \\ 0 & 0 & -\frac{1}{\mathrm{far}-\mathrm{near}} & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
perspective(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>- Alias for
perspectiveRH_NO,perspectiveRH_ZO,perspectiveLH_NOorperspectiveLH_ZO. - Legacy OpenGL counterpart: gluPerspective
- Alias for
perspectiveRH: Alias forperspectiveRH_NOorperspectiveRH_ZO.perspectiveLH: Alias forperspectiveLH_NOorperspectiveLH_ZO.perspectiveNO: Alias forperspectiveRH_NOorperspectiveLH_NO.perspectiveZO: Alias forperspectiveRH_ZOorperspectiveLH_ZO.perspectiveRH_NO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathrm{aspect}\cdot\tan(\mathrm{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathrm{fovy}/2)} & 0 & 0 \\ 0 & 0 & -\frac{\mathrm{far}+\mathrm{near}}{\mathrm{far}-\mathrm{near}} & -\frac{2\mathrm{far}\cdot\mathrm{near}}{\mathrm{far}-\mathrm{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
perspectiveRH_ZO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>perspectiveLH_NO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>perspectiveLH_ZO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>perspectiveFov(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>- Alias for
perspectiveFovRH_NO,perspectiveFovRH_ZO,perspectiveFovLH_NOorperspectiveFovLH_ZO.
- Alias for
perspectiveFovRH: Alias forperspectiveFovRH_NOorperspectiveFovRH_ZO.perspectiveFovLH: Alias forperspectiveFovLH_NOorperspectiveFovLH_ZO.perspectiveFovNO: Alias forperspectiveFovRH_NOorperspectiveFovLH_NO.perspectiveFovZO: Alias forperspectiveFovRH_ZOorperspectiveFovLH_ZO.perspectiveFovRH_NO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>perspectiveFovRH_ZO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>perspectiveFovLH_NO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>perspectiveFovLH_ZO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>infinitePerspective(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>- Alias for
infinitePerspectiveRHorinfinitePerspectiveLH.
- Alias for
infinitePerspectiveRH(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>infinitePerspectiveLH(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>
???
pickMatrix(tvec2 center, tvec2 delta, vec<4, U, Q> viewport) -> tmat4x4project(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3- Alias for
projectNOorprojectZO.
- Alias for
projectNO(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3projectZO(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3tweakedInfinitePerspective(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>tweakedInfinitePerspective(T fovy, T aspect, T near, T ep) -> mat<4, 4, T, defaultp>unProject(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3- Alias for
unProjectNOorunprojectZO.
- Alias for
unProjectNO(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3unProjectZO(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3