~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include "btContinuousConvexCollision.h"
18
18
#include "BulletCollision/CollisionShapes/btConvexShape.h"
19
 
#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
20
19
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
21
20
#include "LinearMath/btTransformUtil.h"
22
21
#include "BulletCollision/CollisionShapes/btSphereShape.h"
26
25
 
27
26
 
28
27
 
29
 
btContinuousConvexCollision::btContinuousConvexCollision ( btConvexShape*       convexA,btConvexShape*  convexB,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* penetrationDepthSolver)
 
28
btContinuousConvexCollision::btContinuousConvexCollision ( const btConvexShape* convexA,const btConvexShape*    convexB,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* penetrationDepthSolver)
30
29
:m_simplexSolver(simplexSolver),
31
30
m_penetrationDepthSolver(penetrationDepthSolver),
32
31
m_convexA(convexA),m_convexB(convexB)
35
34
 
36
35
/// This maximum should not be necessary. It allows for untested/degenerate cases in production code.
37
36
/// You don't want your game ever to lock-up.
38
 
#define MAX_ITERATIONS 1000
 
37
#define MAX_ITERATIONS 64
39
38
 
40
39
bool    btContinuousConvexCollision::calcTimeOfImpact(
41
40
                                const btTransform& fromA,
52
51
        btTransformUtil::calculateVelocity(fromA,toA,btScalar(1.),linVelA,angVelA);
53
52
        btTransformUtil::calculateVelocity(fromB,toB,btScalar(1.),linVelB,angVelB);
54
53
 
 
54
 
55
55
        btScalar boundingRadiusA = m_convexA->getAngularMotionDisc();
56
56
        btScalar boundingRadiusB = m_convexB->getAngularMotionDisc();
57
57
 
58
58
        btScalar maxAngularProjectedVelocity = angVelA.length() * boundingRadiusA + angVelB.length() * boundingRadiusB;
 
59
        btVector3 relLinVel = (linVelB-linVelA);
 
60
 
 
61
        btScalar relLinVelocLength = (linVelB-linVelA).length();
 
62
        
 
63
        if ((relLinVelocLength+maxAngularProjectedVelocity) == 0.f)
 
64
                return false;
 
65
 
59
66
 
60
67
        btScalar radius = btScalar(0.001);
61
68
 
93
100
                btGjkPairDetector::ClosestPointInput input;
94
101
        
95
102
                //we don't use margins during CCD
96
 
                gjk.setIgnoreMargin(true);
 
103
        //      gjk.setIgnoreMargin(true);
97
104
 
98
105
                input.m_transformA = fromA;
99
106
                input.m_transformB = fromB;
108
115
                btScalar dist;
109
116
                dist = pointCollector1.m_distance;
110
117
                n = pointCollector1.m_normalOnBInWorld;
 
118
 
 
119
                btScalar projectedLinearVelocity = relLinVel.dot(n);
111
120
                
112
121
                //not close enough
113
122
                while (dist > radius)
114
123
                {
115
124
                        numIter++;
116
125
                        if (numIter > maxIter)
 
126
                        {
117
127
                                return false; //todo: report a failure
118
 
 
 
128
                        }
119
129
                        btScalar dLambda = btScalar(0.);
120
130
 
 
131
                        projectedLinearVelocity = relLinVel.dot(n);
 
132
 
121
133
                        //calculate safe moving fraction from distance / (linear+rotational velocity)
122
134
                        
123
135
                        //btScalar clippedDist  = GEN_min(angularConservativeRadius,dist);
124
136
                        //btScalar clippedDist  = dist;
125
137
                        
126
 
                        btScalar projectedLinearVelocity = (linVelB-linVelA).dot(n);
127
138
                        
128
139
                        dLambda = dist / (projectedLinearVelocity+ maxAngularProjectedVelocity);
129
140
 
 
141
                        
 
142
                        
130
143
                        lambda = lambda + dLambda;
131
144
 
132
145
                        if (lambda > btScalar(1.))
135
148
                        if (lambda < btScalar(0.))
136
149
                                return false;
137
150
 
 
151
 
138
152
                        //todo: next check with relative epsilon
139
153
                        if (lambda <= lastLambda)
 
154
                        {
 
155
                                return false;
 
156
                                //n.setValue(0,0,0);
140
157
                                break;
 
158
                        }
141
159
                        lastLambda = lambda;
142
160
 
143
161
                        
163
181
                                {
164
182
                                        //degenerate ?!
165
183
                                        result.m_fraction = lastLambda;
166
 
                                        result.m_normal = n;
 
184
                                        n = pointCollector.m_normalOnBInWorld;
 
185
                                        result.m_normal=n;//.setValue(1,1,1);// = n;
 
186
                                        result.m_hitPoint = pointCollector.m_pointInWorld;
167
187
                                        return true;
168
188
                                }
169
189
                                c = pointCollector.m_pointInWorld;              
170
 
                                
 
190
                                n = pointCollector.m_normalOnBInWorld;
171
191
                                dist = pointCollector.m_distance;
172
192
                        } else
173
193
                        {
177
197
 
178
198
                }
179
199
 
 
200
                //don't report time of impact for motion away from the contact normal (or causes minor penetration)
 
201
                if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON)
 
202
                        return false;
 
203
 
180
204
                result.m_fraction = lambda;
181
205
                result.m_normal = n;
 
206
                result.m_hitPoint = c;
182
207
                return true;
183
208
        }
184
209