OPC_AABBCollider.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /*
  3. * OPCODE - Optimized Collision Detection
  4. * Copyright (C) 2001 Pierre Terdiman
  5. * Homepage: http://www.codercorner.com/Opcode.htm
  6. */
  7. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. /**
  10. * Contains code for an AABB collider.
  11. * \file OPC_AABBCollider.h
  12. * \author Pierre Terdiman
  13. * \date January, 1st, 2002
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. // Include Guard
  18. #ifndef __OPC_AABBCOLLIDER_H__
  19. #define __OPC_AABBCOLLIDER_H__
  20. struct OPCODE_API AABBCache : VolumeCache
  21. {
  22. AABBCache() : FatCoeff(1.1f)
  23. {
  24. FatBox.mCenter.Zero();
  25. FatBox.mExtents.Zero();
  26. }
  27. // Cached faces signature
  28. CollisionAABB FatBox; //!< Box used when performing the query resulting in cached faces
  29. // User settings
  30. float FatCoeff; //!< mRadius2 multiplier used to create a fat sphere
  31. };
  32. class OPCODE_API AABBCollider : public VolumeCollider
  33. {
  34. public:
  35. // Constructor / Destructor
  36. AABBCollider();
  37. virtual ~AABBCollider();
  38. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. /**
  40. * Generic collision query for generic OPCODE models. After the call, access the results:
  41. * - with GetContactStatus()
  42. * - with GetNbTouchedPrimitives()
  43. * - with GetTouchedPrimitives()
  44. *
  45. * \param cache [in/out] a box cache
  46. * \param box [in] collision AABB in world space
  47. * \param model [in] Opcode model to collide with
  48. * \return true if success
  49. * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
  50. */
  51. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. bool Collide(AABBCache& cache, const CollisionAABB& box, const Model& model);
  53. //
  54. bool Collide(AABBCache& cache, const CollisionAABB& box, const AABBTree* tree);
  55. protected:
  56. CollisionAABB mBox; //!< Query box in (center, extents) form
  57. Point mMin; //!< Query box min point
  58. Point mMax; //!< Query box max point
  59. // Leaf description
  60. Point mLeafVerts[3]; //!< Triangle vertices
  61. // Internal methods
  62. void _Collide(const AABBCollisionNode* node);
  63. void _Collide(const AABBNoLeafNode* node);
  64. void _Collide(const AABBQuantizedNode* node);
  65. void _Collide(const AABBQuantizedNoLeafNode* node);
  66. void _Collide(const AABBTreeNode* node);
  67. void _CollideNoPrimitiveTest(const AABBCollisionNode* node);
  68. void _CollideNoPrimitiveTest(const AABBNoLeafNode* node);
  69. void _CollideNoPrimitiveTest(const AABBQuantizedNode* node);
  70. void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node);
  71. // Overlap tests
  72. inline_ BOOL AABBContainsBox(const Point& bc, const Point& be);
  73. inline_ BOOL AABBAABBOverlap(const Point& b, const Point& Pb);
  74. inline_ BOOL TriBoxOverlap();
  75. // Init methods
  76. BOOL InitQuery(AABBCache& cache, const CollisionAABB& box);
  77. };
  78. class OPCODE_API HybridAABBCollider : public AABBCollider
  79. {
  80. public:
  81. // Constructor / Destructor
  82. HybridAABBCollider();
  83. virtual ~HybridAABBCollider();
  84. bool Collide(AABBCache& cache, const CollisionAABB& box, const HybridModel& model);
  85. protected:
  86. OPC_Container mTouchedBoxes;
  87. };
  88. #endif // __OPC_AABBCOLLIDER_H__