2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
17
#include "btManifoldResult.h"
18
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
19
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
22
///This is to allow MaterialCombiner/Custom Friction/Restitution values
23
ContactAddedCallback gContactAddedCallback=0;
25
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
26
inline btScalar calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
28
btScalar friction = body0->getFriction() * body1->getFriction();
30
const btScalar MAX_FRICTION = btScalar(10.);
31
if (friction < -MAX_FRICTION)
32
friction = -MAX_FRICTION;
33
if (friction > MAX_FRICTION)
34
friction = MAX_FRICTION;
39
inline btScalar calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
41
return body0->getRestitution() * body1->getRestitution();
46
btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* body1)
51
m_rootTransA = body0->getWorldTransform();
52
m_rootTransB = body1->getWorldTransform();
56
void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
58
assert(m_manifoldPtr);
59
//order in manifold needs to match
61
if (depth > m_manifoldPtr->getContactBreakingThreshold())
64
bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
66
btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
73
localA = m_rootTransB.invXform(pointA );
74
localB = m_rootTransA.invXform(pointInWorld);
77
localA = m_rootTransA.invXform(pointA );
78
localB = m_rootTransB.invXform(pointInWorld);
81
btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
82
newPt.m_positionWorldOnA = pointA;
83
newPt.m_positionWorldOnB = pointInWorld;
85
int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
87
newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
88
newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
90
//BP mod, store contact triangles.
91
newPt.m_partId0 = m_partId0;
92
newPt.m_partId1 = m_partId1;
93
newPt.m_index0 = m_index0;
94
newPt.m_index1 = m_index1;
96
///todo, check this for any side effects
99
//const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
100
m_manifoldPtr->replaceContactPoint(newPt,insertIndex);
103
m_manifoldPtr->AddManifoldPoint(newPt);
106
//User can override friction and/or restitution
107
if (gContactAddedCallback &&
108
//and if either of the two bodies requires custom material
109
((m_body0->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
110
(m_body1->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
112
//experimental feature info, for per-triangle material etc.
113
btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
114
btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
115
(*gContactAddedCallback)(newPt,obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
17
#include "btManifoldResult.h"
18
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
19
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
22
///This is to allow MaterialCombiner/Custom Friction/Restitution values
23
ContactAddedCallback gContactAddedCallback=0;
25
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
26
inline btScalar calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
28
btScalar friction = body0->getFriction() * body1->getFriction();
30
const btScalar MAX_FRICTION = btScalar(10.);
31
if (friction < -MAX_FRICTION)
32
friction = -MAX_FRICTION;
33
if (friction > MAX_FRICTION)
34
friction = MAX_FRICTION;
39
inline btScalar calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
41
return body0->getRestitution() * body1->getRestitution();
46
btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* body1)
51
m_rootTransA = body0->getWorldTransform();
52
m_rootTransB = body1->getWorldTransform();
56
void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
58
assert(m_manifoldPtr);
59
//order in manifold needs to match
61
if (depth > m_manifoldPtr->getContactBreakingThreshold())
64
bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
66
btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
73
localA = m_rootTransB.invXform(pointA );
74
localB = m_rootTransA.invXform(pointInWorld);
77
localA = m_rootTransA.invXform(pointA );
78
localB = m_rootTransB.invXform(pointInWorld);
81
btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
82
newPt.m_positionWorldOnA = pointA;
83
newPt.m_positionWorldOnB = pointInWorld;
85
int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
87
newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
88
newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
90
//BP mod, store contact triangles.
91
newPt.m_partId0 = m_partId0;
92
newPt.m_partId1 = m_partId1;
93
newPt.m_index0 = m_index0;
94
newPt.m_index1 = m_index1;
96
///todo, check this for any side effects
99
//const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
100
m_manifoldPtr->replaceContactPoint(newPt,insertIndex);
103
m_manifoldPtr->AddManifoldPoint(newPt);
106
//User can override friction and/or restitution
107
if (gContactAddedCallback &&
108
//and if either of the two bodies requires custom material
109
((m_body0->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
110
(m_body1->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
112
//experimental feature info, for per-triangle material etc.
113
btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
114
btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
115
(*gContactAddedCallback)(newPt,obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);