persp_rh_no.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 mat4s glms_frustum_rh_no(float left, float right,
  10. float bottom, float top,
  11. float nearZ, float farZ)
  12. CGLM_INLINE mat4s glms_perspective_rh_no(float fovy,
  13. float aspect,
  14. float nearZ,
  15. float farZ)
  16. CGLM_INLINE void glms_persp_move_far_rh_no(mat4s proj, float deltaFar)
  17. CGLM_INLINE mat4s glms_perspective_default_rh_no(float aspect)
  18. CGLM_INLINE void glms_perspective_resize_rh_no(mat4s proj, float aspect)
  19. CGLM_INLINE void glms_persp_decomp_rh_no(mat4s proj,
  20. float *nearv, float *farv,
  21. float *top, float *bottom,
  22. float *left, float *right)
  23. CGLM_INLINE void glms_persp_decompv_rh_no(mat4s proj, float dest[6])
  24. CGLM_INLINE void glms_persp_decomp_x_rh_no(mat4s proj, float *left, float *right)
  25. CGLM_INLINE void glms_persp_decomp_y_rh_no(mat4s proj, float *top, float *bottom)
  26. CGLM_INLINE void glms_persp_decomp_z_rh_no(mat4s proj, float *nearv, float *farv)
  27. CGLM_INLINE void glms_persp_decomp_far_rh_no(mat4s proj, float *farZ)
  28. CGLM_INLINE void glms_persp_decomp_near_rh_no(mat4s proj, float *nearZ)
  29. CGLM_INLINE float glms_persp_fovy_rh_no(mat4s proj)
  30. CGLM_INLINE float glms_persp_aspect_rh_no(mat4s proj)
  31. CGLM_INLINE vec4s glms_persp_sizes_rh_no(mat4s proj, float fovy)
  32. */
  33. #ifndef cglms_persp_rh_no_h
  34. #define cglms_persp_rh_no_h
  35. #include "../../common.h"
  36. #include "../../types-struct.h"
  37. #include "../../plane.h"
  38. #include "../../cam.h"
  39. #include "../../clipspace/persp_rh_no.h"
  40. /*!
  41. * @brief set up perspective peprojection matrix
  42. * with a right-hand coordinate system and a
  43. * clip-space of [-1, 1].
  44. *
  45. * @param[in] left viewport.left
  46. * @param[in] right viewport.right
  47. * @param[in] bottom viewport.bottom
  48. * @param[in] top viewport.top
  49. * @param[in] nearZ near clipping plane
  50. * @param[in] farZ far clipping plane
  51. * @returns result matrix
  52. */
  53. CGLM_INLINE
  54. mat4s
  55. glms_frustum_rh_no(float left, float right,
  56. float bottom, float top,
  57. float nearZ, float farZ) {
  58. mat4s dest;
  59. glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest.raw);
  60. return dest;
  61. }
  62. /*!
  63. * @brief set up perspective projection matrix
  64. * with a right-hand coordinate system and a
  65. * clip-space of [-1, 1].
  66. *
  67. * @param[in] fovy field of view angle
  68. * @param[in] aspect aspect ratio ( width / height )
  69. * @param[in] nearZ near clipping plane
  70. * @param[in] farZ far clipping planes
  71. * @returns result matrix
  72. */
  73. CGLM_INLINE
  74. mat4s
  75. glms_perspective_rh_no(float fovy, float aspect, float nearZ, float farZ) {
  76. mat4s dest;
  77. glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest.raw);
  78. return dest;
  79. }
  80. /*!
  81. * @brief extend perspective projection matrix's far distance
  82. * with a right-hand coordinate system and a
  83. * clip-space of [-1, 1].
  84. *
  85. * NOTE: if you dodn't want to create new matrix then use array api on struct.raw
  86. * like glms_persp_move_far_rh_no(prooj.raw, deltaFar) to avoid create new mat4
  87. * each time
  88. * s
  89. * this function does not guarantee far >= near, be aware of that!
  90. *
  91. * @param[in, out] proj projection matrix to extend
  92. * @param[in] deltaFar distance from existing far (negative to shink)
  93. */
  94. CGLM_INLINE
  95. mat4s
  96. glms_persp_move_far_rh_no(mat4s proj, float deltaFar) {
  97. mat4s dest;
  98. dest = proj;
  99. glm_persp_move_far_rh_no(dest.raw, deltaFar);
  100. return dest;
  101. }
  102. /*!
  103. * @brief set up perspective projection matrix with default near/far
  104. * and angle values with a right-hand coordinate system and a
  105. * clip-space of [-1, 1].
  106. *
  107. * @param[in] aspect aspect ratio ( width / height )
  108. * @returns result matrix
  109. */
  110. CGLM_INLINE
  111. mat4s
  112. glms_perspective_default_rh_no(float aspect) {
  113. mat4s dest;
  114. glm_perspective_default_rh_no(aspect, dest.raw);
  115. return dest;
  116. }
  117. /*!
  118. * @brief resize perspective matrix by aspect ratio ( width / height )
  119. * this makes very easy to resize proj matrix when window /viewport
  120. * reized with a right-hand coordinate system and a
  121. * clip-space of [-1, 1].
  122. *
  123. * NOTE: if you dodn't want to create new matrix then use array api on struct.raw
  124. * like glm_perspective_resize_rh_no(proj.raw, aspect) to avoid create new mat4
  125. * each time
  126. *
  127. * @param[in, out] proj perspective projection matrix
  128. * @param[in] aspect aspect ratio ( width / height )
  129. */
  130. CGLM_INLINE
  131. mat4s
  132. glms_perspective_resize_rh_no(mat4s proj, float aspect) {
  133. mat4s dest;
  134. dest = proj;
  135. glm_perspective_resize_rh_no(aspect, dest.raw);
  136. return dest;
  137. }
  138. /*!
  139. * @brief decomposes frustum values of perspective projection.
  140. * with a right-hand coordinate system and a
  141. * clip-space of [-1, 1].
  142. *
  143. * @param[in] proj perspective projection matrix
  144. * @param[out] nearZ near
  145. * @param[out] farZ far
  146. * @param[out] top top
  147. * @param[out] bottom bottom
  148. * @param[out] left left
  149. * @param[out] right right
  150. */
  151. CGLM_INLINE
  152. void
  153. glms_persp_decomp_rh_no(mat4s proj,
  154. float * __restrict nearZ, float * __restrict farZ,
  155. float * __restrict top, float * __restrict bottom,
  156. float * __restrict left, float * __restrict right) {
  157. glm_persp_decomp_rh_no(proj.raw, nearZ, farZ, top, bottom, left, right);
  158. }
  159. /*!
  160. * @brief decomposes frustum values of perspective projection.
  161. * this makes easy to get all values at once
  162. * with a right-hand coordinate system and a
  163. * clip-space of [-1, 1].
  164. *
  165. * @param[in] proj perspective projection matrix
  166. * @param[out] dest array
  167. */
  168. CGLM_INLINE
  169. void
  170. glms_persp_decompv_rh_no(mat4s proj, float dest[6]) {
  171. glm_persp_decompv_rh_no(proj.raw, dest);
  172. }
  173. /*!
  174. * @brief decomposes left and right values of perspective projection
  175. * with a right-hand coordinate system and a
  176. * clip-space of [-1, 1].
  177. * x stands for x axis (left / right axis)
  178. *
  179. * @param[in] proj perspective projection matrix
  180. * @param[out] left left
  181. * @param[out] right right
  182. */
  183. CGLM_INLINE
  184. void
  185. glms_persp_decomp_x_rh_no(mat4s proj,
  186. float * __restrict left,
  187. float * __restrict right) {
  188. glm_persp_decomp_x_rh_no(proj.raw, left, right);
  189. }
  190. /*!
  191. * @brief decomposes top and bottom values of perspective projection
  192. * with a right-hand coordinate system and a
  193. * clip-space of [-1, 1].
  194. * y stands for y axis (top / bottom axis)
  195. *
  196. * @param[in] proj perspective projection matrix
  197. * @param[out] top top
  198. * @param[out] bottom bottom
  199. */
  200. CGLM_INLINE
  201. void
  202. glms_persp_decomp_y_rh_no(mat4s proj,
  203. float * __restrict top,
  204. float * __restrict bottom) {
  205. glm_persp_decomp_y_rh_no(proj.raw, top, bottom);
  206. }
  207. /*!
  208. * @brief decomposes near and far values of perspective projection
  209. * with a right-hand coordinate system and a
  210. * clip-space of [-1, 1].
  211. * z stands for z axis (near / far axis)
  212. *
  213. * @param[in] proj perspective projection matrix
  214. * @param[out] nearZ near
  215. * @param[out] farZ far
  216. */
  217. CGLM_INLINE
  218. void
  219. glms_persp_decomp_z_rh_no(mat4s proj,
  220. float * __restrict nearZ,
  221. float * __restrict farZ) {
  222. glm_persp_decomp_z_rh_no(proj.raw, nearZ, farZ);
  223. }
  224. /*!
  225. * @brief decomposes far value of perspective projection
  226. * with a right-hand coordinate system and a
  227. * clip-space of [-1, 1].
  228. *
  229. * @param[in] proj perspective projection matrix
  230. * @param[out] farZ far
  231. */
  232. CGLM_INLINE
  233. void
  234. glms_persp_decomp_far_rh_no(mat4s proj, float * __restrict farZ) {
  235. glm_persp_decomp_far_rh_no(proj.raw, farZ);
  236. }
  237. /*!
  238. * @brief decomposes near value of perspective projection
  239. * with a right-hand coordinate system and a
  240. * clip-space of [-1, 1].
  241. *
  242. * @param[in] proj perspective projection matrix
  243. * @param[out] nearZ near
  244. */
  245. CGLM_INLINE
  246. void
  247. glms_persp_decomp_near_rh_no(mat4s proj, float * __restrict nearZ) {
  248. glm_persp_decomp_near_rh_no(proj.raw, nearZ);
  249. }
  250. /*!
  251. * @brief returns field of view angle along the Y-axis (in radians)
  252. * with a right-hand coordinate system and a
  253. * clip-space of [-1, 1].
  254. *
  255. * if you need to degrees, use glm_deg to convert it or use this:
  256. * fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
  257. *
  258. * @param[in] proj perspective projection matrix
  259. */
  260. CGLM_INLINE
  261. float
  262. glms_persp_fovy_rh_no(mat4s proj) {
  263. return glm_persp_fovy_rh_no(proj.raw);
  264. }
  265. /*!
  266. * @brief returns aspect ratio of perspective projection
  267. * with a right-hand coordinate system and a
  268. * clip-space of [-1, 1].
  269. *
  270. * @param[in] proj perspective projection matrix
  271. */
  272. CGLM_INLINE
  273. float
  274. glms_persp_aspect_rh_no(mat4s proj) {
  275. return glm_persp_aspect_rh_no(proj.raw);
  276. }
  277. /*!
  278. * @brief returns sizes of near and far planes of perspective projection
  279. * with a right-hand coordinate system and a
  280. * clip-space of [-1, 1].
  281. *
  282. * @param[in] proj perspective projection matrix
  283. * @param[in] fovy fovy (see brief)
  284. * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar]
  285. */
  286. CGLM_INLINE
  287. vec4s
  288. glms_persp_sizes_rh_no(mat4s proj, float fovy) {
  289. vec4s dest;
  290. glm_persp_sizes_rh_no(proj.raw, fovy, dest.raw);
  291. return dest;
  292. }
  293. #endif /* cglms_persp_rh_no_h */