2
0

OPC_VolumeCollider.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.cpp
  12. * \author Pierre Terdiman
  13. * \date June, 2, 2001
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. /**
  18. * Contains the abstract class for volume colliders.
  19. *
  20. * \class VolumeCollider
  21. * \author Pierre Terdiman
  22. * \version 1.3
  23. * \date June, 2, 2001
  24. */
  25. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "Opcode.h"
  28. using namespace Opcode;
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. /**
  31. * Constructor.
  32. */
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. VolumeCollider::VolumeCollider() :
  35. mTouchedPrimitives (null),
  36. mNbVolumeBVTests (0),
  37. mNbVolumePrimTests (0)
  38. {
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. /**
  42. * Destructor.
  43. */
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. VolumeCollider::~VolumeCollider()
  46. {
  47. mTouchedPrimitives = null;
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. /**
  51. * Validates current settings. You should call this method after all the settings / callbacks have been defined for a collider.
  52. * \return null if everything is ok, else a string describing the problem
  53. */
  54. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. const char* VolumeCollider::ValidateSettings()
  56. {
  57. return null;
  58. }
  59. // Pretty dumb way to dump - to do better - one day...
  60. #define IMPLEMENT_NOLEAFDUMP(type) \
  61. void VolumeCollider::_Dump(const type* node) \
  62. { \
  63. if(node->HasPosLeaf()) mTouchedPrimitives->Add(node->GetPosPrimitive()); \
  64. else _Dump(node->GetPos()); \
  65. \
  66. if(ContactFound()) return; \
  67. \
  68. if(node->HasNegLeaf()) mTouchedPrimitives->Add(node->GetNegPrimitive()); \
  69. else _Dump(node->GetNeg()); \
  70. }
  71. #define IMPLEMENT_LEAFDUMP(type) \
  72. void VolumeCollider::_Dump(const type* node) \
  73. { \
  74. if(node->IsLeaf()) \
  75. { \
  76. mTouchedPrimitives->Add(node->GetPrimitive()); \
  77. } \
  78. else \
  79. { \
  80. _Dump(node->GetPos()); \
  81. \
  82. if(ContactFound()) return; \
  83. \
  84. _Dump(node->GetNeg()); \
  85. } \
  86. }
  87. IMPLEMENT_NOLEAFDUMP(AABBNoLeafNode)
  88. IMPLEMENT_NOLEAFDUMP(AABBQuantizedNoLeafNode)
  89. IMPLEMENT_LEAFDUMP(AABBCollisionNode)
  90. IMPLEMENT_LEAFDUMP(AABBQuantizedNode)