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:
lookAt
frustum
,frustumNO
,frustumZO
ortho
(for 3-dim),orthoNO
,orthoZO
perspective
,perspectiveNO
,perspectiveZO
perspectiveFov
,perspectiveFovNO
,perspectiveFovZO
infinitePerspective
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
,frustumLH
ortho
(for 3-dim),orthoRH
,orthoLH
perspective
,perspectiveRH
,perspectiveLH
perspectiveFov
,perspectiveFovRH
,perspectiveFovLH
project
unProject
Rotation, scaling, and translation
rotate(tmat4x4 m, T angle, tvec3 axis) -> tmat4x4
scale(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
lookAtRH
orlookAtLH
. - 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_NO
orfrustumRH_ZO
.frustumLH
: Alias forfrustumLH_NO
orfrustumLH_ZO
.frustumNO
: Alias forfrustumRH_NO
orfrustumLH_NO
.frustumZO
: Alias forfrustumRH_ZO
orfrustumLH_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_NO
ororthoRH_ZO
.orthoLH
: Alias fororthoLH_NO
ororthoLH_ZO
.orthoNO
: Alias fororthoRH_NO
ororthoLH_NO
.orthoZO
: Alias fororthoRH_NO
ororthoLH_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_NO
orperspectiveLH_ZO
. - Legacy OpenGL counterpart: gluPerspective
- Alias for
perspectiveRH
: Alias forperspectiveRH_NO
orperspectiveRH_ZO
.perspectiveLH
: Alias forperspectiveLH_NO
orperspectiveLH_ZO
.perspectiveNO
: Alias forperspectiveRH_NO
orperspectiveLH_NO
.perspectiveZO
: Alias forperspectiveRH_ZO
orperspectiveLH_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_NO
orperspectiveFovLH_ZO
.
- Alias for
perspectiveFovRH
: Alias forperspectiveFovRH_NO
orperspectiveFovRH_ZO
.perspectiveFovLH
: Alias forperspectiveFovLH_NO
orperspectiveFovLH_ZO
.perspectiveFovNO
: Alias forperspectiveFovRH_NO
orperspectiveFovLH_NO
.perspectiveFovZO
: Alias forperspectiveFovRH_ZO
orperspectiveFovLH_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
infinitePerspectiveRH
orinfinitePerspectiveLH
.
- 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) -> tmat4x4
project(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3
- Alias for
projectNO
orprojectZO
.
- Alias for
projectNO(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3
projectZO(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3
tweakedInfinitePerspective(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
unProjectNO
orunprojectZO
.
- Alias for
unProjectNO(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3
unProjectZO(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3