OPC_LSSCollider.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 LSS collider.
  11. * \file OPC_LSSCollider.h
  12. * \author Pierre Terdiman
  13. * \date December, 28, 2002
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. // Include Guard
  18. #ifndef __OPC_LSSCOLLIDER_H__
  19. #define __OPC_LSSCOLLIDER_H__
  20. struct OPCODE_API LSSCache : VolumeCache
  21. {
  22. LSSCache()
  23. {
  24. Previous.mP0 = Point(0.0f, 0.0f, 0.0f);
  25. Previous.mP1 = Point(0.0f, 0.0f, 0.0f);
  26. Previous.mRadius = 0.0f;
  27. FatCoeff = 1.1f;
  28. }
  29. // Cached faces signature
  30. LSS Previous; //!< LSS used when performing the query resulting in cached faces
  31. // User settings
  32. float FatCoeff; //!< mRadius2 multiplier used to create a fat LSS
  33. };
  34. class OPCODE_API LSSCollider : public VolumeCollider
  35. {
  36. public:
  37. // Constructor / Destructor
  38. LSSCollider();
  39. virtual ~LSSCollider();
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. /**
  42. * Generic collision query for generic OPCODE models. After the call, access the results:
  43. * - with GetContactStatus()
  44. * - with GetNbTouchedPrimitives()
  45. * - with GetTouchedPrimitives()
  46. *
  47. * \param cache [in/out] an lss cache
  48. * \param lss [in] collision lss in local space
  49. * \param model [in] Opcode model to collide with
  50. * \param worldl [in] lss world matrix, or null
  51. * \param worldm [in] model's world matrix, or null
  52. * \return true if success
  53. * \warning SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
  54. */
  55. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. bool Collide(LSSCache& cache, const LSS& lss, const Model& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
  57. //
  58. bool Collide(LSSCache& cache, const LSS& lss, const AABBTree* tree);
  59. protected:
  60. // LSS in model space
  61. Segment mSeg; //!< Segment
  62. float mRadius2; //!< LSS radius squared
  63. // Internal methods
  64. void _Collide(const AABBCollisionNode* node);
  65. void _Collide(const AABBNoLeafNode* node);
  66. void _Collide(const AABBQuantizedNode* node);
  67. void _Collide(const AABBQuantizedNoLeafNode* node);
  68. void _Collide(const AABBTreeNode* node);
  69. void _CollideNoPrimitiveTest(const AABBCollisionNode* node);
  70. void _CollideNoPrimitiveTest(const AABBNoLeafNode* node);
  71. void _CollideNoPrimitiveTest(const AABBQuantizedNode* node);
  72. void _CollideNoPrimitiveTest(const AABBQuantizedNoLeafNode* node);
  73. // Overlap tests
  74. inline_ BOOL LSSContainsBox(const Point& bc, const Point& be);
  75. inline_ BOOL LSSAABBOverlap(const Point& center, const Point& extents);
  76. inline_ BOOL LSSTriOverlap(const Point& vert0, const Point& vert1, const Point& vert2);
  77. // Init methods
  78. BOOL InitQuery(LSSCache& cache, const LSS& lss, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
  79. };
  80. class OPCODE_API HybridLSSCollider : public LSSCollider
  81. {
  82. public:
  83. // Constructor / Destructor
  84. HybridLSSCollider();
  85. virtual ~HybridLSSCollider();
  86. bool Collide(LSSCache& cache, const LSS& lss, const HybridModel& model, const Matrix4x4* worldl=null, const Matrix4x4* worldm=null);
  87. protected:
  88. OPC_Container mTouchedBoxes;
  89. };
  90. #endif // __OPC_LSSCOLLIDER_H__