box.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. .. default-domain:: C
  2. axis aligned bounding box (AABB)
  3. ================================================================================
  4. Header: cglm/box.h
  5. Some convenient functions provided for AABB.
  6. **Definition of box:**
  7. cglm defines box as two dimensional array of vec3.
  8. The first element is **min** point and the second one is **max** point.
  9. If you have another type e.g. struct or even another representation then you must
  10. convert it before and after call cglm box function.
  11. Table of contents (click to go):
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. Functions:
  14. 1. :c:func:`glm_aabb_transform`
  15. #. :c:func:`glm_aabb_merge`
  16. #. :c:func:`glm_aabb_crop`
  17. #. :c:func:`glm_aabb_crop_until`
  18. #. :c:func:`glm_aabb_frustum`
  19. #. :c:func:`glm_aabb_invalidate`
  20. #. :c:func:`glm_aabb_isvalid`
  21. #. :c:func:`glm_aabb_size`
  22. #. :c:func:`glm_aabb_radius`
  23. #. :c:func:`glm_aabb_center`
  24. #. :c:func:`glm_aabb_aabb`
  25. #. :c:func:`glm_aabb_sphere`
  26. #. :c:func:`glm_aabb_point`
  27. #. :c:func:`glm_aabb_contains`
  28. Functions documentation
  29. ~~~~~~~~~~~~~~~~~~~~~~~
  30. .. c:function:: void glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2])
  31. | apply transform to Axis-Aligned Bounding Box
  32. Parameters:
  33. | *[in]* **box** bounding box
  34. | *[in]* **m** transform matrix
  35. | *[out]* **dest** transformed bounding box
  36. .. c:function:: void glm_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2])
  37. | merges two AABB bounding box and creates new one
  38. two box must be in same space, if one of box is in different space then
  39. you should consider to convert it's space by glm_box_space
  40. Parameters:
  41. | *[in]* **box1** bounding box 1
  42. | *[in]* **box2** bounding box 2
  43. | *[out]* **dest** merged bounding box
  44. .. c:function:: void glm_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2])
  45. | crops a bounding box with another one.
  46. this could be useful for getting a bbox which fits with view frustum and
  47. object bounding boxes. In this case you crop view frustum box with objects
  48. box
  49. Parameters:
  50. | *[in]* **box** bounding box 1
  51. | *[in]* **cropBox** crop box
  52. | *[out]* **dest** cropped bounding box
  53. .. c:function:: void glm_aabb_crop_until(vec3 box[2], vec3 cropBox[2], vec3 clampBox[2], vec3 dest[2])
  54. | crops a bounding box with another one.
  55. this could be useful for getting a bbox which fits with view frustum and
  56. object bounding boxes. In this case you crop view frustum box with objects
  57. box
  58. Parameters:
  59. | *[in]* **box** bounding box
  60. | *[in]* **cropBox** crop box
  61. | *[in]* **clampBox** minimum box
  62. | *[out]* **dest** cropped bounding box
  63. .. c:function:: bool glm_aabb_frustum(vec3 box[2], vec4 planes[6])
  64. | check if AABB intersects with frustum planes
  65. this could be useful for frustum culling using AABB.
  66. OPTIMIZATION HINT:
  67. if planes order is similar to LEFT, RIGHT, BOTTOM, TOP, NEAR, FAR
  68. then this method should run even faster because it would only use two
  69. planes if object is not inside the two planes
  70. fortunately cglm extracts planes as this order! just pass what you got!
  71. Parameters:
  72. | *[in]* **box** bounding box
  73. | *[out]* **planes** frustum planes
  74. .. c:function:: void glm_aabb_invalidate(vec3 box[2])
  75. | invalidate AABB min and max values
  76. | It fills *max* values with -FLT_MAX and *min* values with +FLT_MAX
  77. Parameters:
  78. | *[in, out]* **box** bounding box
  79. .. c:function:: bool glm_aabb_isvalid(vec3 box[2])
  80. | check if AABB is valid or not
  81. Parameters:
  82. | *[in]* **box** bounding box
  83. Returns:
  84. returns true if aabb is valid otherwise false
  85. .. c:function:: float glm_aabb_size(vec3 box[2])
  86. | distance between of min and max
  87. Parameters:
  88. | *[in]* **box** bounding box
  89. Returns:
  90. distance between min - max
  91. .. c:function:: float glm_aabb_radius(vec3 box[2])
  92. | radius of sphere which surrounds AABB
  93. Parameters:
  94. | *[in]* **box** bounding box
  95. .. c:function:: void glm_aabb_center(vec3 box[2], vec3 dest)
  96. | computes center point of AABB
  97. Parameters:
  98. | *[in]* **box** bounding box
  99. | *[out]* **dest** center of bounding box
  100. .. c:function:: bool glm_aabb_aabb(vec3 box[2], vec3 other[2])
  101. | check if two AABB intersects
  102. Parameters:
  103. | *[in]* **box** bounding box
  104. | *[out]* **other** other bounding box
  105. .. c:function:: bool glm_aabb_sphere(vec3 box[2], vec4 s)
  106. | check if AABB intersects with sphere
  107. | https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
  108. | Solid Box - Solid Sphere test.
  109. Parameters:
  110. | *[in]* **box** solid bounding box
  111. | *[out]* **s** solid sphere
  112. .. c:function:: bool glm_aabb_point(vec3 box[2], vec3 point)
  113. | check if point is inside of AABB
  114. Parameters:
  115. | *[in]* **box** bounding box
  116. | *[out]* **point** point
  117. .. c:function:: bool glm_aabb_contains(vec3 box[2], vec3 other[2])
  118. | check if AABB contains other AABB
  119. Parameters:
  120. | *[in]* **box** bounding box
  121. | *[out]* **other** other bounding box