mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
add docs for project/unproject
This commit is contained in:
@@ -41,6 +41,7 @@ Follow the :doc:`build` documentation for this
|
|||||||
vec4-ext
|
vec4-ext
|
||||||
color
|
color
|
||||||
plane
|
plane
|
||||||
|
project
|
||||||
util
|
util
|
||||||
io
|
io
|
||||||
call
|
call
|
||||||
|
102
docs/source/project.rst
Normal file
102
docs/source/project.rst
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
.. default-domain:: C
|
||||||
|
|
||||||
|
Project / UnProject
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
Header: cglm/project.h
|
||||||
|
|
||||||
|
Viewport is required as *vec4* **[X, Y, Width, Height]** but this doesn't mean
|
||||||
|
that you should store it as **vec4**. You can convert your data representation
|
||||||
|
to vec4 before passing it to related functions.
|
||||||
|
|
||||||
|
Table of contents (click to go):
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
|
||||||
|
1. :c:func:`glm_unprojecti`
|
||||||
|
#. :c:func:`glm_unproject`
|
||||||
|
#. :c:func:`glm_project`
|
||||||
|
|
||||||
|
Functions documentation
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. c:function:: void glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest)
|
||||||
|
|
||||||
|
| maps the specified viewport coordinates into specified space [1]
|
||||||
|
the matrix should contain projection matrix.
|
||||||
|
|
||||||
|
if you don't have ( and don't want to have ) an inverse matrix then use
|
||||||
|
glm_unproject version. You may use existing inverse of matrix in somewhere
|
||||||
|
else, this is why glm_unprojecti exists to save save inversion cost
|
||||||
|
|
||||||
|
[1] space:
|
||||||
|
- if m = invProj: View Space
|
||||||
|
- if m = invViewProj: World Space
|
||||||
|
- if m = invMVP: Object Space
|
||||||
|
|
||||||
|
You probably want to map the coordinates into object space
|
||||||
|
so use invMVP as m
|
||||||
|
|
||||||
|
Computing viewProj:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
glm_mat4_mul(proj, view, viewProj);
|
||||||
|
glm_mat4_mul(viewProj, model, MVP);
|
||||||
|
glm_mat4_inv(viewProj, invMVP);
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **pos** point/position in viewport coordinates
|
||||||
|
| *[in]* **invMat** matrix (see brief)
|
||||||
|
| *[in]* **vp** viewport as [x, y, width, height]
|
||||||
|
| *[out]* **dest** unprojected coordinates
|
||||||
|
|
||||||
|
.. c:function:: void glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest)
|
||||||
|
|
||||||
|
| maps the specified viewport coordinates into specified space [1]
|
||||||
|
the matrix should contain projection matrix.
|
||||||
|
|
||||||
|
this is same as glm_unprojecti except this function get inverse matrix for
|
||||||
|
you.
|
||||||
|
|
||||||
|
[1] space:
|
||||||
|
- if m = proj: View Space
|
||||||
|
- if m = viewProj: World Space
|
||||||
|
- if m = MVP: Object Space
|
||||||
|
|
||||||
|
You probably want to map the coordinates into object space so use MVP as m
|
||||||
|
|
||||||
|
Computing viewProj and MVP:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
glm_mat4_mul(proj, view, viewProj);
|
||||||
|
glm_mat4_mul(viewProj, model, MVP);
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **pos** point/position in viewport coordinates
|
||||||
|
| *[in]* **m** matrix (see brief)
|
||||||
|
| *[in]* **vp** viewport as [x, y, width, height]
|
||||||
|
| *[out]* **dest** unprojected coordinates
|
||||||
|
|
||||||
|
.. c:function:: void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest)
|
||||||
|
|
||||||
|
| map object coordinates to window coordinates
|
||||||
|
|
||||||
|
Computing MVP:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
glm_mat4_mul(proj, view, viewProj);
|
||||||
|
glm_mat4_mul(viewProj, model, MVP);
|
||||||
|
|
||||||
|
this could be useful for gettng a bbox which fits with view frustum and
|
||||||
|
object bounding boxes. In this case you crop view frustum box with objects
|
||||||
|
box
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **pos** object coordinates
|
||||||
|
| *[in]* **m** MVP matrix
|
||||||
|
| *[in]* **vp** viewport as [x, y, width, height]
|
||||||
|
| *[out]* **dest** projected coordinates
|
@@ -33,7 +33,7 @@
|
|||||||
* glm_mat4_mul(viewProj, model, MVP);
|
* glm_mat4_mul(viewProj, model, MVP);
|
||||||
* glm_mat4_inv(viewProj, invMVP);
|
* glm_mat4_inv(viewProj, invMVP);
|
||||||
*
|
*
|
||||||
* @param[in] pos viewport coordinates
|
* @param[in] pos point/position in viewport coordinates
|
||||||
* @param[in] invMat matrix (see brief)
|
* @param[in] invMat matrix (see brief)
|
||||||
* @param[in] vp viewport as [x, y, width, height]
|
* @param[in] vp viewport as [x, y, width, height]
|
||||||
* @param[out] dest unprojected coordinates
|
* @param[out] dest unprojected coordinates
|
||||||
@@ -72,7 +72,7 @@ glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
|
|||||||
* glm_mat4_mul(proj, view, viewProj);
|
* glm_mat4_mul(proj, view, viewProj);
|
||||||
* glm_mat4_mul(viewProj, model, MVP);
|
* glm_mat4_mul(viewProj, model, MVP);
|
||||||
*
|
*
|
||||||
* @param[in] pos viewport coordinates
|
* @param[in] pos point/position in viewport coordinates
|
||||||
* @param[in] m matrix (see brief)
|
* @param[in] m matrix (see brief)
|
||||||
* @param[in] vp viewport as [x, y, width, height]
|
* @param[in] vp viewport as [x, y, width, height]
|
||||||
* @param[out] dest unprojected coordinates
|
* @param[out] dest unprojected coordinates
|
||||||
|
Reference in New Issue
Block a user