CollisionAlgorithmsMatrix.h 4.9 KB

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