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

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.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:
18
18
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
19
19
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
20
20
 
 
21
 
 
22
 
21
23
#if defined(DEBUG) || defined (_DEBUG)
 
24
//#define TEST_NON_VIRTUAL 1
22
25
#include <stdio.h> //for debug printf
23
26
#ifdef __SPU__
24
27
#include <spu_printf.h>
25
28
#define printf spu_printf
 
29
//#define DEBUG_SPU_COLLISION_DETECTION 1
26
30
#endif //__SPU__
27
31
#endif
28
32
 
49
53
 
50
54
void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults)
51
55
{
 
56
        m_cachedSeparatingDistance = 0.f;
 
57
 
52
58
        btScalar distance=btScalar(0.);
53
59
        btVector3       normalInB(btScalar(0.),btScalar(0.),btScalar(0.));
54
60
        btVector3 pointOnA,pointOnB;
58
64
        localTransA.getOrigin() -= positionOffset;
59
65
        localTransB.getOrigin() -= positionOffset;
60
66
 
 
67
#ifdef __SPU__
 
68
        btScalar marginA = m_minkowskiA->getMarginNonVirtual();
 
69
        btScalar marginB = m_minkowskiB->getMarginNonVirtual();
 
70
#else
61
71
        btScalar marginA = m_minkowskiA->getMargin();
62
72
        btScalar marginB = m_minkowskiB->getMargin();
 
73
#ifdef TEST_NON_VIRTUAL
 
74
        btScalar marginAv = m_minkowskiA->getMarginNonVirtual();
 
75
        btScalar marginBv = m_minkowskiB->getMarginNonVirtual();
 
76
        btAssert(marginA == marginAv);
 
77
        btAssert(marginB == marginBv);
 
78
#endif //TEST_NON_VIRTUAL
 
79
#endif
 
80
        
 
81
 
63
82
 
64
83
        gNumGjkChecks++;
65
84
 
 
85
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
86
        spu_printf("inside gjk\n");
 
87
#endif
66
88
        //for CCD we don't use margins
67
89
        if (m_ignoreMargin)
68
90
        {
69
91
                marginA = btScalar(0.);
70
92
                marginB = btScalar(0.);
 
93
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
94
                spu_printf("ignoring margin\n");
 
95
#endif
71
96
        }
72
97
 
73
98
        m_curIter = 0;
98
123
                        btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis();
99
124
                        btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
100
125
 
 
126
#ifdef __SPU__
 
127
                        btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
 
128
                        btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
 
129
#else
101
130
                        btVector3 pInA = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
102
131
                        btVector3 qInB = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
103
 
                        btPoint3  pWorld = localTransA(pInA);   
104
 
                        btPoint3  qWorld = localTransB(qInB);
105
 
                        
 
132
#ifdef TEST_NON_VIRTUAL
 
133
                        btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
 
134
                        btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
 
135
                        btAssert((pInAv-pInA).length() < 0.0001);
 
136
                        btAssert((qInBv-qInB).length() < 0.0001);
 
137
#endif //
 
138
#endif //__SPU__
 
139
 
 
140
                        btVector3  pWorld = localTransA(pInA);  
 
141
                        btVector3  qWorld = localTransB(qInB);
 
142
 
 
143
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
144
                spu_printf("got local supporting vertices\n");
 
145
#endif
 
146
 
106
147
                        btVector3 w     = pWorld - qWorld;
107
148
                        delta = m_cachedSeparatingAxis.dot(w);
108
149
 
109
150
                        // potential exit, they don't overlap
110
151
                        if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared)) 
111
152
                        {
112
 
                                checkPenetration = false;
 
153
                                checkSimplex=true;
 
154
                                //checkPenetration = false;
113
155
                                break;
114
156
                        }
115
157
 
133
175
                                checkSimplex = true;
134
176
                                break;
135
177
                        }
 
178
 
 
179
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
180
                spu_printf("addVertex 1\n");
 
181
#endif
136
182
                        //add current vertex to simplex
137
183
                        m_simplexSolver->addVertex(w, pWorld, qWorld);
138
 
 
 
184
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
185
                spu_printf("addVertex 2\n");
 
186
#endif
139
187
                        //calculate the closest point to the origin (update vector v)
140
188
                        if (!m_simplexSolver->closest(m_cachedSeparatingAxis))
141
189
                        {
167
215
                          //degeneracy, this is typically due to invalid/uninitialized worldtransforms for a btCollisionObject   
168
216
              if (m_curIter++ > gGjkMaxIter)   
169
217
              {   
170
 
                      #if defined(DEBUG) || defined (_DEBUG)   
 
218
                      #if defined(DEBUG) || defined (_DEBUG) || defined (DEBUG_SPU_COLLISION_DETECTION)
171
219
 
172
220
                              printf("btGjkPairDetector maxIter exceeded:%i\n",m_curIter);   
173
221
                              printf("sepAxis=(%f,%f,%f), squaredDistance = %f, shapeTypeA=%i,shapeTypeB=%i\n",   
290
338
#endif //__CELLOS_LV2__
291
339
 
292
340
 
 
341
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
342
                spu_printf("output 1\n");
 
343
#endif
 
344
                m_cachedSeparatingAxis = normalInB;
 
345
                m_cachedSeparatingDistance = distance;
 
346
 
293
347
                output.addContactPoint(
294
348
                        normalInB,
295
349
                        pointOnB+positionOffset,
296
350
                        distance);
 
351
 
 
352
#ifdef DEBUG_SPU_COLLISION_DETECTION
 
353
                spu_printf("output 2\n");
 
354
#endif
297
355
                //printf("gjk add:%f",distance);
298
356
        }
299
357