cam.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. .. default-domain:: C
  2. camera
  3. ======
  4. Header: cglm/cam.h
  5. There are many convenient functions for camera. For instance :c:func:`glm_look`
  6. is just wrapper for :c:func:`glm_lookat`. Sometimes you only have direction
  7. instead of target, so that makes easy to build view matrix using direction.
  8. There is also :c:func:`glm_look_anyup` function which can help build view matrix
  9. without providing UP axis. It uses :c:func:`glm_vec3_ortho` to get a UP axis and
  10. builds view matrix.
  11. You can also *_default* versions of ortho and perspective to build projection
  12. fast if you don't care specific projection values.
  13. *_decomp* means decompose; these function can help to decompose projection
  14. matrices.
  15. **NOTE**: Be careful when working with high range (very small near, very large
  16. far) projection matrices. You may not get exact value you gave.
  17. **float** type cannot store very high precision so you will lose precision.
  18. Also your projection matrix will be inaccurate due to losing precision
  19. Table of contents (click to go):
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. Functions:
  22. 1. :c:func:`glm_frustum`
  23. #. :c:func:`glm_ortho`
  24. #. :c:func:`glm_ortho_aabb`
  25. #. :c:func:`glm_ortho_aabb_p`
  26. #. :c:func:`glm_ortho_aabb_pz`
  27. #. :c:func:`glm_ortho_default`
  28. #. :c:func:`glm_ortho_default_s`
  29. #. :c:func:`glm_perspective`
  30. #. :c:func:`glm_perspective_default`
  31. #. :c:func:`glm_perspective_resize`
  32. #. :c:func:`glm_lookat`
  33. #. :c:func:`glm_look`
  34. #. :c:func:`glm_look_anyup`
  35. #. :c:func:`glm_persp_decomp`
  36. #. :c:func:`glm_persp_decompv`
  37. #. :c:func:`glm_persp_decomp_x`
  38. #. :c:func:`glm_persp_decomp_y`
  39. #. :c:func:`glm_persp_decomp_z`
  40. #. :c:func:`glm_persp_decomp_far`
  41. #. :c:func:`glm_persp_decomp_near`
  42. #. :c:func:`glm_persp_fovy`
  43. #. :c:func:`glm_persp_aspect`
  44. #. :c:func:`glm_persp_sizes`
  45. Functions documentation
  46. ~~~~~~~~~~~~~~~~~~~~~~~
  47. .. c:function:: void glm_frustum(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest)
  48. | set up perspective peprojection matrix
  49. Parameters:
  50. | *[in]* **left** viewport.left
  51. | *[in]* **right** viewport.right
  52. | *[in]* **bottom** viewport.bottom
  53. | *[in]* **top** viewport.top
  54. | *[in]* **nearVal** near clipping plane
  55. | *[in]* **farVal** far clipping plane
  56. | *[out]* **dest** result matrix
  57. .. c:function:: void glm_ortho(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest)
  58. | set up orthographic projection matrix
  59. Parameters:
  60. | *[in]* **left** viewport.left
  61. | *[in]* **right** viewport.right
  62. | *[in]* **bottom** viewport.bottom
  63. | *[in]* **top** viewport.top
  64. | *[in]* **nearVal** near clipping plane
  65. | *[in]* **farVal** far clipping plane
  66. | *[out]* **dest** result matrix
  67. .. c:function:: void glm_ortho_aabb(vec3 box[2], mat4 dest)
  68. | set up orthographic projection matrix using bounding box
  69. | bounding box (AABB) must be in view space
  70. Parameters:
  71. | *[in]* **box** AABB
  72. | *[in]* **dest** result matrix
  73. .. c:function:: void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest)
  74. | set up orthographic projection matrix using bounding box
  75. | bounding box (AABB) must be in view space
  76. this version adds padding to box
  77. Parameters:
  78. | *[in]* **box** AABB
  79. | *[in]* **padding** padding
  80. | *[out]* **d** result matrix
  81. .. c:function:: void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest)
  82. | set up orthographic projection matrix using bounding box
  83. | bounding box (AABB) must be in view space
  84. this version adds Z padding to box
  85. Parameters:
  86. | *[in]* **box** AABB
  87. | *[in]* **padding** padding for near and far
  88. | *[out]* **d** result matrix
  89. Returns:
  90. square of norm / magnitude
  91. .. c:function:: void glm_ortho_default(float aspect, mat4 dest)
  92. | set up unit orthographic projection matrix
  93. Parameters:
  94. | *[in]* **aspect** aspect ration ( width / height )
  95. | *[out]* **dest** result matrix
  96. .. c:function:: void glm_ortho_default_s(float aspect, float size, mat4 dest)
  97. | set up orthographic projection matrix with given CUBE size
  98. Parameters:
  99. | *[in]* **aspect** aspect ration ( width / height )
  100. | *[in]* **size** cube size
  101. | *[out]* **dest** result matrix
  102. .. c:function:: void glm_perspective(float fovy, float aspect, float nearVal, float farVal, mat4 dest)
  103. | set up perspective projection matrix
  104. Parameters:
  105. | *[in]* **fovy** field of view angle
  106. | *[in]* **aspect** aspect ratio ( width / height )
  107. | *[in]* **nearVal** near clipping plane
  108. | *[in]* **farVal** far clipping planes
  109. | *[out]* **dest** result matrix
  110. .. c:function:: void glm_perspective_default(float aspect, mat4 dest)
  111. | set up perspective projection matrix with default near/far
  112. and angle values
  113. Parameters:
  114. | *[in]* **aspect** aspect aspect ratio ( width / height )
  115. | *[out]* **dest** result matrix
  116. .. c:function:: void glm_perspective_resize(float aspect, mat4 proj)
  117. | resize perspective matrix by aspect ratio ( width / height )
  118. this makes very easy to resize proj matrix when window / viewport reized
  119. Parameters:
  120. | *[in]* **aspect** aspect ratio ( width / height )
  121. | *[in, out]* **proj** perspective projection matrix
  122. .. c:function:: void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
  123. | set up view matrix
  124. **NOTE:** The UP vector must not be parallel to the line of sight from the eye point to the reference point.
  125. Parameters:
  126. | *[in]* **eye** eye vector
  127. | *[in]* **center** center vector
  128. | *[in]* **up** up vector
  129. | *[out]* **dest** result matrix
  130. .. c:function:: void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest)
  131. | set up view matrix
  132. convenient wrapper for :c:func:`glm_lookat`: if you only have direction not
  133. target self then this might be useful. Because you need to get target
  134. from direction.
  135. **NOTE:** The UP vector must not be parallel to the line of sight from the eye point to the reference point.
  136. Parameters:
  137. | *[in]* **eye** eye vector
  138. | *[in]* **center** direction vector
  139. | *[in]* **up** up vector
  140. | *[out]* **dest** result matrix
  141. .. c:function:: void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest)
  142. | set up view matrix
  143. convenient wrapper for :c:func:`glm_look` if you only have direction
  144. and if you don't care what UP vector is then this might be useful
  145. to create view matrix
  146. Parameters:
  147. | *[in]* **eye** eye vector
  148. | *[in]* **center** direction vector
  149. | *[out]* **dest** result matrix
  150. .. c:function:: void glm_persp_decomp(mat4 proj, float *nearVal, float *farVal, float *top, float *bottom, float *left, float *right)
  151. | decomposes frustum values of perspective projection.
  152. Parameters:
  153. | *[in]* **eye** perspective projection matrix
  154. | *[out]* **nearVal** near
  155. | *[out]* **farVal** far
  156. | *[out]* **top** top
  157. | *[out]* **bottom** bottom
  158. | *[out]* **left** left
  159. | *[out]* **right** right
  160. .. c:function:: void glm_persp_decompv(mat4 proj, float dest[6])
  161. | decomposes frustum values of perspective projection.
  162. | this makes easy to get all values at once
  163. Parameters:
  164. | *[in]* **proj** perspective projection matrix
  165. | *[out]* **dest** array
  166. .. c:function:: void glm_persp_decomp_x(mat4 proj, float *left, float *right)
  167. | decomposes left and right values of perspective projection.
  168. | x stands for x axis (left / right axis)
  169. Parameters:
  170. | *[in]* **proj** perspective projection matrix
  171. | *[out]* **left** left
  172. | *[out]* **right** right
  173. .. c:function:: void glm_persp_decomp_y(mat4 proj, float *top, float *bottom)
  174. | decomposes top and bottom values of perspective projection.
  175. | y stands for y axis (top / botom axis)
  176. Parameters:
  177. | *[in]* **proj** perspective projection matrix
  178. | *[out]* **top** top
  179. | *[out]* **bottom** bottom
  180. .. c:function:: void glm_persp_decomp_z(mat4 proj, float *nearVal, float *farVal)
  181. | decomposes near and far values of perspective projection.
  182. | z stands for z axis (near / far axis)
  183. Parameters:
  184. | *[in]* **proj** perspective projection matrix
  185. | *[out]* **nearVal** near
  186. | *[out]* **farVal** far
  187. .. c:function:: void glm_persp_decomp_far(mat4 proj, float * __restrict farVal)
  188. | decomposes far value of perspective projection.
  189. Parameters:
  190. | *[in]* **proj** perspective projection matrix
  191. | *[out]* **farVal** far
  192. .. c:function:: void glm_persp_decomp_near(mat4 proj, float * __restrict nearVal)
  193. | decomposes near value of perspective projection.
  194. Parameters:
  195. | *[in]* **proj** perspective projection matrix
  196. | *[out]* **nearVal** near
  197. .. c:function:: float glm_persp_fovy(mat4 proj)
  198. | returns field of view angle along the Y-axis (in radians)
  199. if you need to degrees, use glm_deg to convert it or use this:
  200. fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
  201. Parameters:
  202. | *[in]* **proj** perspective projection matrix
  203. Returns:
  204. | fovy in radians
  205. .. c:function:: float glm_persp_aspect(mat4 proj)
  206. | returns aspect ratio of perspective projection
  207. Parameters:
  208. | *[in]* **proj** perspective projection matrix
  209. .. c:function:: void glm_persp_sizes(mat4 proj, float fovy, vec4 dest)
  210. | returns sizes of near and far planes of perspective projection
  211. Parameters:
  212. | *[in]* **proj** perspective projection matrix
  213. | *[in]* **fovy** fovy (see brief)
  214. | *[out]* **dest** sizes order: [Wnear, Hnear, Wfar, Hfar]