/lib/ode/ode_source/OPCODE/OPC_VolumeCollider.h

http://narutortsproject.googlecode.com/ · C++ Header · 138 lines · 49 code · 18 blank · 71 comment · 1 complexity · 8d2c1144b61c2e529cb41b70d4ca40e0 MD5 · raw file

  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 base volume collider class.
  11. * \file OPC_VolumeCollider.h
  12. * \author Pierre Terdiman
  13. * \date June, 2, 2001
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. // Include Guard
  18. #ifndef __OPC_VOLUMECOLLIDER_H__
  19. #define __OPC_VOLUMECOLLIDER_H__
  20. struct OPCODE_API VolumeCache
  21. {
  22. VolumeCache() : Model(null) {}
  23. ~VolumeCache() {}
  24. Container TouchedPrimitives; //!< Indices of touched primitives
  25. const BaseModel* Model; //!< Owner
  26. };
  27. class OPCODE_API VolumeCollider : public Collider
  28. {
  29. public:
  30. // Constructor / Destructor
  31. VolumeCollider();
  32. virtual ~VolumeCollider() = 0;
  33. // Collision report
  34. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. /**
  36. * Gets the number of touched primitives after a collision query.
  37. * \see GetContactStatus()
  38. * \see GetTouchedPrimitives()
  39. * \return the number of touched primitives
  40. */
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. inline_ udword GetNbTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetNbEntries() : 0; }
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  44. /**
  45. * Gets the list of touched primitives after a collision query.
  46. * \see GetContactStatus()
  47. * \see GetNbTouchedPrimitives()
  48. * \return the list of touched primitives (primitive indices)
  49. */
  50. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. inline_ const udword* GetTouchedPrimitives() const { return mTouchedPrimitives ? mTouchedPrimitives->GetEntries() : null; }
  52. // Stats
  53. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  54. /**
  55. * Stats: gets the number of Volume-BV overlap tests after a collision query.
  56. * \see GetNbVolumePrimTests()
  57. * \return the number of Volume-BV tests performed during last query
  58. */
  59. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. inline_ udword GetNbVolumeBVTests() const { return mNbVolumeBVTests; }
  61. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. /**
  63. * Stats: gets the number of Volume-Triangle overlap tests after a collision query.
  64. * \see GetNbVolumeBVTests()
  65. * \return the number of Volume-Triangle tests performed during last query
  66. */
  67. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. inline_ udword GetNbVolumePrimTests() const { return mNbVolumePrimTests; }
  69. // Settings
  70. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. /**
  72. * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider.
  73. * \return null if everything is ok, else a string describing the problem
  74. */
  75. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. override(Collider) const char* ValidateSettings();
  77. protected:
  78. // Touched primitives
  79. Container* mTouchedPrimitives; //!< List of touched primitives
  80. // Dequantization coeffs
  81. Point mCenterCoeff;
  82. Point mExtentsCoeff;
  83. // Stats
  84. udword mNbVolumeBVTests; //!< Number of Volume-BV tests
  85. udword mNbVolumePrimTests; //!< Number of Volume-Primitive tests
  86. // Internal methods
  87. void _Dump(const AABBCollisionNode* node);
  88. void _Dump(const AABBNoLeafNode* node);
  89. void _Dump(const AABBQuantizedNode* node);
  90. void _Dump(const AABBQuantizedNoLeafNode* node);
  91. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. /**
  93. * Initializes a query
  94. */
  95. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  96. override(Collider) inline_ void InitQuery()
  97. {
  98. // Reset stats & contact status
  99. mNbVolumeBVTests = 0;
  100. mNbVolumePrimTests = 0;
  101. Collider::InitQuery();
  102. }
  103. inline_ BOOL IsCacheValid(VolumeCache& cache)
  104. {
  105. // We're going to do a volume-vs-model query.
  106. if(cache.Model!=mCurrentModel)
  107. {
  108. // Cached list was for another model so we can't keep it
  109. // Keep track of new owner and reset cache
  110. cache.Model = mCurrentModel;
  111. return FALSE;
  112. }
  113. else
  114. {
  115. // Same models, no problem
  116. return TRUE;
  117. }
  118. }
  119. };
  120. #endif // __OPC_VOLUMECOLLIDER_H__