CollisionAlgorithms.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (C) 2014, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_COLLISION_COLLISION_ALGORITHMS_H
  6. #define ANKI_COLLISION_COLLISION_ALGORITHMS_H
  7. #include "anki/collision/Forward.h"
  8. #include "anki/util/StdTypes.h"
  9. namespace anki {
  10. namespace detail {
  11. /// @addtogroup Collision
  12. /// @{
  13. /// @addtogroup Algorithms
  14. /// Provides the collision algorithms that detect collision between various
  15. /// shapes
  16. /// @code
  17. /// +------+------+------+------+------+------+------+
  18. /// | | LS | OBB | P | R | S | AABB |
  19. /// +------+------+------+------+------+------+------+
  20. /// | LS | N/A | OK | OK | N/A | OK | OK |
  21. /// +------+------+------+------+------+------+------+
  22. /// | OBB | | OK | OK | OK | OK | OK |
  23. /// +------+------+------+------+------+------+------+
  24. /// | P | | | OK | OK | OK | OK |
  25. /// +------+------+------+------+------+------+------+
  26. /// | R | | | | N/A | OK | OK |
  27. /// +------+------+------+------+------+------+------+
  28. /// | S | | | | | OK | OK |
  29. /// +------+------+------+------+------+------+------+
  30. /// | AABB | | | | | | OK |
  31. /// +------+------+------+------+------+------+------+
  32. /// @endcode
  33. /// @{
  34. /// Generic collide function. It doesn't uses visitor pattern for
  35. /// speed reasons
  36. extern Bool collide(const CollisionShape& a, const CollisionShape& b);
  37. // 1st line (LS)
  38. extern Bool collide(const LineSegment& a, const LineSegment& b);
  39. extern Bool collide(const LineSegment& a, const Obb& b);
  40. extern Bool collide(const LineSegment& a, const Plane& b);
  41. extern Bool collide(const LineSegment& a, const Ray& b);
  42. extern Bool collide(const LineSegment& a, const Sphere& b);
  43. extern Bool collide(const LineSegment& a, const Aabb& b);
  44. // 2nd line (OBB)
  45. inline Bool collide(const Obb& a, const LineSegment& b)
  46. {
  47. return collide(b, a);
  48. }
  49. extern Bool collide(const Obb& a, const Obb& 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. // 4th line (P)
  55. inline Bool collide(const Plane& a, const LineSegment& b)
  56. {
  57. return collide(b, a);
  58. }
  59. inline Bool collide(const Plane& a, const Obb& b)
  60. {
  61. return collide(b, a);
  62. }
  63. extern Bool collide(const Plane& a, const Plane& b);
  64. extern Bool collide(const Plane& a, const Ray& b);
  65. extern Bool collide(const Plane& a, const Sphere& b);
  66. extern Bool collide(const Plane& a, const Aabb& b);
  67. // 5th line (R)
  68. inline Bool collide(const Ray& a, const LineSegment& b)
  69. {
  70. return collide(b, a);
  71. }
  72. inline Bool collide(const Ray& a, const Obb& b)
  73. {
  74. return collide(b, a);
  75. }
  76. inline Bool collide(const Ray& a, const Plane& b)
  77. {
  78. return collide(b, a);
  79. }
  80. extern Bool collide(const Ray& a, const Ray& b);
  81. extern Bool collide(const Ray& a, const Sphere& b);
  82. extern Bool collide(const Ray& a, const Aabb& b);
  83. // 6th line (S)
  84. inline Bool collide(const Sphere& a, const LineSegment& b)
  85. {
  86. return collide(b, a);
  87. }
  88. inline Bool collide(const Sphere& a, const Obb& b)
  89. {
  90. return collide(b, a);
  91. }
  92. inline Bool collide(const Sphere& a, const Plane& b)
  93. {
  94. return collide(b, a);
  95. }
  96. inline Bool collide(const Sphere& a, const Ray& b)
  97. {
  98. return collide(b, a);
  99. }
  100. extern Bool collide(const Sphere& a, const Sphere& b);
  101. extern Bool collide(const Sphere& a, const Aabb& b);
  102. // 7th line (AABB)
  103. inline Bool collide(const Aabb& a, const LineSegment& b)
  104. {
  105. return collide(b, a);
  106. }
  107. inline Bool collide(const Aabb& a, const Obb& b)
  108. {
  109. return collide(b, a);
  110. }
  111. inline Bool collide(const Aabb& a, const Plane& b)
  112. {
  113. return collide(b, a);
  114. }
  115. inline Bool collide(const Aabb& a, const Ray& b)
  116. {
  117. return collide(b, a);
  118. }
  119. inline Bool collide(const Aabb& a, const Sphere& b)
  120. {
  121. return collide(b, a);
  122. }
  123. extern Bool collide(const Aabb& a, const Aabb& b);
  124. /// @}
  125. /// @}
  126. } // end namespace detail
  127. } // end namespace anki
  128. #endif