Bullet Collision Detection & Physics Library: btMultiBodyLinkCollider.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
19 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
20
21 #include "btMultiBody.h"
22
23 class btMultiBodyLinkCollider : public btCollisionObject
24 {
25 //protected:
26 public:
27
28 btMultiBody* m_multiBody;
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 {
41 m_collisionFlags &= (~btCollisionObject::CF_STATIC_OBJECT);
42 }
43 // else
44 //{
45 // m_collisionFlags |= (btCollisionObject::CF_STATIC_OBJECT);
46 //}
47
48 m_internalType = CO_FEATHERSTONE_LINK;
49 }
50 static btMultiBodyLinkCollider* upcast(btCollisionObject* colObj)
51 {
52 if (colObj->getInternalType()&btCollisionObject::CO_FEATHERSTONE_LINK)
53 return (btMultiBodyLinkCollider*)colObj;
54 return 0;
55 }
56 static const btMultiBodyLinkCollider* upcast(const btCollisionObject* colObj)
57 {
58 if (colObj->getInternalType()&btCollisionObject::CO_FEATHERSTONE_LINK)
59 return (btMultiBodyLinkCollider*)colObj;
60 return 0;
61 }
62
63 virtual bool checkCollideWithOverride(const btCollisionObject* co) const
64 {
65 const btMultiBodyLinkCollider* other = btMultiBodyLinkCollider::upcast(co);
66 if (!other)
67 return true;
68 if (other->m_multiBody != this->m_multiBody)
69 return true;
70 if (!m_multiBody->hasSelfCollision())
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);
77 if ((link.m_flags&BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION) && link.m_parent == other->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.m_parent == this->m_link)
85 return false;
86 }
87 return true;
88 }
89 };
90
91 #endif //BT_FEATHERSTONE_LINK_COLLIDER_H
92
btMultiBodyLinkCollider::upcast
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
Definition: btMultiBodyLinkCollider.h:50
btMultiBody::getLink
const btMultibodyLink & getLink(int index) const
Definition: btMultiBody.h:118
BT_MULTIBODYLINKFLAGS_DISABLE_PARENT_COLLISION
Definition: btMultiBodyLink.h:25
btCollisionObject::getInternalType
int getInternalType() const
reserved for Bullet internal usage
Definition: btCollisionObject.h:322
btCollisionObject::CF_STATIC_OBJECT
Definition: btCollisionObject.h:124
btMultiBodyLinkCollider::checkCollideWithOverride
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
Definition: btMultiBodyLinkCollider.h:63
btMultibodyLink
Definition: btMultiBodyLink.h:47
btMultiBody
Definition: btMultiBody.h:48
btMultiBodyLinkCollider::btMultiBodyLinkCollider
btMultiBodyLinkCollider(btMultiBody *multiBody, int link)
Definition: btMultiBodyLinkCollider.h:32
btCollisionObject::CO_FEATHERSTONE_LINK
Definition: btCollisionObject.h:143
btCollisionObject::m_internalType
int m_internalType
m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
Definition: btCollisionObject.h:92
btMultiBodyLinkCollider::upcast
static const btMultiBodyLinkCollider * upcast(const btCollisionObject *colObj)
Definition: btMultiBodyLinkCollider.h:56
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btMultiBody::hasSelfCollision
bool hasSelfCollision() const
Definition: btMultiBody.h:574
btCollisionObject::m_collisionFlags
int m_collisionFlags
Definition: btCollisionObject.h:78
btMultibodyLink::m_flags
int m_flags
Definition: btMultiBodyLink.h:122
btMultiBody.h
btMultiBodyLinkCollider
Definition: btMultiBodyLinkCollider.h:23
btCollisionObject.h
btCollisionObject::m_checkCollideWith
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
Definition: btCollisionObject.h:110
btMultiBodyLinkCollider::m_link
int m_link
Definition: btMultiBodyLinkCollider.h:29
btMultiBodyLinkCollider::m_multiBody
btMultiBody * m_multiBody
Definition: btMultiBodyLinkCollider.h:28
btMultibodyLink::m_parent
int m_parent
Definition: btMultiBodyLink.h:55