Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2011, 5:07:42 AM (13 years ago)
Author:
rgrieder
Message:

Updated Bullet from v2.77 to v2.78.
(I'm not going to make a branch for that since the update from 2.74 to 2.77 hasn't been tested that much either).

You will HAVE to do a complete RECOMPILE! I tested with MSVC and MinGW and they both threw linker errors at me.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp

    r8351 r8393  
    2323#include "btGjkPairDetector.h"
    2424#include "btPointCollector.h"
     25#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
    2526
    2627
     
    2930:m_simplexSolver(simplexSolver),
    3031m_penetrationDepthSolver(penetrationDepthSolver),
    31 m_convexA(convexA),m_convexB(convexB)
    32 {
    33 }
     32m_convexA(convexA),m_convexB1(convexB),m_planeShape(0)
     33{
     34}
     35
     36
     37btContinuousConvexCollision::btContinuousConvexCollision( const btConvexShape*  convexA,const btStaticPlaneShape*       plane)
     38:m_simplexSolver(0),
     39m_penetrationDepthSolver(0),
     40m_convexA(convexA),m_convexB1(0),m_planeShape(plane)
     41{
     42}
     43
    3444
    3545/// This maximum should not be necessary. It allows for untested/degenerate cases in production code.
    3646/// You don't want your game ever to lock-up.
    3747#define MAX_ITERATIONS 64
     48
     49void 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}
    3890
    3991bool    btContinuousConvexCollision::calcTimeOfImpact(
     
    4597{
    4698
    47         m_simplexSolver->reset();
    4899
    49100        /// compute linear and angular velocity for this interval, to interpolate
     
    54105
    55106        btScalar boundingRadiusA = m_convexA->getAngularMotionDisc();
    56         btScalar boundingRadiusB = m_convexB->getAngularMotionDisc();
     107        btScalar boundingRadiusB = m_convexB1?m_convexB1->getAngularMotionDisc():0.f;
    57108
    58109        btScalar maxAngularProjectedVelocity = angVelA.length() * boundingRadiusA + angVelB.length() * boundingRadiusB;
     
    65116
    66117
    67         btScalar radius = btScalar(0.001);
    68118
    69119        btScalar lambda = btScalar(0.);
     
    84134
    85135
    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;
    93137//      result.drawCoordSystem(sphereTr);
    94138
     
    96140
    97141        {
    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;
    101142       
    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);
    108144
    109145                hasResult = pointCollector1.m_hasResult;
     
    114150        {
    115151                btScalar dist;
    116                 dist = pointCollector1.m_distance;
     152                dist = pointCollector1.m_distance + result.m_allowedPenetration;
    117153                n = pointCollector1.m_normalOnBInWorld;
    118 
    119154                btScalar projectedLinearVelocity = relLinVel.dot(n);
    120                
     155                if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON)
     156                        return false;
     157
    121158                //not close enough
    122159                while (dist > radius)
     
    126163                                result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1));
    127164                        }
    128                         numIter++;
    129                         if (numIter > maxIter)
    130                         {
    131                                 return false; //todo: report a failure
    132                         }
    133165                        btScalar dLambda = btScalar(0.);
    134166
    135167                        projectedLinearVelocity = relLinVel.dot(n);
    136168
    137                         //calculate safe moving fraction from distance / (linear+rotational velocity)
    138                        
    139                         //btScalar clippedDist  = GEN_min(angularConservativeRadius,dist);
    140                         //btScalar clippedDist  = dist;
    141169                       
    142170                        //don't report time of impact for motion away from the contact normal (or causes minor penetration)
     
    183211
    184212                        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
    190215                        if (pointCollector.m_hasResult)
    191216                        {
    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;
    201218                                c = pointCollector.m_pointInWorld;             
    202219                                n = pointCollector.m_normalOnBInWorld;
    203                                 dist = pointCollector.m_distance;
    204220                        } else
    205221                        {
    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                        }
    211232                }
    212233       
    213                 if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON)
    214                         return false;
    215                        
    216234                result.m_fraction = lambda;
    217235                result.m_normal = n;
     
    222240        return false;
    223241
    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.