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

Bullet Collision Detection & Physics Library

btManifoldResult.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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
17 #ifndef BT_MANIFOLD_RESULT_H
18 #define BT_MANIFOLD_RESULT_H
19
20 class btCollisionObject;
21 struct btCollisionObjectWrapper;
22
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btManifoldPoint;
25
26 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
27
28 #include "LinearMath/btTransform.h"
29 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
30 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
31
32 typedef bool (*ContactAddedCallback)(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
33 extern ContactAddedCallback gContactAddedCallback;
34
35 //#define DEBUG_PART_INDEX 1
36
37
39 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
40 {
41 protected:
42
43 btPersistentManifold* m_manifoldPtr;
44
45 const btCollisionObjectWrapper* m_body0Wrap;
46 const btCollisionObjectWrapper* m_body1Wrap;
47 int m_partId0;
48 int m_partId1;
49 int m_index0;
50 int m_index1;
51
52
53 public:
54
55 btManifoldResult()
56 :
57 #ifdef DEBUG_PART_INDEX
58
59 m_partId0(-1),
60 m_partId1(-1),
61 m_index0(-1),
62 m_index1(-1)
63 #endif //DEBUG_PART_INDEX
64 m_closestPointDistanceThreshold(0)
65 {
66 }
67
68 btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
69
70 virtual ~btManifoldResult() {};
71
72 void setPersistentManifold(btPersistentManifold* manifoldPtr)
73 {
74 m_manifoldPtr = manifoldPtr;
75 }
76
77 const btPersistentManifold* getPersistentManifold() const
78 {
79 return m_manifoldPtr;
80 }
81 btPersistentManifold* getPersistentManifold()
82 {
83 return m_manifoldPtr;
84 }
85
86 virtual void setShapeIdentifiersA(int partId0,int index0)
87 {
88 m_partId0=partId0;
89 m_index0=index0;
90 }
91
92 virtual void setShapeIdentifiersB( int partId1,int index1)
93 {
94 m_partId1=partId1;
95 m_index1=index1;
96 }
97
98
99 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth);
100
101 SIMD_FORCE_INLINE void refreshContactPoints()
102 {
103 btAssert(m_manifoldPtr);
104 if (!m_manifoldPtr->getNumContacts())
105 return;
106
107 bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
108
109 if (isSwapped)
110 {
111 m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(),m_body0Wrap->getCollisionObject()->getWorldTransform());
112 } else
113 {
114 m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(),m_body1Wrap->getCollisionObject()->getWorldTransform());
115 }
116 }
117
118 const btCollisionObjectWrapper* getBody0Wrap() const
119 {
120 return m_body0Wrap;
121 }
122 const btCollisionObjectWrapper* getBody1Wrap() const
123 {
124 return m_body1Wrap;
125 }
126
127 void setBody0Wrap(const btCollisionObjectWrapper* obj0Wrap)
128 {
129 m_body0Wrap = obj0Wrap;
130 }
131
132 void setBody1Wrap(const btCollisionObjectWrapper* obj1Wrap)
133 {
134 m_body1Wrap = obj1Wrap;
135 }
136
137 const btCollisionObject* getBody0Internal() const
138 {
139 return m_body0Wrap->getCollisionObject();
140 }
141
142 const btCollisionObject* getBody1Internal() const
143 {
144 return m_body1Wrap->getCollisionObject();
145 }
146
147 btScalar m_closestPointDistanceThreshold;
148
150 static btScalar calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1);
151 static btScalar calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1);
152 static btScalar calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1);
153 static btScalar calculateCombinedSpinningFriction(const btCollisionObject* body0,const btCollisionObject* body1);
154 static btScalar calculateCombinedContactDamping(const btCollisionObject* body0,const btCollisionObject* body1);
155 static btScalar calculateCombinedContactStiffness(const btCollisionObject* body0,const btCollisionObject* body1);
156 };
157
158 #endif //BT_MANIFOLD_RESULT_H
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:55
btManifoldResult::~btManifoldResult
virtual ~btManifoldResult()
Definition: btManifoldResult.h:70
btPersistentManifold::refreshContactPoints
void refreshContactPoints(const btTransform &trA, const btTransform &trB)
calculated new worldspace coordinates and depth, and reject points that exceed the collision margin ...
Definition: btPersistentManifold.cpp:247
btManifoldResult::getBody0Wrap
const btCollisionObjectWrapper * getBody0Wrap() const
Definition: btManifoldResult.h:118
btManifoldResult::calculateCombinedContactDamping
static btScalar calculateCombinedContactDamping(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btManifoldResult.cpp:71
btDiscreteCollisionDetectorInterface::Result
Definition: btDiscreteCollisionDetectorInterface.h:31
btManifoldResult::m_manifoldPtr
btPersistentManifold * m_manifoldPtr
Definition: btManifoldResult.h:43
btManifoldResult::getBody1Internal
const btCollisionObject * getBody1Internal() const
Definition: btManifoldResult.h:142
btManifoldResult::calculateCombinedRollingFriction
static btScalar calculateCombinedRollingFriction(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btManifoldResult.cpp:27
btManifoldResult::getPersistentManifold
btPersistentManifold * getPersistentManifold()
Definition: btManifoldResult.h:81
btManifoldResult::setPersistentManifold
void setPersistentManifold(btPersistentManifold *manifoldPtr)
Definition: btManifoldResult.h:72
btPersistentManifold::getNumContacts
int getNumContacts() const
Definition: btPersistentManifold.h:109
btAssert
#define btAssert(x)
Definition: btScalar.h:114
btManifoldResult::refreshContactPoints
void refreshContactPoints()
Definition: btManifoldResult.h:101
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:64
btManifoldResult::calculateCombinedContactStiffness
static btScalar calculateCombinedContactStiffness(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btManifoldResult.cpp:76
btPersistentManifold.h
btTransform.h
btManifoldPoint
ManifoldContactPoint collects and maintains persistent contactpoints.
Definition: btManifoldPoint.h:48
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:39
btManifoldResult::m_body1Wrap
const btCollisionObjectWrapper * m_body1Wrap
Definition: btManifoldResult.h:46
btManifoldResult::setShapeIdentifiersA
virtual void setShapeIdentifiersA(int partId0, int index0)
setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material comb...
Definition: btManifoldResult.h:86
btManifoldResult::addContactPoint
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)
Definition: btManifoldResult.cpp:104
btCollisionObject::getWorldTransform
btTransform & getWorldTransform()
Definition: btCollisionObject.h:370
btManifoldResult::m_closestPointDistanceThreshold
btScalar m_closestPointDistanceThreshold
Definition: btManifoldResult.h:147
btPersistentManifold::getBody0
const btCollisionObject * getBody0() const
Definition: btPersistentManifold.h:94
btCollisionObjectWrapper::getCollisionObject
const btCollisionObject * getCollisionObject() const
Definition: btCollisionObjectWrapper.h:39
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btManifoldResult::btManifoldResult
btManifoldResult()
Definition: btManifoldResult.h:55
btCollisionObjectWrapper.h
btManifoldResult::setShapeIdentifiersB
virtual void setShapeIdentifiersB(int partId1, int index1)
Definition: btManifoldResult.h:92
btManifoldResult::calculateCombinedFriction
static btScalar calculateCombinedFriction(const btCollisionObject *body0, const btCollisionObject *body1)
User can override this material combiner by implementing gContactAddedCallback and setting body0->m_c...
Definition: btManifoldResult.cpp:53
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ContactAddedCallback
bool(* ContactAddedCallback)(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
Definition: btManifoldResult.h:32
btManifoldResult::getBody0Internal
const btCollisionObject * getBody0Internal() const
Definition: btManifoldResult.h:137
btManifoldResult::calculateCombinedSpinningFriction
static btScalar calculateCombinedSpinningFriction(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btManifoldResult.cpp:40
btManifoldResult::m_index0
int m_index0
Definition: btManifoldResult.h:49
btManifoldResult::setBody1Wrap
void setBody1Wrap(const btCollisionObjectWrapper *obj1Wrap)
Definition: btManifoldResult.h:132
btCollisionObject.h
gContactAddedCallback
ContactAddedCallback gContactAddedCallback
This is to allow MaterialCombiner/Custom Friction/Restitution values.
Definition: btManifoldResult.cpp:23
btManifoldResult::getBody1Wrap
const btCollisionObjectWrapper * getBody1Wrap() const
Definition: btManifoldResult.h:122
btManifoldResult::m_body0Wrap
const btCollisionObjectWrapper * m_body0Wrap
Definition: btManifoldResult.h:45
btManifoldResult::m_index1
int m_index1
Definition: btManifoldResult.h:50
btManifoldResult::setBody0Wrap
void setBody0Wrap(const btCollisionObjectWrapper *obj0Wrap)
Definition: btManifoldResult.h:127
btManifoldResult::m_partId0
int m_partId0
Definition: btManifoldResult.h:47
btManifoldResult::calculateCombinedRestitution
static btScalar calculateCombinedRestitution(const btCollisionObject *body0, const btCollisionObject *body1)
in the future we can let the user override the methods to combine restitution and friction ...
Definition: btManifoldResult.cpp:66
btManifoldResult::getPersistentManifold
const btPersistentManifold * getPersistentManifold() const
Definition: btManifoldResult.h:77
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:17
btDiscreteCollisionDetectorInterface.h
btManifoldResult::m_partId1
int m_partId1
Definition: btManifoldResult.h:48
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279