Bullet Collision Detection & Physics Library
btMultiBodyLinkCollider.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_FEATHERSTONE_LINK_COLLIDER_H
17 #define BT_FEATHERSTONE_LINK_COLLIDER_H
18 
20 
21 #include "btMultiBody.h"
22 
24 {
25 //protected:
26 public:
27 
29  int m_link;
30 
31 
32  btMultiBodyLinkCollider (btMultiBody* multiBody,int link)
33  :m_multiBody(multiBody),
34  m_link(link)
35  {
36  m_checkCollideWith = true;
37  //we need to remove the 'CF_STATIC_OBJECT' flag, otherwise links/base doesn't merge islands
38  //this means that some constraints might point to bodies that are not in the islands, causing crashes
39  //if (link>=0 || (multiBody && !multiBody->hasFixedBase()))
40  {
42  }
43  // else
44  //{
45  // m_collisionFlags |= (btCollisionObject::CF_STATIC_OBJECT);
46  //}
47 
49  }
51  {
53  return (btMultiBodyLinkCollider*)colObj;
54  return 0;
55  }
56  static const btMultiBodyLinkCollider* upcast(const btCollisionObject* colObj)
57  {
59  return (btMultiBodyLinkCollider*)colObj;
60  return 0;
61  }
62 
63  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
64  {
66  if (!other)
67  return true;
68  if (other->m_multiBody != this->m_multiBody)
69  return true;
71  return false;
72 
73  //check if 'link' has collision disabled
74  if (m_link>=0)
75  {
76  const btMultibodyLink& link = m_multiBody->getLink(this->m_link);
78  {
79  int parent_of_this = m_link;
80  while (1)
81  {
82  if (parent_of_this==-1)
83  break;
84  parent_of_this = m_multiBody->getLink(parent_of_this).m_parent;
85  if (parent_of_this==other->m_link)
86  {
87  return false;
88  }
89  }
90  }
92  {
93  if ( link.m_parent == other->m_link)
94  return false;
95  }
96 
97  }
98 
99  if (other->m_link>=0)
100  {
101  const btMultibodyLink& otherLink = other->m_multiBody->getLink(other->m_link);
103  {
104  int parent_of_other = other->m_link;
105  while (1)
106  {
107  if (parent_of_other==-1)
108  break;
109  parent_of_other = m_multiBody->getLink(parent_of_other).m_parent;
110  if (parent_of_other==this->m_link)
111  return false;
112  }
113  }
115  {
116  if (otherLink.m_parent == this->m_link)
117  return false;
118  }
119  }
120  return true;
121  }
122 };
123 
124 #endif //BT_FEATHERSTONE_LINK_COLLIDER_H
125 
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btMultiBodyLinkCollider::upcast
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
Definition: btMultiBodyLinkCollider.h:50
btCollisionObject::~btCollisionObject
virtual ~btCollisionObject()
Definition: btCollisionObject.cpp:56
btCollisionObject::m_internalType
int m_internalType
m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody,...
Definition: btCollisionObject.h:98
btMultiBodyLinkCollider::btMultiBodyLinkCollider
btMultiBodyLinkCollider(btMultiBody *multiBody, int link)
Definition: btMultiBodyLinkCollider.h:32
btMultiBodyLinkCollider::upcast
static const btMultiBodyLinkCollider * upcast(const btCollisionObject *colObj)
Definition: btMultiBodyLinkCollider.h:56
btMultiBody::hasSelfCollision
bool hasSelfCollision() const
Definition: btMultiBody.h:543
btMultiBodyLinkCollider
Definition: btMultiBodyLinkCollider.h:23
btMultiBody::getLink
const btMultibodyLink & getLink(int index) const
Definition: btMultiBody.h:119
btMultiBody
Definition: btMultiBody.h:51
btCollisionObject::CF_STATIC_OBJECT
@ CF_STATIC_OBJECT
Definition: btCollisionObject.h:133
btCollisionObject::m_collisionFlags
int m_collisionFlags
Definition: btCollisionObject.h:78
btCollisionObject::CO_FEATHERSTONE_LINK
@ CO_FEATHERSTONE_LINK
Definition: btCollisionObject.h:156
btMultiBody.h
btMultiBodyLinkCollider::m_link
int m_link
Definition: btMultiBodyLinkCollider.h:29
btCollisionObject::getInternalType
int getInternalType() const
reserved for Bullet internal usage
Definition: btCollisionObject.h:367
btCollisionObject.h
btCollisionObject::m_checkCollideWith
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
Definition: btCollisionObject.h:118
btMultiBodyLinkCollider::m_multiBody
btMultiBody * m_multiBody
Definition: btMultiBodyLinkCollider.h:28
btMultiBodyLinkCollider::checkCollideWithOverride
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
Definition: btMultiBodyLinkCollider.h:63