CollisionAlgorithms.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef ANKI_COLLISION_COLLISION_ALGORITHMS_H
  2. #define ANKI_COLLISION_COLLISION_ALGORITHMS_H
  3. #include "anki/collision/Forward.h"
  4. #include "anki/util/StdTypes.h"
  5. namespace anki {
  6. namespace detail {
  7. /// @addtogroup Collision
  8. /// @{
  9. /// @addtogroup Algorithms
  10. /// Provides the collision algorithms that detect collision between various
  11. /// shapes
  12. /// @code
  13. /// +------+------+------+------+------+------+------+------+
  14. /// | | LS | OBB | FRU | P | R | S | AABB |
  15. /// +------+------+------+------+------+------+------+------+
  16. /// | LS | N/A | OK | N/I | OK | N/A | OK | OK |
  17. /// +------+------+------+------+------+------+------+------+
  18. /// | OBB | | OK | N/I | OK | OK | OK | OK |
  19. /// +------+------+------+------+------+------+------+------+
  20. /// | FRU | | | N/I | N/I | N/I | N/I | N/I |
  21. /// +------+------+------+------+------+------+------+------+
  22. /// | P | | | | OK | OK | OK | OK |
  23. /// +------+------+------+------+------+------+------+------+
  24. /// | R | | | | | N/A | OK | OK |
  25. /// +------+------+------+------+------+------+------+------+
  26. /// | S | | | | | | OK | OK |
  27. /// +------+------+------+------+------+------+------+------+
  28. /// | AABB | | | | | | | OK |
  29. /// +------+------+------+------+------+------+------+------+
  30. /// @endcode
  31. /// @{
  32. /// Generic collide function. It doesn't uses visitor pattern for
  33. /// speed reasons
  34. extern Bool collide(const CollisionShape& a, const CollisionShape& b);
  35. // 1st line (LS)
  36. extern Bool collide(const LineSegment& a, const LineSegment& b);
  37. extern Bool collide(const LineSegment& a, const Obb& b);
  38. extern Bool collide(const LineSegment& a, const Frustum& b);
  39. extern Bool collide(const LineSegment& a, const Plane& b);
  40. extern Bool collide(const LineSegment& a, const Ray& b);
  41. extern Bool collide(const LineSegment& a, const Sphere& b);
  42. extern Bool collide(const LineSegment& a, const Aabb& b);
  43. // 2nd line (OBB)
  44. inline Bool collide(const Obb& a, const LineSegment& b)
  45. {
  46. return collide(b, a);
  47. }
  48. extern Bool collide(const Obb& a, const Obb& b);
  49. extern Bool collide(const Obb& a, const Frustum& b);
  50. extern Bool collide(const Obb& a, const Plane& b);
  51. extern Bool collide(const Obb& a, const Ray& b);
  52. extern Bool collide(const Obb& a, const Sphere& b);
  53. extern Bool collide(const Obb& a, const Aabb& b);
  54. // 3rd line (FRU)
  55. inline Bool collide(const Frustum& a, const LineSegment& b)
  56. {
  57. return collide(b, a);
  58. }
  59. inline Bool collide(const Frustum& a, const Obb& b)
  60. {
  61. return collide(b, a);
  62. }
  63. extern Bool collide(const Frustum& a, const Frustum& b);
  64. extern Bool collide(const Frustum& a, const Plane& b);
  65. extern Bool collide(const Frustum& a, const Ray& b);
  66. extern Bool collide(const Frustum& a, const Sphere& b);
  67. extern Bool collide(const Frustum& a, const Aabb& b);
  68. // 4th line (P)
  69. inline Bool collide(const Plane& a, const LineSegment& b)
  70. {
  71. return collide(b, a);
  72. }
  73. inline Bool collide(const Plane& a, const Obb& b)
  74. {
  75. return collide(b, a);
  76. }
  77. inline Bool collide(const Plane& a,const Frustum& b)
  78. {
  79. return collide(b, a);
  80. }
  81. extern Bool collide(const Plane& a, const Plane& b);
  82. extern Bool collide(const Plane& a, const Ray& b);
  83. extern Bool collide(const Plane& a, const Sphere& b);
  84. extern Bool collide(const Plane& a, const Aabb& b);
  85. // 5th line (R)
  86. inline Bool collide(const Ray& a, const LineSegment& b)
  87. {
  88. return collide(b, a);
  89. }
  90. inline Bool collide(const Ray& a, const Obb& b)
  91. {
  92. return collide(b, a);
  93. }
  94. inline Bool collide(const Ray& a, const Frustum& b)
  95. {
  96. return collide(b, a);
  97. }
  98. inline Bool collide(const Ray& a, const Plane& b)
  99. {
  100. return collide(b, a);
  101. }
  102. extern Bool collide(const Ray& a, const Ray& b);
  103. extern Bool collide(const Ray& a, const Sphere& b);
  104. extern Bool collide(const Ray& a, const Aabb& b);
  105. // 6th line (S)
  106. inline Bool collide(const Sphere& a, const LineSegment& b)
  107. {
  108. return collide(b, a);
  109. }
  110. inline Bool collide(const Sphere& a, const Obb& b)
  111. {
  112. return collide(b, a);
  113. }
  114. inline Bool collide(const Sphere& a, const Frustum& b)
  115. {
  116. return collide(b, a);
  117. }
  118. inline Bool collide(const Sphere& a, const Plane& b)
  119. {
  120. return collide(b, a);
  121. }
  122. inline Bool collide(const Sphere& a, const Ray& b)
  123. {
  124. return collide(b, a);
  125. }
  126. extern Bool collide(const Sphere& a, const Sphere& b);
  127. extern Bool collide(const Sphere& a, const Aabb& b);
  128. // 7th line (AABB)
  129. inline Bool collide(const Aabb& a, const LineSegment& b)
  130. {
  131. return collide(b, a);
  132. }
  133. inline Bool collide(const Aabb& a, const Obb& b)
  134. {
  135. return collide(b, a);
  136. }
  137. inline Bool collide(const Aabb& a, const Frustum& b)
  138. {
  139. return collide(b, a);
  140. }
  141. inline Bool collide(const Aabb& a, const Plane& b)
  142. {
  143. return collide(b, a);
  144. }
  145. inline Bool collide(const Aabb& a, const Ray& b)
  146. {
  147. return collide(b, a);
  148. }
  149. inline Bool collide(const Aabb& a, const Sphere& b)
  150. {
  151. return collide(b, a);
  152. }
  153. extern Bool collide(const Aabb& a, const Aabb& b);
  154. /// @}
  155. /// @}
  156. } // end namespace detail
  157. } // end namespace anki
  158. #endif