Upgrade Bullet to version 2.83.
[blender.git] / extern / bullet2 / src / BulletDynamics / Featherstone / btMultiBodyLinkCollider.h
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