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  return false;
79  }
80 
81  if (other->m_link>=0)
82  {
83  const btMultibodyLink& otherLink = other->m_multiBody->getLink(other->m_link);
84  if ((otherLink.m_flags& BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION) && otherLink.parent == this->m_link)
85  return false;
86  }
87  return true;
88  }
89 };
90 
91 #endif //BT_FEATHERSTONE_LINK_COLLIDER_H
92 
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
const btMultibodyLink & getLink(int index) const
Definition: btMultiBody.h:76
int getInternalType() const
reserved for Bullet internal usage
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
btMultiBodyLinkCollider(btMultiBody *multiBody, int link)
int m_internalType
m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
static const btMultiBodyLinkCollider * upcast(const btCollisionObject *colObj)
btCollisionObject can be used to manage collision detection objects.
bool hasSelfCollision() const
Definition: btMultiBody.h:394
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.