cam.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. /*
  8. Functions:
  9. CGLM_INLINE void glm_frustum(float left, float right,
  10. float bottom, float top,
  11. float nearZ, float farZ,
  12. mat4 dest)
  13. CGLM_INLINE void glm_ortho(float left, float right,
  14. float bottom, float top,
  15. float nearZ, float farZ,
  16. mat4 dest)
  17. CGLM_INLINE void glm_ortho_aabb(vec3 box[2], mat4 dest)
  18. CGLM_INLINE void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest)
  19. CGLM_INLINE void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest)
  20. CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest)
  21. CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest)
  22. CGLM_INLINE void glm_perspective(float fovy,
  23. float aspect,
  24. float nearZ,
  25. float farZ,
  26. mat4 dest)
  27. CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest)
  28. CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj)
  29. CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
  30. CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest)
  31. CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest)
  32. CGLM_INLINE void glm_persp_decomp(mat4 proj,
  33. float *nearZ, float *farZ,
  34. float *top, float *bottom,
  35. float *left, float *right)
  36. CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6])
  37. CGLM_INLINE void glm_persp_decomp_x(mat4 proj, float *left, float *right)
  38. CGLM_INLINE void glm_persp_decomp_y(mat4 proj, float *top, float *bottom)
  39. CGLM_INLINE void glm_persp_decomp_z(mat4 proj, float *nearv, float *farv)
  40. CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farZ)
  41. CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *nearZ)
  42. CGLM_INLINE float glm_persp_fovy(mat4 proj)
  43. CGLM_INLINE float glm_persp_aspect(mat4 proj)
  44. CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest)
  45. */
  46. #ifndef cglm_cam_h
  47. #define cglm_cam_h
  48. #include "common.h"
  49. #include "plane.h"
  50. #include "clipspace/persp.h"
  51. #ifndef CGLM_CLIPSPACE_INCLUDE_ALL
  52. # if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  53. # include "clipspace/ortho_lh_zo.h"
  54. # include "clipspace/persp_lh_zo.h"
  55. # include "clipspace/view_lh_zo.h"
  56. # elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  57. # include "clipspace/ortho_lh_no.h"
  58. # include "clipspace/persp_lh_no.h"
  59. # include "clipspace/view_lh_no.h"
  60. # elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  61. # include "clipspace/ortho_rh_zo.h"
  62. # include "clipspace/persp_rh_zo.h"
  63. # include "clipspace/view_rh_zo.h"
  64. # elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  65. # include "clipspace/ortho_rh_no.h"
  66. # include "clipspace/persp_rh_no.h"
  67. # include "clipspace/view_rh_no.h"
  68. # endif
  69. #else
  70. # include "clipspace/ortho_lh_zo.h"
  71. # include "clipspace/persp_lh_zo.h"
  72. # include "clipspace/ortho_lh_no.h"
  73. # include "clipspace/persp_lh_no.h"
  74. # include "clipspace/ortho_rh_zo.h"
  75. # include "clipspace/persp_rh_zo.h"
  76. # include "clipspace/ortho_rh_no.h"
  77. # include "clipspace/persp_rh_no.h"
  78. # include "clipspace/view_lh_zo.h"
  79. # include "clipspace/view_lh_no.h"
  80. # include "clipspace/view_rh_zo.h"
  81. # include "clipspace/view_rh_no.h"
  82. #endif
  83. /*!
  84. * @brief set up perspective peprojection matrix
  85. *
  86. * @param[in] left viewport.left
  87. * @param[in] right viewport.right
  88. * @param[in] bottom viewport.bottom
  89. * @param[in] top viewport.top
  90. * @param[in] nearZ near clipping plane
  91. * @param[in] farZ far clipping plane
  92. * @param[out] dest result matrix
  93. */
  94. CGLM_INLINE
  95. void
  96. glm_frustum(float left, float right,
  97. float bottom, float top,
  98. float nearZ, float farZ,
  99. mat4 dest) {
  100. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  101. glm_frustum_lh_zo(left, right, bottom, top, nearZ, farZ, dest);
  102. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  103. glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest);
  104. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  105. glm_frustum_rh_zo(left, right, bottom, top, nearZ, farZ, dest);
  106. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  107. glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest);
  108. #endif
  109. }
  110. /*!
  111. * @brief set up orthographic projection matrix
  112. *
  113. * @param[in] left viewport.left
  114. * @param[in] right viewport.right
  115. * @param[in] bottom viewport.bottom
  116. * @param[in] top viewport.top
  117. * @param[in] nearZ near clipping plane
  118. * @param[in] farZ far clipping plane
  119. * @param[out] dest result matrix
  120. */
  121. CGLM_INLINE
  122. void
  123. glm_ortho(float left, float right,
  124. float bottom, float top,
  125. float nearZ, float farZ,
  126. mat4 dest) {
  127. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  128. glm_ortho_lh_zo(left, right, bottom, top, nearZ, farZ, dest);
  129. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  130. glm_ortho_lh_no(left, right, bottom, top, nearZ, farZ, dest);
  131. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  132. glm_ortho_rh_zo(left, right, bottom, top, nearZ, farZ, dest);
  133. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  134. glm_ortho_rh_no(left, right, bottom, top, nearZ, farZ, dest);
  135. #endif
  136. }
  137. /*!
  138. * @brief set up orthographic projection matrix using bounding box
  139. *
  140. * bounding box (AABB) must be in view space
  141. *
  142. * @param[in] box AABB
  143. * @param[out] dest result matrix
  144. */
  145. CGLM_INLINE
  146. void
  147. glm_ortho_aabb(vec3 box[2], mat4 dest) {
  148. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  149. glm_ortho_aabb_lh_zo(box, dest);
  150. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  151. glm_ortho_aabb_lh_no(box, dest);
  152. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  153. glm_ortho_aabb_rh_zo(box, dest);
  154. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  155. glm_ortho_aabb_rh_no(box, dest);
  156. #endif
  157. }
  158. /*!
  159. * @brief set up orthographic projection matrix using bounding box
  160. *
  161. * bounding box (AABB) must be in view space
  162. *
  163. * @param[in] box AABB
  164. * @param[in] padding padding
  165. * @param[out] dest result matrix
  166. */
  167. CGLM_INLINE
  168. void
  169. glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) {
  170. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  171. glm_ortho_aabb_p_lh_zo(box, padding, dest);
  172. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  173. glm_ortho_aabb_p_lh_no(box, padding, dest);
  174. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  175. glm_ortho_aabb_p_rh_zo(box, padding, dest);
  176. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  177. glm_ortho_aabb_p_rh_no(box, padding, dest);
  178. #endif
  179. }
  180. /*!
  181. * @brief set up orthographic projection matrix using bounding box
  182. *
  183. * bounding box (AABB) must be in view space
  184. *
  185. * @param[in] box AABB
  186. * @param[in] padding padding for near and far
  187. * @param[out] dest result matrix
  188. */
  189. CGLM_INLINE
  190. void
  191. glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) {
  192. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  193. glm_ortho_aabb_pz_lh_zo(box, padding, dest);
  194. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  195. glm_ortho_aabb_pz_lh_no(box, padding, dest);
  196. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  197. glm_ortho_aabb_pz_rh_zo(box, padding, dest);
  198. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  199. glm_ortho_aabb_pz_rh_no(box, padding, dest);
  200. #endif
  201. }
  202. /*!
  203. * @brief set up unit orthographic projection matrix
  204. *
  205. * @param[in] aspect aspect ration ( width / height )
  206. * @param[out] dest result matrix
  207. */
  208. CGLM_INLINE
  209. void
  210. glm_ortho_default(float aspect, mat4 dest) {
  211. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  212. glm_ortho_default_lh_zo(aspect, dest);
  213. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  214. glm_ortho_default_lh_no(aspect, dest);
  215. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  216. glm_ortho_default_rh_zo(aspect, dest);
  217. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  218. glm_ortho_default_rh_no(aspect, dest);
  219. #endif
  220. }
  221. /*!
  222. * @brief set up orthographic projection matrix with given CUBE size
  223. *
  224. * @param[in] aspect aspect ratio ( width / height )
  225. * @param[in] size cube size
  226. * @param[out] dest result matrix
  227. */
  228. CGLM_INLINE
  229. void
  230. glm_ortho_default_s(float aspect, float size, mat4 dest) {
  231. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  232. glm_ortho_default_s_lh_zo(aspect, size, dest);
  233. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  234. glm_ortho_default_s_lh_no(aspect, size, dest);
  235. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  236. glm_ortho_default_s_rh_zo(aspect, size, dest);
  237. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  238. glm_ortho_default_s_rh_no(aspect, size, dest);
  239. #endif
  240. }
  241. /*!
  242. * @brief set up perspective projection matrix
  243. *
  244. * @param[in] fovy field of view angle
  245. * @param[in] aspect aspect ratio ( width / height )
  246. * @param[in] nearZ near clipping plane
  247. * @param[in] farZ far clipping planes
  248. * @param[out] dest result matrix
  249. */
  250. CGLM_INLINE
  251. void
  252. glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) {
  253. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  254. glm_perspective_lh_zo(fovy, aspect, nearZ, farZ, dest);
  255. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  256. glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest);
  257. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  258. glm_perspective_rh_zo(fovy, aspect, nearZ, farZ, dest);
  259. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  260. glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest);
  261. #endif
  262. }
  263. /*!
  264. * @brief extend perspective projection matrix's far distance
  265. *
  266. * this function does not guarantee far >= near, be aware of that!
  267. *
  268. * @param[in, out] proj projection matrix to extend
  269. * @param[in] deltaFar distance from existing far (negative to shink)
  270. */
  271. CGLM_INLINE
  272. void
  273. glm_persp_move_far(mat4 proj, float deltaFar) {
  274. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  275. glm_persp_move_far_lh_zo(proj, deltaFar);
  276. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  277. glm_persp_move_far_lh_no(proj, deltaFar);
  278. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  279. glm_persp_move_far_rh_zo(proj, deltaFar);
  280. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  281. glm_persp_move_far_rh_no(proj, deltaFar);
  282. #endif
  283. }
  284. /*!
  285. * @brief set up perspective projection matrix with default near/far
  286. * and angle values
  287. *
  288. * @param[in] aspect aspect ratio ( width / height )
  289. * @param[out] dest result matrix
  290. */
  291. CGLM_INLINE
  292. void
  293. glm_perspective_default(float aspect, mat4 dest) {
  294. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  295. glm_perspective_default_lh_zo(aspect, dest);
  296. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  297. glm_perspective_default_lh_no(aspect, dest);
  298. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  299. glm_perspective_default_rh_zo(aspect, dest);
  300. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  301. glm_perspective_default_rh_no(aspect, dest);
  302. #endif
  303. }
  304. /*!
  305. * @brief resize perspective matrix by aspect ratio ( width / height )
  306. * this makes very easy to resize proj matrix when window /viewport
  307. * reized
  308. *
  309. * @param[in] aspect aspect ratio ( width / height )
  310. * @param[in, out] proj perspective projection matrix
  311. */
  312. CGLM_INLINE
  313. void
  314. glm_perspective_resize(float aspect, mat4 proj) {
  315. if (proj[0][0] == 0.0f)
  316. return;
  317. proj[0][0] = proj[1][1] / aspect;
  318. }
  319. /*!
  320. * @brief set up view matrix
  321. *
  322. * NOTE: The UP vector must not be parallel to the line of sight from
  323. * the eye point to the reference point
  324. *
  325. * @param[in] eye eye vector
  326. * @param[in] center center vector
  327. * @param[in] up up vector
  328. * @param[out] dest result matrix
  329. */
  330. CGLM_INLINE
  331. void
  332. glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) {
  333. #if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT
  334. glm_lookat_lh(eye, center, up, dest);
  335. #elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT
  336. glm_lookat_rh(eye, center, up, dest);
  337. #endif
  338. }
  339. /*!
  340. * @brief set up view matrix
  341. *
  342. * convenient wrapper for lookat: if you only have direction not target self
  343. * then this might be useful. Because you need to get target from direction.
  344. *
  345. * NOTE: The UP vector must not be parallel to the line of sight from
  346. * the eye point to the reference point
  347. *
  348. * @param[in] eye eye vector
  349. * @param[in] dir direction vector
  350. * @param[in] up up vector
  351. * @param[out] dest result matrix
  352. */
  353. CGLM_INLINE
  354. void
  355. glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) {
  356. #if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT
  357. glm_look_lh(eye, dir, up, dest);
  358. #elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT
  359. glm_look_rh(eye, dir, up, dest);
  360. #endif
  361. }
  362. /*!
  363. * @brief set up view matrix
  364. *
  365. * convenient wrapper for look: if you only have direction and if you don't
  366. * care what UP vector is then this might be useful to create view matrix
  367. *
  368. * @param[in] eye eye vector
  369. * @param[in] dir direction vector
  370. * @param[out] dest result matrix
  371. */
  372. CGLM_INLINE
  373. void
  374. glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) {
  375. #if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT
  376. glm_look_anyup_lh(eye, dir, dest);
  377. #elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT
  378. glm_look_anyup_rh(eye, dir, dest);
  379. #endif
  380. }
  381. /*!
  382. * @brief decomposes frustum values of perspective projection.
  383. *
  384. * @param[in] proj perspective projection matrix
  385. * @param[out] nearZ near
  386. * @param[out] farZ far
  387. * @param[out] top top
  388. * @param[out] bottom bottom
  389. * @param[out] left left
  390. * @param[out] right right
  391. */
  392. CGLM_INLINE
  393. void
  394. glm_persp_decomp(mat4 proj,
  395. float * __restrict nearZ, float * __restrict farZ,
  396. float * __restrict top, float * __restrict bottom,
  397. float * __restrict left, float * __restrict right) {
  398. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  399. glm_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right);
  400. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  401. glm_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right);
  402. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  403. glm_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right);
  404. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  405. glm_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right);
  406. #endif
  407. }
  408. /*!
  409. * @brief decomposes frustum values of perspective projection.
  410. * this makes easy to get all values at once
  411. *
  412. * @param[in] proj perspective projection matrix
  413. * @param[out] dest array
  414. */
  415. CGLM_INLINE
  416. void
  417. glm_persp_decompv(mat4 proj, float dest[6]) {
  418. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  419. glm_persp_decompv_lh_zo(proj, dest);
  420. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  421. glm_persp_decompv_lh_no(proj, dest);
  422. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  423. glm_persp_decompv_rh_zo(proj, dest);
  424. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  425. glm_persp_decompv_rh_no(proj, dest);
  426. #endif
  427. }
  428. /*!
  429. * @brief decomposes left and right values of perspective projection.
  430. * x stands for x axis (left / right axis)
  431. *
  432. * @param[in] proj perspective projection matrix
  433. * @param[out] left left
  434. * @param[out] right right
  435. */
  436. CGLM_INLINE
  437. void
  438. glm_persp_decomp_x(mat4 proj,
  439. float * __restrict left,
  440. float * __restrict right) {
  441. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  442. glm_persp_decomp_x_lh_zo(proj, left, right);
  443. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  444. glm_persp_decomp_x_lh_no(proj, left, right);
  445. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  446. glm_persp_decomp_x_rh_zo(proj, left, right);
  447. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  448. glm_persp_decomp_x_rh_no(proj, left, right);
  449. #endif
  450. }
  451. /*!
  452. * @brief decomposes top and bottom values of perspective projection.
  453. * y stands for y axis (top / bottom axis)
  454. *
  455. * @param[in] proj perspective projection matrix
  456. * @param[out] top top
  457. * @param[out] bottom bottom
  458. */
  459. CGLM_INLINE
  460. void
  461. glm_persp_decomp_y(mat4 proj,
  462. float * __restrict top,
  463. float * __restrict bottom) {
  464. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  465. glm_persp_decomp_y_lh_zo(proj, top, bottom);
  466. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  467. glm_persp_decomp_y_lh_no(proj, top, bottom);
  468. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  469. glm_persp_decomp_y_rh_zo(proj, top, bottom);
  470. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  471. glm_persp_decomp_y_rh_no(proj, top, bottom);
  472. #endif
  473. }
  474. /*!
  475. * @brief decomposes near and far values of perspective projection.
  476. * z stands for z axis (near / far axis)
  477. *
  478. * @param[in] proj perspective projection matrix
  479. * @param[out] nearZ near
  480. * @param[out] farZ far
  481. */
  482. CGLM_INLINE
  483. void
  484. glm_persp_decomp_z(mat4 proj, float * __restrict nearZ, float * __restrict farZ) {
  485. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  486. glm_persp_decomp_z_lh_zo(proj, nearZ, farZ);
  487. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  488. glm_persp_decomp_z_lh_no(proj, nearZ, farZ);
  489. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  490. glm_persp_decomp_z_rh_zo(proj, nearZ, farZ);
  491. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  492. glm_persp_decomp_z_rh_no(proj, nearZ, farZ);
  493. #endif
  494. }
  495. /*!
  496. * @brief decomposes far value of perspective projection.
  497. *
  498. * @param[in] proj perspective projection matrix
  499. * @param[out] farZ far
  500. */
  501. CGLM_INLINE
  502. void
  503. glm_persp_decomp_far(mat4 proj, float * __restrict farZ) {
  504. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  505. glm_persp_decomp_far_lh_zo(proj, farZ);
  506. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  507. glm_persp_decomp_far_lh_no(proj, farZ);
  508. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  509. glm_persp_decomp_far_rh_zo(proj, farZ);
  510. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  511. glm_persp_decomp_far_rh_no(proj, farZ);
  512. #endif
  513. }
  514. /*!
  515. * @brief decomposes near value of perspective projection.
  516. *
  517. * @param[in] proj perspective projection matrix
  518. * @param[out] nearZ near
  519. */
  520. CGLM_INLINE
  521. void
  522. glm_persp_decomp_near(mat4 proj, float * __restrict nearZ) {
  523. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  524. glm_persp_decomp_near_lh_zo(proj, nearZ);
  525. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  526. glm_persp_decomp_near_lh_no(proj, nearZ);
  527. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  528. glm_persp_decomp_near_rh_zo(proj, nearZ);
  529. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  530. glm_persp_decomp_near_rh_no(proj, nearZ);
  531. #endif
  532. }
  533. /*!
  534. * @brief returns sizes of near and far planes of perspective projection
  535. *
  536. * @param[in] proj perspective projection matrix
  537. * @param[in] fovy fovy (see brief)
  538. * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar]
  539. */
  540. CGLM_INLINE
  541. void
  542. glm_persp_sizes(mat4 proj, float fovy, vec4 dest) {
  543. #if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  544. glm_persp_sizes_lh_zo(proj, fovy, dest);
  545. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  546. glm_persp_sizes_lh_no(proj, fovy, dest);
  547. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  548. glm_persp_sizes_rh_zo(proj, fovy, dest);
  549. #elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  550. glm_persp_sizes_rh_no(proj, fovy, dest);
  551. #endif
  552. }
  553. #endif /* cglm_cam_h */