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 (the near clip plane is \(z=-1\)). Define GLM_FORCE_DEPTH_ZERO_TO_ONE to use \([0,1]\) clip space by default (the near clip plane is \(z=0\)).
Functions that are affected by this setting are:
frustum,frustumRH,frustumLHortho(for 3-dim),orthoRH,orthoLHperspective,perspectiveRH,perspectiveLHperspectiveFov,perspectiveFovRH,perspectiveFovLHprojectunProject
The _NO and _ZO variants of functions have the relation that \[
\mathit{foo}\mathtt{\_ZO}(\mathit{args})
=\begin{pmatrix}1&&&\\&1&&\\&&1/2&1/2\\&&&1\end{pmatrix}
\mathit{foo}\mathtt{\_NO}(\mathit{args}).
\]
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
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}(\mathsf{center}-\mathsf{eye}), \\ s&:=\operatorname{normalize}(f\times\mathsf{up}), \\ u&:=s\times f. \end{aligned}\]
- Returns \(\begin{pmatrix} s_x & s_y & s_z & -s\cdot \mathsf{eye} \\ u_x & u_y & u_z & -u\cdot \mathsf{eye} \\ -f_x & -f_y & -f_z & f\cdot \mathsf{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-\mathsf{eye})\\u\cdot(v-\mathsf{eye})\\-f\cdot(v-\mathsf{eye})\end{pmatrix}. \end{array}\]
lookAtLH(tvec3 eye, tvec3 center, tvec3 up) -> tmat4x4- Let \[\begin{aligned} f&:=\operatorname{normalize}(\mathsf{center}-\mathsf{eye}), \\ s&:=\operatorname{normalize}(\mathsf{up}\times f), \\ u&:=f\times s. \end{aligned}\]
- Returns \(\begin{pmatrix} s_x & s_y & s_z & -s\cdot \mathsf{eye} \\ u_x & u_y & u_z & -u\cdot \mathsf{eye} \\ f_x & f_y & f_z & -f\cdot \mathsf{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-\mathsf{eye})\\u\cdot(v-\mathsf{eye})\\f\cdot(v-\mathsf{eye})\end{pmatrix}. \end{array}\]
Projection (from view coordinates to clip coordinates)
frustum
frustum(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>
- Typical invocation of this function satisfy
left < right && bottom < top && 0 < near && near < far. frustum: Alias forfrustumRH_NO,frustumRH_ZO,frustumLH_NO, orfrustumLH_ZO.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\mathsf{near}}{\mathsf{right}-\mathsf{left}} & 0 & \frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} & 0 \\ 0 & \frac{2\mathsf{near}}{\mathsf{top}-\mathsf{bottom}} & \frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} & 0 \\ 0 & 0 & -\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
- This matrix corresponds to the map \[\begin{array}{ccc} \mathbf{R}^3 & \to & \mathbf{R}^3 \\ \begin{pmatrix}x\\y\\z\end{pmatrix} & \mapsto & \begin{pmatrix} \frac{2\mathsf{near}}{\mathsf{right}-\mathsf{left}}\left(-\frac{x}{z}\right)-\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ \frac{2\mathsf{near}}{\mathsf{top}-\mathsf{bottom}}\left(-\frac{y}{z}\right)-\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ \frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}}\frac{1}{z}+\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} \end{pmatrix}. \end{array}\]
- Legacy OpenGL counterpart: glFrustum
frustumRH_ZO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2\mathsf{near}}{\mathsf{right}-\mathsf{left}} & 0 & \frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} & 0 \\ 0 & \frac{2\mathsf{near}}{\mathsf{top}-\mathsf{bottom}} & \frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} & 0 \\ 0 & 0 & -\frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
frustumLH_NO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2\mathsf{near}}{\mathsf{right}-\mathsf{left}} & 0 & \frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} & 0 \\ 0 & \frac{2\mathsf{near}}{\mathsf{top}-\mathsf{bottom}} & \frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} & 0 \\ 0 & 0 & \frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
- TODO: Are the signs of \(\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}}\) and \(\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}}\) correct?
frustumLH_ZO(T left, T right, T bottom, T top, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2\mathsf{near}}{\mathsf{right}-\mathsf{left}} & 0 & \frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} & 0 \\ 0 & \frac{2\mathsf{near}}{\mathsf{top}-\mathsf{bottom}} & \frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} & 0 \\ 0 & 0 & \frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
ortho (2-dim)
ortho(T left, T right, T bottom, T top) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathsf{right}-\mathsf{left}} & 0 & 0 & -\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ 0 & \frac{2}{\mathsf{top}-\mathsf{bottom}} & 0 & -\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
- Legacy OpenGL counterpart: gluOrtho2D
ortho (3-dim)
ortho(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>
- Typical invocation of this function satisfy
left < right && bottom < top && 0 < zNear && zNear < zFar. ortho: Alias fororthoRH_NO,orthoRH_ZO,orthoLH_NO, ororthoLH_ZO.orthoRH: Alias fororthoRH_NOororthoRH_ZO.orthoLH: Alias fororthoLH_NOororthoLH_ZO.orthoNO: Alias fororthoRH_NOororthoLH_NO.orthoZO: Alias fororthoRH_NOororthoLH_NO.orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathsf{right}-\mathsf{left}} & 0 & 0 & -\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ 0 & \frac{2}{\mathsf{top}-\mathsf{bottom}} & 0 & -\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ 0 & 0 & -\frac{2}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
- Legacy OpenGL counterpart: glOrtho
orthoRH_ZO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathsf{right}-\mathsf{left}} & 0 & 0 & -\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ 0 & \frac{2}{\mathsf{top}-\mathsf{bottom}} & 0 & -\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ 0 & 0 & -\frac{1}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
orthoLH_NO(T left, T right, T bottom, T top, T zNear, T zFar) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{2}{\mathsf{right}-\mathsf{left}} & 0 & 0 & -\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ 0 & \frac{2}{\mathsf{top}-\mathsf{bottom}} & 0 & -\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ 0 & 0 & \frac{2}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{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}{\mathsf{right}-\mathsf{left}} & 0 & 0 & -\frac{\mathsf{right}+\mathsf{left}}{\mathsf{right}-\mathsf{left}} \\ 0 & \frac{2}{\mathsf{top}-\mathsf{bottom}} & 0 & -\frac{\mathsf{top}+\mathsf{bottom}}{\mathsf{top}-\mathsf{bottom}} \\ 0 & 0 & \frac{1}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 0 & 1 \end{pmatrix}\).
perspective
perspective(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>
- Typical invocation of this function satisfy
fovy > 0 && aspect > 0 && 0 < near && near < far. - The “field of view” angle
fovyis in radians. - Equivalent to
frustum(-w/2, w/2, -h/2, h/2, near, far), where \(h=2\cdot\mathsf{near}\cdot\tan(\mathsf{fovy}/2)\), \(w=\mathsf{aspect}\cdot h\). perspective: Alias forperspectiveRH_NO,perspectiveRH_ZO,perspectiveLH_NOorperspectiveLH_ZO.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}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & -\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
- Legacy OpenGL counterpart: gluPerspective
perspectiveRH_ZO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & -\frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
perspectiveLH_NO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & \frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
perspectiveLH_ZO(T fovy, T aspect, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & \frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
perspectiveFov
perspectiveFov(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>
- Precondition:
width > 0 && height > 0 && fov > 0 - The “field of view” angle
fovyis in radians. - Equivalent to
perspective(fov, height / width, near, far). perspectiveFov: Alias forperspectiveFovRH_NO,perspectiveFovRH_ZO,perspectiveFovLH_NOorperspectiveFovLH_ZO.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>- Returns \(\begin{pmatrix} \frac{\mathsf{height}}{\mathsf{width}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & -\frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
perspectiveFovRH_ZO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{\mathsf{height}}{\mathsf{width}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & -\frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
perspectiveFovLH_NO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{\mathsf{height}}{\mathsf{width}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & \frac{\mathsf{far}+\mathsf{near}}{\mathsf{far}-\mathsf{near}} & -\frac{2\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
perspectiveFovLH_ZO(T fovy, T width, T height, T near, T far) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{\mathsf{height}}{\mathsf{width}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & \frac{\mathsf{far}}{\mathsf{far}-\mathsf{near}} & -\frac{\mathsf{far}\cdot\mathsf{near}}{\mathsf{far}-\mathsf{near}} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
infinitePerspective
infinitePerspective(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>
- The “field of view” angle
fovyis in radians. - (There is no variant for \([0,1]\) clipping?)
infinitePerspective: Alias forinfinitePerspectiveRHorinfinitePerspectiveLH.infinitePerspectiveRH(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & -1 & -2\mathsf{near} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
infinitePerspectiveLH(T fovy, T aspect, T near) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & 1 & -2\mathsf{near} \\ 0 & 0 & 1 & 0 \end{pmatrix}\).
tweakedInfinitePerspective(T fovy, T aspect, T near, T ep = epsilon<T>()) -> mat<4, 4, T, defaultp>- Returns \(\begin{pmatrix} \frac{1}{\mathsf{aspect}\cdot\tan(\mathsf{fovy}/2)} & 0 & 0 & 0 \\ 0 & \frac{1}{\tan(\mathsf{fovy}/2)} & 0 & 0 \\ 0 & 0 & \varepsilon-1 & (\varepsilon-2)\mathsf{near} \\ 0 & 0 & -1 & 0 \end{pmatrix}\).
Miscellaneous functions
pickMatrix
pickMatrix(tvec2 center, tvec2 delta, vec<4, U, Q> viewport) -> tmat4x4- Define a picking region.
centeris the center of the picking region anddeltais the width and height of the region, both in window coordinates.- Precondition:
delta.x > 0 && delta.y > 0 viewportis the window coordinates \((v_x,v_y,v_{\mathsf{width}},v_{\mathsf{height}})\) for the viewport.Ucan be a floating-point type or an integer type.- Returns \(\begin{pmatrix} \frac{v_{\mathsf{width}}}{\mathsf{delta}_x} & & & \frac{v_{\mathsf{width}}+2(v_x-\mathsf{center}_x)}{\mathsf{delta}_x} \\ & \frac{v_{\mathsf{height}}}{\mathsf{delta}_y} & & \frac{v_{\mathsf{height}}+2(v_y-\mathsf{center}_y)}{\mathsf{delta}_y} \\ & & 1 & \\ & & & 1 \end{pmatrix}\), which is the matrix representation of the affine map \[\begin{array}{ccccc} \mathbf{R}^3 & \to & \mathbf{R}^3 & \to & \mathbf{R}^3 \\ \begin{pmatrix}x\\y\\z\end{pmatrix} & \mapsto & \begin{pmatrix} v_{\mathsf{width}}\frac{x+1}{2}+v_x \\ v_{\mathsf{height}}\frac{y+1}{2}+v_y \\ z \end{pmatrix}=:\begin{pmatrix}\mathsf{win}_x\\\mathsf{win}_y\\z\end{pmatrix} & \mapsto & \begin{pmatrix} \frac{2(\mathsf{win}_x-\mathsf{center}_x)}{\mathsf{delta}_x} \\ \frac{2(\mathsf{win}_y-\mathsf{center}_y)}{\mathsf{delta}_y} \\ z \end{pmatrix}. \\ \text{(clip coords)} & & \text{(window coords)} & & \text{(clip coords)} \end{array}\]
- Legacy OpenGL counterpart: gluPickMatrix
project
project(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) -> tvec3viewportis the window coordinates \((v_x,v_y,v_{\mathsf{width}},v_{\mathsf{height}})\) for the viewport.Ucan be a floating-point type or an integer type.- Let \(\begin{pmatrix}x\\y\\z\\w\end{pmatrix}:=\mathsf{proj}\cdot\mathsf{model}\cdot\begin{pmatrix}\mathsf{obj}\\1\end{pmatrix}\).
- Returns \(\begin{pmatrix}v_{\mathsf{width}}\frac{x/w+1}{2}+v_x\\v_{\mathsf{height}}\frac{y/w+1}{2}+v_y\\\frac{z/w+1}{2}\end{pmatrix}\).
- Legacy OpenGL counterpart: gluProject
projectZO(tvec3 obj, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3viewportis the window coordinates \((v_x,v_y,v_{\mathsf{width}},v_{\mathsf{height}})\) for the viewport.Ucan be a floating-point type or an integer type.- Let \(\begin{pmatrix}x\\y\\z\\w\end{pmatrix}:=\mathsf{proj}\cdot\mathsf{model}\cdot\begin{pmatrix}\mathsf{obj}\\1\end{pmatrix}\).
- Returns \(\begin{pmatrix}v_{\mathsf{width}}\frac{x/w+1}{2}+v_x\\v_{\mathsf{height}}\frac{y/w+1}{2}+v_y\\z/w\end{pmatrix}\).
unProject
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) -> tvec3viewportis the window coordinates \((v_x,v_y,v_{\mathsf{width}},v_{\mathsf{height}})\) for the viewport.Ucan be a floating-point type or an integer type.- Returns \(\mathsf{model}^{-1}\cdot\mathsf{proj}^{-1}\begin{pmatrix} \frac{2(\mathsf{win}_x-v_x)}{v_{\mathsf{width}}}-1 \\ \frac{2(\mathsf{win}_y-v_y)}{v_{\mathsf{height}}}-1 \\ 2\mathsf{win}_z-1 \\ 1\end{pmatrix}.\)
- Legacy OpenGL counterpart: gluUnProject
unProjectZO(tvec3 win, tmat4x4 model, tmat4x4 proj, vec<4, U, Q> viewport) -> tvec3viewportis the window coordinates \((v_x,v_y,v_{\mathsf{width}},v_{\mathsf{height}})\) for the viewport.Ucan be a floating-point type or an integer type.- Returns \(\mathsf{model}^{-1}\cdot\mathsf{proj}^{-1}\begin{pmatrix} \frac{2(\mathsf{win}_x-v_x)}{v_{\mathsf{width}}}-1 \\ \frac{2(\mathsf{win}_y-v_y)}{v_{\mathsf{height}}}-1 \\ \mathsf{win}_z \\ 1\end{pmatrix}.\)