Changeset 8393 for code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
- Timestamp:
- May 3, 2011, 5:07:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
r8351 r8393 23 23 #include "btGjkPairDetector.h" 24 24 #include "btPointCollector.h" 25 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 25 26 26 27 … … 29 30 :m_simplexSolver(simplexSolver), 30 31 m_penetrationDepthSolver(penetrationDepthSolver), 31 m_convexA(convexA),m_convexB(convexB) 32 { 33 } 32 m_convexA(convexA),m_convexB1(convexB),m_planeShape(0) 33 { 34 } 35 36 37 btContinuousConvexCollision::btContinuousConvexCollision( const btConvexShape* convexA,const btStaticPlaneShape* plane) 38 :m_simplexSolver(0), 39 m_penetrationDepthSolver(0), 40 m_convexA(convexA),m_convexB1(0),m_planeShape(plane) 41 { 42 } 43 34 44 35 45 /// This maximum should not be necessary. It allows for untested/degenerate cases in production code. 36 46 /// You don't want your game ever to lock-up. 37 47 #define MAX_ITERATIONS 64 48 49 void btContinuousConvexCollision::computeClosestPoints( const btTransform& transA, const btTransform& transB,btPointCollector& pointCollector) 50 { 51 if (m_convexB1) 52 { 53 m_simplexSolver->reset(); 54 btGjkPairDetector gjk(m_convexA,m_convexB1,m_convexA->getShapeType(),m_convexB1->getShapeType(),m_convexA->getMargin(),m_convexB1->getMargin(),m_simplexSolver,m_penetrationDepthSolver); 55 btGjkPairDetector::ClosestPointInput input; 56 input.m_transformA = transA; 57 input.m_transformB = transB; 58 gjk.getClosestPoints(input,pointCollector,0); 59 } else 60 { 61 //convex versus plane 62 const btConvexShape* convexShape = m_convexA; 63 const btStaticPlaneShape* planeShape = m_planeShape; 64 65 bool hasCollision = false; 66 const btVector3& planeNormal = planeShape->getPlaneNormal(); 67 const btScalar& planeConstant = planeShape->getPlaneConstant(); 68 69 btTransform convexWorldTransform = transA; 70 btTransform convexInPlaneTrans; 71 convexInPlaneTrans= transB.inverse() * convexWorldTransform; 72 btTransform planeInConvex; 73 planeInConvex= convexWorldTransform.inverse() * transB; 74 75 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal); 76 77 btVector3 vtxInPlane = convexInPlaneTrans(vtx); 78 btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant); 79 80 btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal; 81 btVector3 vtxInPlaneWorld = transB * vtxInPlaneProjected; 82 btVector3 normalOnSurfaceB = transB.getBasis() * planeNormal; 83 84 pointCollector.addContactPoint( 85 normalOnSurfaceB, 86 vtxInPlaneWorld, 87 distance); 88 } 89 } 38 90 39 91 bool btContinuousConvexCollision::calcTimeOfImpact( … … 45 97 { 46 98 47 m_simplexSolver->reset();48 99 49 100 /// compute linear and angular velocity for this interval, to interpolate … … 54 105 55 106 btScalar boundingRadiusA = m_convexA->getAngularMotionDisc(); 56 btScalar boundingRadiusB = m_convexB ->getAngularMotionDisc();107 btScalar boundingRadiusB = m_convexB1?m_convexB1->getAngularMotionDisc():0.f; 57 108 58 109 btScalar maxAngularProjectedVelocity = angVelA.length() * boundingRadiusA + angVelB.length() * boundingRadiusB; … … 65 116 66 117 67 btScalar radius = btScalar(0.001);68 118 69 119 btScalar lambda = btScalar(0.); … … 84 134 85 135 86 btTransform identityTrans; 87 identityTrans.setIdentity(); 88 89 btSphereShape raySphere(btScalar(0.0)); 90 raySphere.setMargin(btScalar(0.)); 91 92 136 btScalar radius = 0.001f; 93 137 // result.drawCoordSystem(sphereTr); 94 138 … … 96 140 97 141 { 98 99 btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver);100 btGjkPairDetector::ClosestPointInput input;101 142 102 //we don't use margins during CCD 103 // gjk.setIgnoreMargin(true); 104 105 input.m_transformA = fromA; 106 input.m_transformB = fromB; 107 gjk.getClosestPoints(input,pointCollector1,0); 143 computeClosestPoints(fromA,fromB,pointCollector1); 108 144 109 145 hasResult = pointCollector1.m_hasResult; … … 114 150 { 115 151 btScalar dist; 116 dist = pointCollector1.m_distance ;152 dist = pointCollector1.m_distance + result.m_allowedPenetration; 117 153 n = pointCollector1.m_normalOnBInWorld; 118 119 154 btScalar projectedLinearVelocity = relLinVel.dot(n); 120 155 if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON) 156 return false; 157 121 158 //not close enough 122 159 while (dist > radius) … … 126 163 result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1)); 127 164 } 128 numIter++;129 if (numIter > maxIter)130 {131 return false; //todo: report a failure132 }133 165 btScalar dLambda = btScalar(0.); 134 166 135 167 projectedLinearVelocity = relLinVel.dot(n); 136 168 137 //calculate safe moving fraction from distance / (linear+rotational velocity)138 139 //btScalar clippedDist = GEN_min(angularConservativeRadius,dist);140 //btScalar clippedDist = dist;141 169 142 170 //don't report time of impact for motion away from the contact normal (or causes minor penetration) … … 183 211 184 212 btPointCollector pointCollector; 185 btGjkPairDetector gjk(m_convexA,m_convexB,m_simplexSolver,m_penetrationDepthSolver); 186 btGjkPairDetector::ClosestPointInput input; 187 input.m_transformA = interpolatedTransA; 188 input.m_transformB = interpolatedTransB; 189 gjk.getClosestPoints(input,pointCollector,0); 213 computeClosestPoints(interpolatedTransA,interpolatedTransB,pointCollector); 214 190 215 if (pointCollector.m_hasResult) 191 216 { 192 if (pointCollector.m_distance < btScalar(0.)) 193 { 194 //degenerate ?! 195 result.m_fraction = lastLambda; 196 n = pointCollector.m_normalOnBInWorld; 197 result.m_normal=n;//.setValue(1,1,1);// = n; 198 result.m_hitPoint = pointCollector.m_pointInWorld; 199 return true; 200 } 217 dist = pointCollector.m_distance+result.m_allowedPenetration; 201 218 c = pointCollector.m_pointInWorld; 202 219 n = pointCollector.m_normalOnBInWorld; 203 dist = pointCollector.m_distance;204 220 } else 205 221 { 206 //?? 207 return false; 208 } 209 210 222 result.reportFailure(-1, numIter); 223 return false; 224 } 225 226 numIter++; 227 if (numIter > maxIter) 228 { 229 result.reportFailure(-2, numIter); 230 return false; 231 } 211 232 } 212 233 213 if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON)214 return false;215 216 234 result.m_fraction = lambda; 217 235 result.m_normal = n; … … 222 240 return false; 223 241 224 /* 225 //todo: 226 //if movement away from normal, discard result 227 btVector3 move = transBLocalTo.getOrigin() - transBLocalFrom.getOrigin(); 228 if (result.m_fraction < btScalar(1.)) 229 { 230 if (move.dot(result.m_normal) <= btScalar(0.)) 231 { 232 } 233 } 234 */ 235 236 } 242 } 243
Note: See TracChangeset
for help on using the changeset viewer.