Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 31, 2009, 8:05:51 PM (15 years ago)
Author:
rgrieder
Message:

Update from Bullet 2.73 to 2.74.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp

    r2662 r2882  
    55This software is provided 'as-is', without any express or implied warranty.
    66In no event will the authors be held liable for any damages arising from the use of this software.
    7 Permission is granted to anyone to use this software for any purpose, 
    8 including commercial applications, and to alter it and redistribute it freely, 
     7Permission is granted to anyone to use this software for any purpose,
     8including commercial applications, and to alter it and redistribute it freely,
    99subject to the following restrictions:
    1010
     
    2323//#include <stdio.h>
    2424
    25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped)
     25btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
    2626: btCollisionAlgorithm(ci),
    2727m_ownManifold(false),
    2828m_manifoldPtr(mf),
    29 m_isSwapped(isSwapped)
     29m_isSwapped(isSwapped),
     30m_numPerturbationIterations(numPerturbationIterations),
     31m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
    3032{
    3133        btCollisionObject* convexObj = m_isSwapped? col1 : col0;
    3234        btCollisionObject* planeObj = m_isSwapped? col0 : col1;
    33        
     35
    3436        if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj))
    3537        {
     
    4951}
    5052
    51 
    52 
    53 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
     53void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
    5454{
    55         (void)dispatchInfo;
    56         (void)resultOut;
    57         if (!m_manifoldPtr)
    58                 return;
    59 
    60         btCollisionObject* convexObj = m_isSwapped? body1 : body0;
     55    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
    6156        btCollisionObject* planeObj = m_isSwapped? body0: body1;
    6257
     
    6459        btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
    6560
    66         bool hasCollision = false;
     61    bool hasCollision = false;
    6762        const btVector3& planeNormal = planeShape->getPlaneNormal();
    6863        const btScalar& planeConstant = planeShape->getPlaneConstant();
     64       
     65        btTransform convexWorldTransform = convexObj->getWorldTransform();
     66        btTransform convexInPlaneTrans;
     67        convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform;
     68        //now perturbe the convex-world transform
     69        convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot);
    6970        btTransform planeInConvex;
    70         planeInConvex= convexObj->getWorldTransform().inverse() * planeObj->getWorldTransform();
    71         btTransform convexInPlaneTrans;
    72         convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform();
     71        planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform();
     72       
     73        btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
    7374
    74         btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
    7575        btVector3 vtxInPlane = convexInPlaneTrans(vtx);
    7676        btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
     
    8888                resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
    8989        }
     90}
     91
     92
     93void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
     94{
     95        (void)dispatchInfo;
     96        if (!m_manifoldPtr)
     97                return;
     98
     99    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
     100        btCollisionObject* planeObj = m_isSwapped? body0: body1;
     101
     102        btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
     103        btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
     104
     105    bool hasCollision = false;
     106        const btVector3& planeNormal = planeShape->getPlaneNormal();
     107        const btScalar& planeConstant = planeShape->getPlaneConstant();
     108
     109        //first perform a collision query with the non-perturbated collision objects
     110        {
     111                btQuaternion rotq(0,0,0,1);
     112                collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut);
     113        }
     114
     115        if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold)
     116        {
     117                btVector3 v0,v1;
     118                btPlaneSpace1(planeNormal,v0,v1);
     119                //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
     120
     121                const btScalar angleLimit = 0.125f * SIMD_PI;
     122                btScalar perturbeAngle;
     123                btScalar radius = convexShape->getAngularMotionDisc();
     124                perturbeAngle = gContactBreakingThreshold / radius;
     125                if ( perturbeAngle > angleLimit )
     126                                perturbeAngle = angleLimit;
     127
     128                btQuaternion perturbeRot(v0,perturbeAngle);
     129                for (int i=0;i<m_numPerturbationIterations;i++)
     130                {
     131                        btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
     132                        btQuaternion rotq(planeNormal,iterationAngle);
     133                        collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut);
     134                }
     135        }
     136
    90137        if (m_ownManifold)
    91138        {
Note: See TracChangeset for help on using the changeset viewer.