~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
20
20
#include "LinearMath/btIDebugDraw.h"
21
21
#include "LinearMath/btAabbUtil2.h"
 
22
#include "btManifoldResult.h"
22
23
 
23
24
btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
24
 
:btCollisionAlgorithm(ci),
 
25
:btActivatingCollisionAlgorithm(ci,body0,body1),
25
26
m_isSwapped(isSwapped),
26
27
m_sharedManifold(ci.m_manifold)
27
28
{
28
29
        m_ownsManifold = false;
29
30
 
30
31
        btCollisionObject* colObj = m_isSwapped? body1 : body0;
 
32
        btAssert (colObj->getCollisionShape()->isCompound());
 
33
        
 
34
        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
 
35
        m_compoundShapeRevision = compoundShape->getUpdateRevision();
 
36
        
 
37
        preallocateChildAlgorithms(body0,body1);
 
38
}
 
39
 
 
40
void    btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1)
 
41
{
 
42
        btCollisionObject* colObj = m_isSwapped? body1 : body0;
31
43
        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
32
 
        assert (colObj->getCollisionShape()->isCompound());
 
44
        btAssert (colObj->getCollisionShape()->isCompound());
33
45
        
34
46
        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
 
47
 
35
48
        int numChildren = compoundShape->getNumChildShapes();
36
49
        int i;
37
50
        
46
59
                        btCollisionShape* tmpShape = colObj->getCollisionShape();
47
60
                        btCollisionShape* childShape = compoundShape->getChildShape(i);
48
61
                        colObj->internalSetTemporaryCollisionShape( childShape );
49
 
                        m_childCollisionAlgorithms[i] = ci.m_dispatcher1->findAlgorithm(colObj,otherObj,m_sharedManifold);
 
62
                        m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(colObj,otherObj,m_sharedManifold);
50
63
                        colObj->internalSetTemporaryCollisionShape( tmpShape );
51
64
                }
52
65
        }
53
66
}
54
67
 
55
 
 
56
 
btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
 
68
void    btCompoundCollisionAlgorithm::removeChildAlgorithms()
57
69
{
58
70
        int numChildren = m_childCollisionAlgorithms.size();
59
71
        int i;
67
79
        }
68
80
}
69
81
 
 
82
btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
 
83
{
 
84
        removeChildAlgorithms();
 
85
}
 
86
 
70
87
 
71
88
 
72
89
 
167
184
        btCollisionObject* colObj = m_isSwapped? body1 : body0;
168
185
        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
169
186
 
170
 
        assert (colObj->getCollisionShape()->isCompound());
 
187
        
 
188
 
 
189
        btAssert (colObj->getCollisionShape()->isCompound());
171
190
        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
172
191
 
 
192
        ///btCompoundShape might have changed:
 
193
        ////make sure the internal child collision algorithm caches are still valid
 
194
        if (compoundShape->getUpdateRevision() != m_compoundShapeRevision)
 
195
        {
 
196
                ///clear and update all
 
197
                removeChildAlgorithms();
 
198
                
 
199
                preallocateChildAlgorithms(body0,body1);
 
200
        }
 
201
 
 
202
 
173
203
        btDbvt* tree = compoundShape->getDynamicAabbTree();
174
204
        //use a dynamic aabb tree to cull potential child-overlaps
175
205
        btCompoundLeafCallback  callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
176
206
 
 
207
        ///we need to refresh all contact manifolds
 
208
        ///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
 
209
        ///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 
210
        {
 
211
                int i;
 
212
                btManifoldArray manifoldArray;
 
213
                for (i=0;i<m_childCollisionAlgorithms.size();i++)
 
214
                {
 
215
                        if (m_childCollisionAlgorithms[i])
 
216
                        {
 
217
                                m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
 
218
                                for (int m=0;m<manifoldArray.size();m++)
 
219
                                {
 
220
                                        if (manifoldArray[m]->getNumContacts())
 
221
                                        {
 
222
                                                resultOut->setPersistentManifold(manifoldArray[m]);
 
223
                                                resultOut->refreshContactPoints();
 
224
                                                resultOut->setPersistentManifold(0);//??necessary?
 
225
                                        }
 
226
                                }
 
227
                                manifoldArray.clear();
 
228
                        }
 
229
                }
 
230
        }
177
231
 
178
232
        if (tree)
179
233
        {
242
296
        btCollisionObject* colObj = m_isSwapped? body1 : body0;
243
297
        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
244
298
 
245
 
        assert (colObj->getCollisionShape()->isCompound());
 
299
        btAssert (colObj->getCollisionShape()->isCompound());
246
300
        
247
301
        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
248
302
 
285
339
}
286
340
 
287
341
 
 
342