sphere.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef cglms_spheres_h
  8. #define cglms_spheres_h
  9. #include "../common.h"
  10. #include "../types-struct.h"
  11. #include "../sphere.h"
  12. #include "mat4.h"
  13. /*
  14. Sphere Representation in cglm: [center.x, center.y, center.z, radii]
  15. You could use this representation or you can convert it to vec4 before call
  16. any function
  17. */
  18. /*!
  19. * @brief helper for getting sphere radius
  20. *
  21. * @param[in] s sphere
  22. *
  23. * @return returns radii
  24. */
  25. CGLM_INLINE
  26. float
  27. glms_sphere_radii(vec4s s) {
  28. return glm_sphere_radii(s.raw);
  29. }
  30. /*!
  31. * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3
  32. *
  33. * @param[in] s sphere
  34. * @param[in] m transform matrix
  35. * @returns transformed sphere
  36. */
  37. CGLM_INLINE
  38. vec4s
  39. glms_sphere_transform(vec4s s, mat4s m) {
  40. vec4s r;
  41. glm_sphere_transform(s.raw, m.raw, r.raw);
  42. return r;
  43. }
  44. /*!
  45. * @brief merges two spheres and creates a new one
  46. *
  47. * two sphere must be in same space, for instance if one in world space then
  48. * the other must be in world space too, not in local space.
  49. *
  50. * @param[in] s1 sphere 1
  51. * @param[in] s2 sphere 2
  52. * returns merged/extended sphere
  53. */
  54. CGLM_INLINE
  55. vec4s
  56. glms_sphere_merge(vec4s s1, vec4s s2) {
  57. vec4s r;
  58. glm_sphere_merge(s1.raw, s2.raw, r.raw);
  59. return r;
  60. }
  61. /*!
  62. * @brief check if two sphere intersects
  63. *
  64. * @param[in] s1 sphere
  65. * @param[in] s2 other sphere
  66. */
  67. CGLM_INLINE
  68. bool
  69. glms_sphere_sphere(vec4s s1, vec4s s2) {
  70. return glm_sphere_sphere(s1.raw, s2.raw);
  71. }
  72. /*!
  73. * @brief check if sphere intersects with point
  74. *
  75. * @param[in] s sphere
  76. * @param[in] point point
  77. */
  78. CGLM_INLINE
  79. bool
  80. glms_sphere_point(vec4s s, vec3s point) {
  81. return glm_sphere_point(s.raw, point.raw);
  82. }
  83. #endif /* cglms_spheres_h */