Blender V4.3
btMultiBodyLinkCollider.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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
32class btMultiBodyLinkCollider : public btCollisionObject
33{
34 //protected:
35public:
37 int m_link;
38
40 {
41
42 }
44 : m_multiBody(multiBody),
45 m_link(link)
46 {
47 m_checkCollideWith = true;
48 //we need to remove the 'CF_STATIC_OBJECT' flag, otherwise links/base doesn't merge islands
49 //this means that some constraints might point to bodies that are not in the islands, causing crashes
50 //if (link>=0 || (multiBody && !multiBody->hasFixedBase()))
51 {
53 }
54 // else
55 //{
56 // m_collisionFlags |= (btCollisionObject::CF_STATIC_OBJECT);
57 //}
58
60 }
61 static btMultiBodyLinkCollider* upcast(btCollisionObject* colObj)
62 {
63 if (colObj->getInternalType() & btCollisionObject::CO_FEATHERSTONE_LINK)
64 return (btMultiBodyLinkCollider*)colObj;
65 return 0;
66 }
67 static const btMultiBodyLinkCollider* upcast(const btCollisionObject* colObj)
68 {
69 if (colObj->getInternalType() & btCollisionObject::CO_FEATHERSTONE_LINK)
70 return (btMultiBodyLinkCollider*)colObj;
71 return 0;
72 }
73
74 virtual bool checkCollideWithOverride(const btCollisionObject* co) const
75 {
77 if (!other)
78 return true;
79 if (other->m_multiBody != this->m_multiBody)
80 return true;
81 if (!m_multiBody->hasSelfCollision())
82 return false;
83
84 //check if 'link' has collision disabled
85 if (m_link >= 0)
86 {
87 const btMultibodyLink& link = m_multiBody->getLink(this->m_link);
89 {
90 int parent_of_this = m_link;
91 while (1)
92 {
93 if (parent_of_this == -1)
94 break;
95 parent_of_this = m_multiBody->getLink(parent_of_this).m_parent;
96 if (parent_of_this == other->m_link)
97 {
98 return false;
99 }
100 }
101 }
103 {
104 if (link.m_parent == other->m_link)
105 return false;
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// clang-format off
140
148
156
157// clang-format on
158
163
164SIMD_FORCE_INLINE const char* btMultiBodyLinkCollider::serialize(void* dataBuffer, class btSerializer* serializer) const
165{
167 btCollisionObject::serialize(&dataOut->m_colObjData, serializer);
168
169 dataOut->m_link = this->m_link;
170 dataOut->m_multiBody = (btMultiBodyData*)serializer->getUniquePointer(m_multiBody);
171
172 // Fill padding with zeros to appease msan.
173 memset(dataOut->m_padding, 0, sizeof(dataOut->m_padding));
174
176}
177
178#endif //BT_FEATHERSTONE_LINK_COLLIDER_H
@ CF_STATIC_OBJECT
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
@ CO_FEATHERSTONE_LINK
virtual ~btCollisionObject()
int m_collisionFlags
int m_internalType
#define btMultiBodyLinkColliderData
#define btMultiBodyLinkColliderDataName
#define btMultiBodyData
serialization data, don't change them if you are not familiar with the details of the serialization m...
Definition btMultiBody.h:40
btMultiBody
Definition btMultiBody.h:51
#define SIMD_FORCE_INLINE
Definition btScalar.h:280
btMultiBodyLinkCollider(btMultiBody *multiBody, int link)
static const btMultiBodyLinkCollider * upcast(const btCollisionObject *colObj)
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
virtual int calculateSerializeBufferSize() const
virtual void * getUniquePointer(void *oldPtr)=0
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btCollisionObjectDoubleData m_colObjData
btCollisionObjectFloatData m_colObjData