btMultiBodyLinkCollider.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_FEATHERSTONE_LINK_COLLIDER_H
  14. #define BT_FEATHERSTONE_LINK_COLLIDER_H
  15. #include "bullet/BulletCollision//CollisionDispatch/btCollisionObject.h"
  16. #include "btMultiBody.h"
  17. class btMultiBodyLinkCollider : public btCollisionObject
  18. {
  19. //protected:
  20. public:
  21. btMultiBody* m_multiBody;
  22. int m_link;
  23. btMultiBodyLinkCollider (btMultiBody* multiBody,int link)
  24. :m_multiBody(multiBody),
  25. m_link(link)
  26. {
  27. m_checkCollideWith = true;
  28. //we need to remove the 'CF_STATIC_OBJECT' flag, otherwise links/base doesn't merge islands
  29. //this means that some constraints might point to bodies that are not in the islands, causing crashes
  30. //if (link>=0 || (multiBody && !multiBody->hasFixedBase()))
  31. {
  32. m_collisionFlags &= (~btCollisionObject::CF_STATIC_OBJECT);
  33. }
  34. // else
  35. //{
  36. // m_collisionFlags |= (btCollisionObject::CF_STATIC_OBJECT);
  37. //}
  38. m_internalType = CO_FEATHERSTONE_LINK;
  39. }
  40. static btMultiBodyLinkCollider* upcast(btCollisionObject* colObj)
  41. {
  42. if (colObj->getInternalType()&btCollisionObject::CO_FEATHERSTONE_LINK)
  43. return (btMultiBodyLinkCollider*)colObj;
  44. return 0;
  45. }
  46. static const btMultiBodyLinkCollider* upcast(const btCollisionObject* colObj)
  47. {
  48. if (colObj->getInternalType()&btCollisionObject::CO_FEATHERSTONE_LINK)
  49. return (btMultiBodyLinkCollider*)colObj;
  50. return 0;
  51. }
  52. virtual bool checkCollideWithOverride(const btCollisionObject* co) const
  53. {
  54. const btMultiBodyLinkCollider* other = btMultiBodyLinkCollider::upcast(co);
  55. if (!other)
  56. return true;
  57. if (other->m_multiBody != this->m_multiBody)
  58. return true;
  59. if (!m_multiBody->hasSelfCollision())
  60. return false;
  61. //check if 'link' has collision disabled
  62. if (m_link>=0)
  63. {
  64. const btMultibodyLink& link = m_multiBody->getLink(this->m_link);
  65. if ((link.m_flags&BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION) && link.parent == other->m_link)
  66. return false;
  67. }
  68. if (other->m_link>=0)
  69. {
  70. const btMultibodyLink& otherLink = other->m_multiBody->getLink(other->m_link);
  71. if ((otherLink.m_flags& BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION) && otherLink.parent == this->m_link)
  72. return false;
  73. }
  74. return true;
  75. }
  76. };
  77. #endif //BT_FEATHERSTONE_LINK_COLLIDER_H