project.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. .. default-domain:: C
  2. Project / UnProject
  3. ================================================================================
  4. Header: cglm/project.h
  5. Viewport is required as *vec4* **[X, Y, Width, Height]** but this doesn't mean
  6. that you should store it as **vec4**. You can convert your data representation
  7. to vec4 before passing it to related functions.
  8. Table of contents (click to go):
  9. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. Functions:
  11. 1. :c:func:`glm_unprojecti`
  12. #. :c:func:`glm_unproject`
  13. #. :c:func:`glm_project`
  14. Functions documentation
  15. ~~~~~~~~~~~~~~~~~~~~~~~
  16. .. c:function:: void glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest)
  17. | maps the specified viewport coordinates into specified space [1]
  18. the matrix should contain projection matrix.
  19. if you don't have ( and don't want to have ) an inverse matrix then use
  20. :c:func:`glm_unproject` version. You may use existing inverse of matrix in somewhere
  21. else, this is why **glm_unprojecti** exists to save inversion cost
  22. [1] space:
  23. - if m = invProj: View Space
  24. - if m = invViewProj: World Space
  25. - if m = invMVP: Object Space
  26. You probably want to map the coordinates into object space
  27. so use invMVP as m
  28. Computing viewProj:
  29. .. code-block:: c
  30. glm_mat4_mul(proj, view, viewProj);
  31. glm_mat4_mul(viewProj, model, MVP);
  32. glm_mat4_inv(viewProj, invMVP);
  33. Parameters:
  34. | *[in]* **pos** point/position in viewport coordinates
  35. | *[in]* **invMat** matrix (see brief)
  36. | *[in]* **vp** viewport as [x, y, width, height]
  37. | *[out]* **dest** unprojected coordinates
  38. .. c:function:: void glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest)
  39. | maps the specified viewport coordinates into specified space [1]
  40. the matrix should contain projection matrix.
  41. this is same as :c:func:`glm_unprojecti` except this function get inverse matrix for
  42. you.
  43. [1] space:
  44. - if m = proj: View Space
  45. - if m = viewProj: World Space
  46. - if m = MVP: Object Space
  47. You probably want to map the coordinates into object space so use MVP as m
  48. Computing viewProj and MVP:
  49. .. code-block:: c
  50. glm_mat4_mul(proj, view, viewProj);
  51. glm_mat4_mul(viewProj, model, MVP);
  52. Parameters:
  53. | *[in]* **pos** point/position in viewport coordinates
  54. | *[in]* **m** matrix (see brief)
  55. | *[in]* **vp** viewport as [x, y, width, height]
  56. | *[out]* **dest** unprojected coordinates
  57. .. c:function:: void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest)
  58. | map object coordinates to window coordinates
  59. Computing MVP:
  60. .. code-block:: c
  61. glm_mat4_mul(proj, view, viewProj);
  62. glm_mat4_mul(viewProj, model, MVP);
  63. Parameters:
  64. | *[in]* **pos** object coordinates
  65. | *[in]* **m** MVP matrix
  66. | *[in]* **vp** viewport as [x, y, width, height]
  67. | *[out]* **dest** projected coordinates
  68. .. c:function:: float glm_project_z(vec3 pos, mat4 m)
  69. | map object's z coordinate to window coordinates
  70. this is same as :c:func:`glm_project` except this function projects only Z coordinate
  71. which reduces a few calculations and parameters.
  72. Computing MVP:
  73. .. code-block:: c
  74. glm_mat4_mul(proj, view, viewProj);
  75. glm_mat4_mul(viewProj, model, MVP);
  76. Parameters:
  77. | *[in]* **pos** object coordinates
  78. | *[in]* **m** MVP matrix
  79. Returns:
  80. projected z coordinate