1
0

ortho_rh_no.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_ortho_rh_no(float left, float right,
  10. float bottom, float top,
  11. float nearZ, float farZ,
  12. mat4 dest)
  13. CGLM_INLINE void glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest)
  14. CGLM_INLINE void glm_ortho_aabb_p_rh_no(vec3 box[2],
  15. float padding,
  16. mat4 dest)
  17. CGLM_INLINE void glm_ortho_aabb_pz_rh_no(vec3 box[2],
  18. float padding,
  19. mat4 dest)
  20. CGLM_INLINE void glm_ortho_default_rh_no(float aspect,
  21. mat4 dest)
  22. CGLM_INLINE void glm_ortho_default_s_rh_no(float aspect,
  23. float size,
  24. mat4 dest)
  25. */
  26. #ifndef cglm_ortho_rh_no_h
  27. #define cglm_ortho_rh_no_h
  28. #include "../common.h"
  29. #include "../plane.h"
  30. #include "../mat4.h"
  31. /*!
  32. * @brief set up orthographic projection matrix
  33. * with a right-hand coordinate system and a
  34. * clip-space of [-1, 1].
  35. *
  36. * @param[in] left viewport.left
  37. * @param[in] right viewport.right
  38. * @param[in] bottom viewport.bottom
  39. * @param[in] top viewport.top
  40. * @param[in] nearZ near clipping plane
  41. * @param[in] farZ far clipping plane
  42. * @param[out] dest result matrix
  43. */
  44. CGLM_INLINE
  45. void
  46. glm_ortho_rh_no(float left, float right,
  47. float bottom, float top,
  48. float nearZ, float farZ,
  49. mat4 dest) {
  50. float rl, tb, fn;
  51. glm_mat4_zero(dest);
  52. rl = 1.0f / (right - left);
  53. tb = 1.0f / (top - bottom);
  54. fn =-1.0f / (farZ - nearZ);
  55. dest[0][0] = 2.0f * rl;
  56. dest[1][1] = 2.0f * tb;
  57. dest[2][2] = 2.0f * fn;
  58. dest[3][0] =-(right + left) * rl;
  59. dest[3][1] =-(top + bottom) * tb;
  60. dest[3][2] = (farZ + nearZ) * fn;
  61. dest[3][3] = 1.0f;
  62. }
  63. /*!
  64. * @brief set up orthographic projection matrix using bounding box
  65. * with a right-hand coordinate system and a
  66. * clip-space of [-1, 1].
  67. *
  68. * bounding box (AABB) must be in view space
  69. *
  70. * @param[in] box AABB
  71. * @param[out] dest result matrix
  72. */
  73. CGLM_INLINE
  74. void
  75. glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest) {
  76. glm_ortho_rh_no(box[0][0], box[1][0],
  77. box[0][1], box[1][1],
  78. -box[1][2], -box[0][2],
  79. dest);
  80. }
  81. /*!
  82. * @brief set up orthographic projection matrix using bounding box
  83. * with a right-hand coordinate system and a
  84. * clip-space of [-1, 1].
  85. *
  86. * bounding box (AABB) must be in view space
  87. *
  88. * @param[in] box AABB
  89. * @param[in] padding padding
  90. * @param[out] dest result matrix
  91. */
  92. CGLM_INLINE
  93. void
  94. glm_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) {
  95. glm_ortho_rh_no(box[0][0] - padding, box[1][0] + padding,
  96. box[0][1] - padding, box[1][1] + padding,
  97. -(box[1][2] + padding), -(box[0][2] - padding),
  98. dest);
  99. }
  100. /*!
  101. * @brief set up orthographic projection matrix using bounding box
  102. * with a right-hand coordinate system and a
  103. * clip-space of [-1, 1].
  104. *
  105. * bounding box (AABB) must be in view space
  106. *
  107. * @param[in] box AABB
  108. * @param[in] padding padding for near and far
  109. * @param[out] dest result matrix
  110. */
  111. CGLM_INLINE
  112. void
  113. glm_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) {
  114. glm_ortho_rh_no(box[0][0], box[1][0],
  115. box[0][1], box[1][1],
  116. -(box[1][2] + padding), -(box[0][2] - padding),
  117. dest);
  118. }
  119. /*!
  120. * @brief set up unit orthographic projection matrix
  121. * with a right-hand coordinate system and a
  122. * clip-space of [-1, 1].
  123. *
  124. * @param[in] aspect aspect ration ( width / height )
  125. * @param[out] dest result matrix
  126. */
  127. CGLM_INLINE
  128. void
  129. glm_ortho_default_rh_no(float aspect, mat4 dest) {
  130. if (aspect >= 1.0f) {
  131. glm_ortho_rh_no(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest);
  132. return;
  133. }
  134. aspect = 1.0f / aspect;
  135. glm_ortho_rh_no(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest);
  136. }
  137. /*!
  138. * @brief set up orthographic projection matrix with given CUBE size
  139. * with a right-hand coordinate system and a
  140. * clip-space of [-1, 1].
  141. *
  142. * @param[in] aspect aspect ratio ( width / height )
  143. * @param[in] size cube size
  144. * @param[out] dest result matrix
  145. */
  146. CGLM_INLINE
  147. void
  148. glm_ortho_default_s_rh_no(float aspect, float size, mat4 dest) {
  149. if (aspect >= 1.0f) {
  150. glm_ortho_rh_no(-size * aspect,
  151. size * aspect,
  152. -size,
  153. size,
  154. -size - 100.0f,
  155. size + 100.0f,
  156. dest);
  157. return;
  158. }
  159. glm_ortho_rh_no(-size,
  160. size,
  161. -size / aspect,
  162. size / aspect,
  163. -size - 100.0f,
  164. size + 100.0f,
  165. dest);
  166. }
  167. #endif /*cglm_ortho_rh_no_h*/