project_zo.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp)
  10. CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp)
  11. CGLM_INLINE float glms_project_z_zo(vec3s v, mat4s m)
  12. */
  13. #ifndef cglms_project_zo_h
  14. #define cglms_project_zo_h
  15. #include "../../common.h"
  16. #include "../../types-struct.h"
  17. #include "../../plane.h"
  18. #include "../../cam.h"
  19. #include "../../clipspace/project_zo.h"
  20. /*!
  21. * @brief maps the specified viewport coordinates into specified space [1]
  22. * the matrix should contain projection matrix.
  23. *
  24. * if you don't have ( and don't want to have ) an inverse matrix then use
  25. * glm_unproject version. You may use existing inverse of matrix in somewhere
  26. * else, this is why glm_unprojecti exists to save save inversion cost
  27. *
  28. * [1] space:
  29. * 1- if m = invProj: View Space
  30. * 2- if m = invViewProj: World Space
  31. * 3- if m = invMVP: Object Space
  32. *
  33. * You probably want to map the coordinates into object space
  34. * so use invMVP as m
  35. *
  36. * Computing viewProj:
  37. * glm_mat4_mul(proj, view, viewProj);
  38. * glm_mat4_mul(viewProj, model, MVP);
  39. * glm_mat4_inv(viewProj, invMVP);
  40. *
  41. * @param[in] pos point/position in viewport coordinates
  42. * @param[in] invMat matrix (see brief)
  43. * @param[in] vp viewport as [x, y, width, height]
  44. *
  45. * @returns unprojected coordinates
  46. */
  47. CGLM_INLINE
  48. vec3s
  49. glms_unprojecti_zo(vec3s pos, mat4s invMat, vec4s vp) {
  50. vec3s dest;
  51. glm_unprojecti_zo(pos.raw, invMat.raw, vp.raw, dest.raw);
  52. return dest;
  53. }
  54. /*!
  55. * @brief map object coordinates to window coordinates
  56. *
  57. * Computing MVP:
  58. * glm_mat4_mul(proj, view, viewProj);
  59. * glm_mat4_mul(viewProj, model, MVP);
  60. *
  61. * @param[in] pos object coordinates
  62. * @param[in] m MVP matrix
  63. * @param[in] vp viewport as [x, y, width, height]
  64. *
  65. * @returns projected coordinates
  66. */
  67. CGLM_INLINE
  68. vec3s
  69. glms_project_zo(vec3s pos, mat4s m, vec4s vp) {
  70. vec3s dest;
  71. glm_project_zo(pos.raw, m.raw, vp.raw, dest.raw);
  72. return dest;
  73. }
  74. /*!
  75. * @brief map object's z coordinate to window coordinates
  76. *
  77. * Computing MVP:
  78. * glm_mat4_mul(proj, view, viewProj);
  79. * glm_mat4_mul(viewProj, model, MVP);
  80. *
  81. * @param[in] v object coordinates
  82. * @param[in] m MVP matrix
  83. *
  84. * @returns projected z coordinate
  85. */
  86. CGLM_INLINE
  87. float
  88. glms_project_z_zo(vec3s v, mat4s m) {
  89. return glm_project_z_zo(v.raw, m.raw);
  90. }
  91. #endif /* cglm_project_zo_h */