cam.rst 10 KB

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