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/CollisionDispatch/SphereTriangleDetector.cpp

    r8351 r8393  
    5858}
    5959
    60 #define MAX_OVERLAP btScalar(0.)
    61 
    6260
    6361
     
    9492}
    9593
    96 ///combined discrete/continuous sphere-triangle
    9794bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold)
    9895{
    9996
    10097        const btVector3* vertices = &m_triangle->getVertexPtr(0);
    101         const btVector3& c = sphereCenter;
    102         btScalar r = m_sphere->getRadius();
    103 
    104         btVector3 delta (0,0,0);
     98       
     99        btScalar radius = m_sphere->getRadius();
     100        btScalar radiusWithThreshold = radius + contactBreakingThreshold;
    105101
    106102        btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
    107103        normal.normalize();
    108         btVector3 p1ToCentre = c - vertices[0];
     104        btVector3 p1ToCentre = sphereCenter - vertices[0];
    109105        btScalar distanceFromPlane = p1ToCentre.dot(normal);
    110106
     
    112108        {
    113109                //triangle facing the other way
    114        
    115110                distanceFromPlane *= btScalar(-1.);
    116111                normal *= btScalar(-1.);
    117112        }
    118113
    119         btScalar contactMargin = contactBreakingThreshold;
    120         bool isInsideContactPlane = distanceFromPlane < r + contactMargin;
    121         bool isInsideShellPlane = distanceFromPlane < r;
    122        
    123         btScalar deltaDotNormal = delta.dot(normal);
    124         if (!isInsideShellPlane && deltaDotNormal >= btScalar(0.0))
    125                 return false;
    126 
     114        bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
     115       
    127116        // Check for contact / intersection
    128117        bool hasContact = false;
    129118        btVector3 contactPoint;
    130119        if (isInsideContactPlane) {
    131                 if (facecontains(c,vertices,normal)) {
     120                if (facecontains(sphereCenter,vertices,normal)) {
    132121                        // Inside the contact wedge - touches a point on the shell plane
    133122                        hasContact = true;
    134                         contactPoint = c - normal*distanceFromPlane;
     123                        contactPoint = sphereCenter - normal*distanceFromPlane;
    135124                } else {
    136125                        // Could be inside one of the contact capsules
    137                         btScalar contactCapsuleRadiusSqr = (r + contactMargin) * (r + contactMargin);
     126                        btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
    138127                        btVector3 nearestOnEdge;
    139128                        for (int i = 0; i < m_triangle->getNumEdges(); i++) {
     
    144133                                m_triangle->getEdge(i,pa,pb);
    145134
    146                                 btScalar distanceSqr = SegmentSqrDistance(pa,pb,c, nearestOnEdge);
     135                                btScalar distanceSqr = SegmentSqrDistance(pa,pb,sphereCenter, nearestOnEdge);
    147136                                if (distanceSqr < contactCapsuleRadiusSqr) {
    148137                                        // Yep, we're inside a capsule
     
    156145
    157146        if (hasContact) {
    158                 btVector3 contactToCentre = c - contactPoint;
     147                btVector3 contactToCentre = sphereCenter - contactPoint;
    159148                btScalar distanceSqr = contactToCentre.length2();
    160                 if (distanceSqr < (r - MAX_OVERLAP)*(r - MAX_OVERLAP)) {
    161                         btScalar distance = btSqrt(distanceSqr);
    162                         resultNormal = contactToCentre;
    163                         resultNormal.normalize();
    164                         point = contactPoint;
    165                         depth = -(r-distance);
     149
     150                if (distanceSqr < radiusWithThreshold*radiusWithThreshold)
     151                {
     152                        if (distanceSqr>SIMD_EPSILON)
     153                        {
     154                                btScalar distance = btSqrt(distanceSqr);
     155                                resultNormal = contactToCentre;
     156                                resultNormal.normalize();
     157                                point = contactPoint;
     158                                depth = -(radius-distance);
     159                        } else
     160                        {
     161                                btScalar distance = 0.f;
     162                                resultNormal = normal;
     163                                point = contactPoint;
     164                                depth = -radius;
     165                        }
    166166                        return true;
    167167                }
    168 
    169                 if (delta.dot(contactToCentre) >= btScalar(0.0))
    170                         return false;
    171                
    172                 // Moving towards the contact point -> collision
    173                 point = contactPoint;
    174                 timeOfImpact = btScalar(0.0);
    175                 return true;
    176168        }
    177169       
Note: See TracChangeset for help on using the changeset viewer.