persp.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_persp_decomp_far(mat4 proj, float *farZ)
  10. CGLM_INLINE float glm_persp_fovy(mat4 proj)
  11. CGLM_INLINE float glm_persp_aspect(mat4 proj)
  12. CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest)
  13. */
  14. #ifndef cglm_persp_h
  15. #define cglm_persp_h
  16. #include "../common.h"
  17. #include "../plane.h"
  18. #include "../mat4.h"
  19. /*!
  20. * @brief returns field of view angle along the Y-axis (in radians)
  21. *
  22. * if you need to degrees, use glm_deg to convert it or use this:
  23. * fovy_deg = glm_deg(glm_persp_fovy(projMatrix))
  24. *
  25. * @param[in] proj perspective projection matrix
  26. */
  27. CGLM_INLINE
  28. float
  29. glm_persp_fovy(mat4 proj) {
  30. return 2.0f * atanf(1.0f / proj[1][1]);
  31. }
  32. /*!
  33. * @brief returns aspect ratio of perspective projection
  34. *
  35. * @param[in] proj perspective projection matrix
  36. */
  37. CGLM_INLINE
  38. float
  39. glm_persp_aspect(mat4 proj) {
  40. return proj[1][1] / proj[0][0];
  41. }
  42. #endif /* cglm_persp_h */