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"
23 
24 #ifdef BT_USE_DOUBLE_PRECISION
25 #define btMultiBodyLinkColliderData btMultiBodyLinkColliderDoubleData
26 #define btMultiBodyLinkColliderDataName "btMultiBodyLinkColliderDoubleData"
27 #else
28 #define btMultiBodyLinkColliderData btMultiBodyLinkColliderFloatData
29 #define btMultiBodyLinkColliderDataName "btMultiBodyLinkColliderFloatData"
30 #endif
31 
32 
34 {
35 //protected:
36 public:
37 
39  int m_link;
40 
41 
42  btMultiBodyLinkCollider (btMultiBody* multiBody,int link)
43  :m_multiBody(multiBody),
44  m_link(link)
45  {
46  m_checkCollideWith = true;
47  //we need to remove the 'CF_STATIC_OBJECT' flag, otherwise links/base doesn't merge islands
48  //this means that some constraints might point to bodies that are not in the islands, causing crashes
49  //if (link>=0 || (multiBody && !multiBody->hasFixedBase()))
50  {
52  }
53  // else
54  //{
55  // m_collisionFlags |= (btCollisionObject::CF_STATIC_OBJECT);
56  //}
57 
59  }
61  {
63  return (btMultiBodyLinkCollider*)colObj;
64  return 0;
65  }
66  static const btMultiBodyLinkCollider* upcast(const btCollisionObject* colObj)
67  {
69  return (btMultiBodyLinkCollider*)colObj;
70  return 0;
71  }
72 
73  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
74  {
76  if (!other)
77  return true;
78  if (other->m_multiBody != this->m_multiBody)
79  return true;
80  if (!m_multiBody->hasSelfCollision())
81  return false;
82 
83  //check if 'link' has collision disabled
84  if (m_link>=0)
85  {
86  const btMultibodyLink& link = m_multiBody->getLink(this->m_link);
88  {
89  int parent_of_this = m_link;
90  while (1)
91  {
92  if (parent_of_this==-1)
93  break;
94  parent_of_this = m_multiBody->getLink(parent_of_this).m_parent;
95  if (parent_of_this==other->m_link)
96  {
97  return false;
98  }
99  }
100  }
102  {
103  if ( link.m_parent == other->m_link)
104  return false;
105  }
106 
107  }
108 
109  if (other->m_link>=0)
110  {
111  const btMultibodyLink& otherLink = other->m_multiBody->getLink(other->m_link);
113  {
114  int parent_of_other = other->m_link;
115  while (1)
116  {
117  if (parent_of_other==-1)
118  break;
119  parent_of_other = m_multiBody->getLink(parent_of_other).m_parent;
120  if (parent_of_other==this->m_link)
121  return false;
122  }
123  }
125  {
126  if (otherLink.m_parent == this->m_link)
127  return false;
128  }
129  }
130  return true;
131  }
132 
133  virtual int calculateSerializeBufferSize() const;
134 
136  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
137 
138 };
139 
140 
142 {
145  int m_link;
146  char m_padding[4];
147 };
148 
150 {
153  int m_link;
154  char m_padding[4];
155 };
156 
158 {
159  return sizeof(btMultiBodyLinkColliderData);
160 }
161 
162 SIMD_FORCE_INLINE const char* btMultiBodyLinkCollider::serialize(void* dataBuffer, class btSerializer* serializer) const
163 {
165  btCollisionObject::serialize(&dataOut->m_colObjData,serializer);
166 
167  dataOut->m_link = this->m_link;
168  dataOut->m_multiBody = (btMultiBodyData*)serializer->getUniquePointer(m_multiBody);
169 
170  // Fill padding with zeros to appease msan.
171  memset(dataOut->m_padding, 0, sizeof(dataOut->m_padding));
172 
174 }
175 
176 #endif //BT_FEATHERSTONE_LINK_COLLIDER_H
177 
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
const btMultibodyLink & getLink(int index) const
Definition: btMultiBody.h:119
int getInternalType() const
reserved for Bullet internal usage
virtual void * getUniquePointer(void *oldPtr)=0
#define btMultiBodyLinkColliderDataName
btCollisionObjectDoubleData m_colObjData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btMultiBody.h:798
btCollisionObjectFloatData m_colObjData
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
btMultiBodyLinkCollider(btMultiBody *multiBody, int link)
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
#define btMultiBodyLinkColliderData
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:543
#define btMultiBodyData
serialization data, don't change them if you are not familiar with the details of the serialization m...
Definition: btMultiBody.h:42
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btMultiBody.h:817
virtual int calculateSerializeBufferSize() const