Bullet Collision Detection & Physics Library
btManifoldResult.cpp
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 #include "btManifoldResult.h"
21 
24 
25 
26 
29 {
30  btScalar friction = body0->getRollingFriction() * body1->getRollingFriction();
31 
32  const btScalar MAX_FRICTION = btScalar(10.);
33  if (friction < -MAX_FRICTION)
34  friction = -MAX_FRICTION;
35  if (friction > MAX_FRICTION)
36  friction = MAX_FRICTION;
37  return friction;
38 
39 }
40 
41 
44 {
45  btScalar friction = body0->getFriction() * body1->getFriction();
46 
47  const btScalar MAX_FRICTION = btScalar(10.);
48  if (friction < -MAX_FRICTION)
49  friction = -MAX_FRICTION;
50  if (friction > MAX_FRICTION)
51  friction = MAX_FRICTION;
52  return friction;
53 
54 }
55 
57 {
58  return body0->getRestitution() * body1->getRestitution();
59 }
60 
61 
62 
64  :m_manifoldPtr(0),
65  m_body0Wrap(body0Wrap),
66  m_body1Wrap(body1Wrap)
67 #ifdef DEBUG_PART_INDEX
68  ,m_partId0(-1),
69  m_partId1(-1),
70  m_index0(-1),
71  m_index1(-1)
72 #endif //DEBUG_PART_INDEX
73 {
74 }
75 
76 
77 void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
78 {
80  //order in manifold needs to match
81 
83 // if (depth > m_manifoldPtr->getContactProcessingThreshold())
84  return;
85 
86  bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
87 
88  btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
89 
90  btVector3 localA;
91  btVector3 localB;
92 
93  if (isSwapped)
94  {
96  localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
97  } else
98  {
100  localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
101  }
102 
103  btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
104  newPt.m_positionWorldOnA = pointA;
105  newPt.m_positionWorldOnB = pointInWorld;
106 
107  int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
108 
113 
114 
115 
116  //BP mod, store contact triangles.
117  if (isSwapped)
118  {
119  newPt.m_partId0 = m_partId1;
120  newPt.m_partId1 = m_partId0;
121  newPt.m_index0 = m_index1;
122  newPt.m_index1 = m_index0;
123  } else
124  {
125  newPt.m_partId0 = m_partId0;
126  newPt.m_partId1 = m_partId1;
127  newPt.m_index0 = m_index0;
128  newPt.m_index1 = m_index1;
129  }
130  //printf("depth=%f\n",depth);
132  if (insertIndex >= 0)
133  {
134  //const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
135  m_manifoldPtr->replaceContactPoint(newPt,insertIndex);
136  } else
137  {
138  insertIndex = m_manifoldPtr->addManifoldPoint(newPt);
139  }
140 
141  //User can override friction and/or restitution
142  if (gContactAddedCallback &&
143  //and if either of the two bodies requires custom material
146  {
147  //experimental feature info, for per-triangle material etc.
148  const btCollisionObjectWrapper* obj0Wrap = isSwapped? m_body1Wrap : m_body0Wrap;
149  const btCollisionObjectWrapper* obj1Wrap = isSwapped? m_body0Wrap : m_body1Wrap;
150  (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
151  }
152 
153 }
154 
int getCacheEntry(const btManifoldPoint &newPoint) const
btVector3 m_lateralFrictionDir1
btScalar getContactBreakingThreshold() const
btPersistentManifold * m_manifoldPtr
btScalar m_combinedRestitution
void btPlaneSpace1(const T &n, T &p, T &q)
Definition: btVector3.h:1271
#define btAssert(x)
Definition: btScalar.h:101
ManifoldContactPoint collects and maintains persistent contactpoints.
int getCollisionFlags() const
const btCollisionObject * getBody0() const
const btCollisionObjectWrapper * m_body1Wrap
btScalar calculateCombinedRollingFriction(const btCollisionObject *body0, const btCollisionObject *body1)
User can override this material combiner by implementing gContactAddedCallback and setting body0->m_c...
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)
btScalar m_combinedRollingFriction
btTransform & getWorldTransform()
btVector3 m_normalWorldOnB
btVector3 m_positionWorldOnB
btCollisionObject can be used to manage collision detection objects.
btVector3 m_positionWorldOnA
m_positionWorldOnA is redundant information, see getPositionWorldOnA(), but for clarity ...
btScalar getRestitution() const
const btManifoldPoint & getContactPoint(int index) const
static btScalar calculateCombinedFriction(const btCollisionObject *body0, const btCollisionObject *body1)
User can override this material combiner by implementing gContactAddedCallback and setting body0->m_c...
btVector3 invXform(const btVector3 &inVec) const
Definition: btTransform.h:223
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btScalar getRollingFriction() const
btScalar getFriction() const
bool(* ContactAddedCallback)(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
ContactAddedCallback gContactAddedCallback
This is to allow MaterialCombiner/Custom Friction/Restitution values.
btScalar m_combinedFriction
const btCollisionObjectWrapper * m_body0Wrap
btVector3 m_lateralFrictionDir2
void replaceContactPoint(const btManifoldPoint &newPoint, int insertIndex)
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 ...
int addManifoldPoint(const btManifoldPoint &newPoint, bool isPredictive=false)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
const btCollisionObject * getCollisionObject() const