cam.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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_infinite`
  31. #. :c:func:`glm_persp_move_far`
  32. #. :c:func:`glm_perspective_default`
  33. #. :c:func:`glm_perspective_default_infinite`
  34. #. :c:func:`glm_perspective_resize`
  35. #. :c:func:`glm_lookat`
  36. #. :c:func:`glm_look`
  37. #. :c:func:`glm_look_anyup`
  38. #. :c:func:`glm_persp_decomp`
  39. #. :c:func:`glm_persp_decompv`
  40. #. :c:func:`glm_persp_decomp_x`
  41. #. :c:func:`glm_persp_decomp_y`
  42. #. :c:func:`glm_persp_decomp_z`
  43. #. :c:func:`glm_persp_decomp_far`
  44. #. :c:func:`glm_persp_decomp_near`
  45. #. :c:func:`glm_persp_fovy`
  46. #. :c:func:`glm_persp_aspect`
  47. #. :c:func:`glm_persp_sizes`
  48. Functions documentation
  49. ~~~~~~~~~~~~~~~~~~~~~~~
  50. .. c:function:: void glm_frustum(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest)
  51. | set up perspective peprojection matrix
  52. Parameters:
  53. | *[in]* **left** viewport.left
  54. | *[in]* **right** viewport.right
  55. | *[in]* **bottom** viewport.bottom
  56. | *[in]* **top** viewport.top
  57. | *[in]* **nearVal** near clipping plane
  58. | *[in]* **farVal** far clipping plane
  59. | *[out]* **dest** result matrix
  60. .. c:function:: void glm_ortho(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest)
  61. | set up orthographic projection matrix
  62. Parameters:
  63. | *[in]* **left** viewport.left
  64. | *[in]* **right** viewport.right
  65. | *[in]* **bottom** viewport.bottom
  66. | *[in]* **top** viewport.top
  67. | *[in]* **nearVal** near clipping plane
  68. | *[in]* **farVal** far clipping plane
  69. | *[out]* **dest** result matrix
  70. .. c:function:: void glm_ortho_aabb(vec3 box[2], mat4 dest)
  71. | set up orthographic projection matrix using bounding box
  72. | bounding box (AABB) must be in view space
  73. Parameters:
  74. | *[in]* **box** AABB
  75. | *[in]* **dest** result matrix
  76. .. c:function:: void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest)
  77. | set up orthographic projection matrix using bounding box
  78. | bounding box (AABB) must be in view space
  79. this version adds padding to box
  80. Parameters:
  81. | *[in]* **box** AABB
  82. | *[in]* **padding** padding
  83. | *[out]* **dest** result matrix
  84. .. c:function:: void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest)
  85. | set up orthographic projection matrix using bounding box
  86. | bounding box (AABB) must be in view space
  87. this version adds Z padding to box
  88. Parameters:
  89. | *[in]* **box** AABB
  90. | *[in]* **padding** padding for near and far
  91. | *[out]* **dest** result matrix
  92. Returns:
  93. square of norm / magnitude
  94. .. c:function:: void glm_ortho_default(float aspect, mat4 dest)
  95. | set up unit orthographic projection matrix
  96. Parameters:
  97. | *[in]* **aspect** aspect ration ( width / height )
  98. | *[out]* **dest** result matrix
  99. .. c:function:: void glm_ortho_default_s(float aspect, float size, mat4 dest)
  100. | set up orthographic projection matrix with given CUBE size
  101. Parameters:
  102. | *[in]* **aspect** aspect ration ( width / height )
  103. | *[in]* **size** cube size
  104. | *[out]* **dest** result matrix
  105. .. c:function:: void glm_perspective(float fovy, float aspect, float nearVal, float farVal, mat4 dest)
  106. | set up perspective projection matrix
  107. Parameters:
  108. | *[in]* **fovy** field of view angle (in radians)
  109. | *[in]* **aspect** aspect ratio ( width / height )
  110. | *[in]* **nearVal** near clipping plane
  111. | *[in]* **farVal** far clipping planes
  112. | *[out]* **dest** result matrix
  113. .. c:function:: void glm_perspective_infinite(float fovy, float aspect, float nearZ, mat4 dest)
  114. | set up perspective projection matrix with infinite far plane
  115. The far clipping plane is pushed to infinity. This can improve depth
  116. precision for distant objects and is required by some rendering techniques
  117. such as shadow volumes. Dispatches to the appropriate clipspace variant
  118. based on compile-time configuration (LH/RH, NO/ZO).
  119. Parameters:
  120. | *[in]* **fovy** field of view angle (in radians)
  121. | *[in]* **aspect** aspect ratio ( width / height )
  122. | *[in]* **nearZ** near clipping plane
  123. | *[out]* **dest** result matrix
  124. .. c:function:: void glm_persp_move_far(mat4 proj, float deltaFar)
  125. | extend perspective projection matrix's far distance
  126. | this function does not guarantee far >= near, be aware of that!
  127. Parameters:
  128. | *[in, out]* **proj** projection matrix to extend
  129. | *[in]* **deltaFar** distance from existing far (negative to shink)
  130. .. c:function:: void glm_perspective_default(float aspect, mat4 dest)
  131. | set up perspective projection matrix with default near/far
  132. and angle values
  133. Parameters:
  134. | *[in]* **aspect** aspect aspect ratio ( width / height )
  135. | *[out]* **dest** result matrix
  136. .. c:function:: void glm_perspective_default_infinite(float aspect, mat4 dest)
  137. | set up infinite perspective projection matrix with default near
  138. and angle values
  139. Equivalent to calling :c:func:`glm_perspective_infinite` with
  140. ``fovy = GLM_PI_4`` (45°) and ``nearZ = 0.01``. Useful as a
  141. quick drop-in when you need an infinite projection without tuning
  142. the individual parameters.
  143. Parameters:
  144. | *[in]* **aspect** aspect ratio ( width / height )
  145. | *[out]* **dest** result matrix
  146. .. c:function:: void glm_perspective_resize(float aspect, mat4 proj)
  147. | resize perspective matrix by aspect ratio ( width / height )
  148. this makes very easy to resize proj matrix when window / viewport reized
  149. Parameters:
  150. | *[in]* **aspect** aspect ratio ( width / height )
  151. | *[in, out]* **proj** perspective projection matrix
  152. .. c:function:: void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
  153. | set up view matrix
  154. .. note:: The UP vector must not be parallel to the line of sight from the eye point to the reference point.
  155. Parameters:
  156. | *[in]* **eye** eye vector
  157. | *[in]* **center** center vector
  158. | *[in]* **up** up vector
  159. | *[out]* **dest** result matrix
  160. .. c:function:: void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest)
  161. | set up view matrix
  162. convenient wrapper for :c:func:`glm_lookat`: if you only have direction not
  163. target self then this might be useful. Because you need to get target
  164. from direction.
  165. .. note:: The UP vector must not be parallel to the line of sight from the eye point to the reference point.
  166. Parameters:
  167. | *[in]* **eye** eye vector
  168. | *[in]* **dir** direction vector
  169. | *[in]* **up** up vector
  170. | *[out]* **dest** result matrix
  171. .. c:function:: void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest)
  172. | set up view matrix
  173. convenient wrapper for :c:func:`glm_look` if you only have direction
  174. and if you don't care what UP vector is then this might be useful
  175. to create view matrix
  176. Parameters:
  177. | *[in]* **eye** eye vector
  178. | *[in]* **dir** direction vector
  179. | *[out]* **dest** result matrix
  180. .. c:function:: void glm_persp_decomp(mat4 proj, float *nearVal, float *farVal, float *top, float *bottom, float *left, float *right)
  181. | decomposes frustum values of perspective projection.
  182. Parameters:
  183. | *[in]* **eye** perspective projection matrix
  184. | *[out]* **nearVal** near
  185. | *[out]* **farVal** far
  186. | *[out]* **top** top
  187. | *[out]* **bottom** bottom
  188. | *[out]* **left** left
  189. | *[out]* **right** right
  190. .. c:function:: void glm_persp_decompv(mat4 proj, float dest[6])
  191. | decomposes frustum values of perspective projection.
  192. | this makes easy to get all values at once
  193. Parameters:
  194. | *[in]* **proj** perspective projection matrix
  195. | *[out]* **dest** array
  196. .. c:function:: void glm_persp_decomp_x(mat4 proj, float *left, float *right)
  197. | decomposes left and right values of perspective projection.
  198. | x stands for x axis (left / right axis)
  199. Parameters:
  200. | *[in]* **proj** perspective projection matrix
  201. | *[out]* **left** left
  202. | *[out]* **right** right
  203. .. c:function:: void glm_persp_decomp_y(mat4 proj, float *top, float *bottom)
  204. | decomposes top and bottom values of perspective projection.
  205. | y stands for y axis (top / bottom axis)
  206. Parameters:
  207. | *[in]* **proj** perspective projection matrix
  208. | *[out]* **top** top
  209. | *[out]* **bottom** bottom
  210. .. c:function:: void glm_persp_decomp_z(mat4 proj, float *nearVal, float *farVal)
  211. | decomposes near and far values of perspective projection.
  212. | z stands for z axis (near / far axis)
  213. Parameters:
  214. | *[in]* **proj** perspective projection matrix
  215. | *[out]* **nearVal** near
  216. | *[out]* **farVal** far
  217. .. c:function:: void glm_persp_decomp_far(mat4 proj, float * __restrict farVal)
  218. | decomposes far value of perspective projection.
  219. Parameters:
  220. | *[in]* **proj** perspective projection matrix
  221. | *[out]* **farVal** far
  222. .. c:function:: void glm_persp_decomp_near(mat4 proj, float * __restrict nearVal)
  223. | decomposes near value of perspective projection.
  224. Parameters:
  225. | *[in]* **proj** perspective projection matrix
  226. | *[out]* **nearVal** near
  227. .. c:function:: float glm_persp_fovy(mat4 proj)
  228. | returns field of view angle along the Y-axis (in radians)
  229. if you need to degrees, use glm_deg to convert it or use this:
  230. fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
  231. Parameters:
  232. | *[in]* **proj** perspective projection matrix
  233. Returns:
  234. | fovy in radians
  235. .. c:function:: float glm_persp_aspect(mat4 proj)
  236. | returns aspect ratio of perspective projection
  237. Parameters:
  238. | *[in]* **proj** perspective projection matrix
  239. .. c:function:: void glm_persp_sizes(mat4 proj, float fovy, vec4 dest)
  240. | returns sizes of near and far planes of perspective projection
  241. Parameters:
  242. | *[in]* **proj** perspective projection matrix
  243. | *[in]* **fovy** fovy (see brief)
  244. | *[out]* **dest** sizes order: [Wnear, Hnear, Wfar, Hfar]