gjk.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GJK_H_
  23. #define _GJK_H_
  24. #ifndef _MMATH_H_
  25. #include "math/mMath.h"
  26. #endif
  27. #ifndef _TVECTOR_H_
  28. #include "core/util/tVector.h"
  29. #endif
  30. #ifndef _CONVEX_H_
  31. #include "collision/convex.h"
  32. #endif
  33. class Convex;
  34. struct CollisionStateList;
  35. struct Collision;
  36. //----------------------------------------------------------------------------
  37. struct GjkCollisionState: public CollisionState
  38. {
  39. /// @name Temporary values
  40. /// @{
  41. Point3F mP[4]; ///< support points of object A in local coordinates
  42. Point3F mQ[4]; ///< support points of object B in local coordinates
  43. VectorF mY[4]; ///< support points of A - B in world coordinates
  44. S32 mBits; ///< identifies current simplex
  45. S32 mAll_bits; ///< all_bits = bits | last_bit
  46. F32 mDet[16][4]; ///< cached sub-determinants
  47. F32 mDP[4][4]; ///< cached dot products
  48. S32 mLast; ///< identifies last found support point
  49. S32 mLast_bit; ///< last_bit = 1<<last
  50. /// @}
  51. ///
  52. void compute_det();
  53. bool valid(S32 s);
  54. void compute_vector(S32 bits, VectorF& v);
  55. bool closest(VectorF& v);
  56. bool degenerate(const VectorF& w);
  57. void nextBit();
  58. void swap();
  59. void reset(const MatrixF& a2w, const MatrixF& b2w);
  60. GjkCollisionState();
  61. ~GjkCollisionState();
  62. void set(Convex* a,Convex* b,const MatrixF& a2w, const MatrixF& b2w);
  63. void getCollisionInfo(const MatrixF& mat, Collision* info);
  64. void getClosestPoints(Point3F& p1, Point3F& p2);
  65. bool intersect(const MatrixF& a2w, const MatrixF& b2w);
  66. F32 distance(const MatrixF& a2w, const MatrixF& b2w, const F32 dontCareDist,
  67. const MatrixF* w2a = NULL, const MatrixF* _w2b = NULL);
  68. };
  69. #endif