Back to index

supertuxkart  0.5+dfsg1
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
btConvexConcaveCollisionAlgorithm Class Reference

btConvexConcaveCollisionAlgorithm supports collision between convex shapes and (concave) trianges meshes. More...

#include <btConvexConcaveCollisionAlgorithm.h>

Inheritance diagram for btConvexConcaveCollisionAlgorithm:
Inheritance graph
[legend]
Collaboration diagram for btConvexConcaveCollisionAlgorithm:
Collaboration graph
[legend]

List of all members.

Classes

struct  CreateFunc
struct  SwappedCreateFunc

Public Member Functions

 btConvexConcaveCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo &ci, btCollisionObject *body0, btCollisionObject *body1, bool isSwapped)
virtual ~btConvexConcaveCollisionAlgorithm ()
virtual void processCollision (btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btScalar calculateTimeOfImpact (btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
void clearCache ()

Protected Member Functions

int getDispatcherId ()

Protected Attributes

btDispatcherm_dispatcher

Private Attributes

bool m_isSwapped
btConvexTriangleCallback m_btConvexTriangleCallback

Detailed Description

btConvexConcaveCollisionAlgorithm supports collision between convex shapes and (concave) trianges meshes.

Definition at line 73 of file btConvexConcaveCollisionAlgorithm.h.


Constructor & Destructor Documentation

btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm ( const btCollisionAlgorithmConstructionInfo ci,
btCollisionObject *  body0,
btCollisionObject *  body1,
bool  isSwapped 
)

Definition at line 29 of file btConvexConcaveCollisionAlgorithm.cpp.

: btCollisionAlgorithm(ci),
m_isSwapped(isSwapped),
m_btConvexTriangleCallback(ci.m_dispatcher1,body0,body1,isSwapped)
{
}

Here is the caller graph for this function:

Definition at line 36 of file btConvexConcaveCollisionAlgorithm.cpp.

{
}

Member Function Documentation

btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact ( btCollisionObject *  body0,
btCollisionObject *  body1,
const btDispatcherInfo dispatchInfo,
btManifoldResult resultOut 
) [virtual]

Implements btCollisionAlgorithm.

Definition at line 203 of file btConvexConcaveCollisionAlgorithm.cpp.

{
       (void)resultOut;
       (void)dispatchInfo;
       btCollisionObject* convexbody = m_isSwapped ? body1 : body0;
       btCollisionObject* triBody = m_isSwapped ? body0 : body1;


       //quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)

       //only perform CCD above a certain threshold, this prevents blocking on the long run
       //because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame...
       btScalar squareMot0 = (convexbody->getInterpolationWorldTransform().getOrigin() - convexbody->getWorldTransform().getOrigin()).length2();
       if (squareMot0 < convexbody->getCcdSquareMotionThreshold())
       {
              return btScalar(1.);
       }

       //const btVector3& from = convexbody->m_worldTransform.getOrigin();
       //btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
       //todo: only do if the motion exceeds the 'radius'

       btTransform triInv = triBody->getWorldTransform().inverse();
       btTransform convexFromLocal = triInv * convexbody->getWorldTransform();
       btTransform convexToLocal = triInv * convexbody->getInterpolationWorldTransform();

       struct LocalTriangleSphereCastCallback    : public btTriangleCallback
       {
              btTransform m_ccdSphereFromTrans;
              btTransform m_ccdSphereToTrans;
              btTransform   m_meshTransform;

              btScalar      m_ccdSphereRadius;
              btScalar      m_hitFraction;
       

              LocalTriangleSphereCastCallback(const btTransform& from,const btTransform& to,btScalar ccdSphereRadius,btScalar hitFraction)
                     :m_ccdSphereFromTrans(from),
                     m_ccdSphereToTrans(to),
                     m_ccdSphereRadius(ccdSphereRadius),
                     m_hitFraction(hitFraction)
              {                    
              }
              
              
              virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
              {
                     (void)partId;
                     (void)triangleIndex;
                     //do a swept sphere for now
                     btTransform ident;
                     ident.setIdentity();
                     btConvexCast::CastResult castResult;
                     castResult.m_fraction = m_hitFraction;
                     btSphereShape pointShape(m_ccdSphereRadius);
                     btTriangleShape      triShape(triangle[0],triangle[1],triangle[2]);
                     btVoronoiSimplexSolver      simplexSolver;
                     btSubsimplexConvexCast convexCaster(&pointShape,&triShape,&simplexSolver);
                     //GjkConvexCast      convexCaster(&pointShape,convexShape,&simplexSolver);
                     //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
                     //local space?

                     if (convexCaster.calcTimeOfImpact(m_ccdSphereFromTrans,m_ccdSphereToTrans,
                            ident,ident,castResult))
                     {
                            if (m_hitFraction > castResult.m_fraction)
                                   m_hitFraction = castResult.m_fraction;
                     }

              }

       };


       

       
       if (triBody->getCollisionShape()->isConcave())
       {
              btVector3 rayAabbMin = convexFromLocal.getOrigin();
              rayAabbMin.setMin(convexToLocal.getOrigin());
              btVector3 rayAabbMax = convexFromLocal.getOrigin();
              rayAabbMax.setMax(convexToLocal.getOrigin());
              btScalar ccdRadius0 = convexbody->getCcdSweptSphereRadius();
              rayAabbMin -= btVector3(ccdRadius0,ccdRadius0,ccdRadius0);
              rayAabbMax += btVector3(ccdRadius0,ccdRadius0,ccdRadius0);

              btScalar curHitFraction = btScalar(1.); //is this available?
              LocalTriangleSphereCastCallback raycastCallback(convexFromLocal,convexToLocal,
                     convexbody->getCcdSweptSphereRadius(),curHitFraction);

              raycastCallback.m_hitFraction = convexbody->getHitFraction();

              btCollisionObject* concavebody = triBody;

              btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
              
              if (triangleMesh)
              {
                     triangleMesh->processAllTriangles(&raycastCallback,rayAabbMin,rayAabbMax);
              }
       


              if (raycastCallback.m_hitFraction < convexbody->getHitFraction())
              {
                     convexbody->setHitFraction( raycastCallback.m_hitFraction);
                     return raycastCallback.m_hitFraction;
              }
       }

       return btScalar(1.);

}

Here is the call graph for this function:

Definition at line 160 of file btConvexConcaveCollisionAlgorithm.cpp.

Here is the call graph for this function:

int btCollisionAlgorithm::getDispatcherId ( ) [protected, inherited]
void btConvexConcaveCollisionAlgorithm::processCollision ( btCollisionObject *  body0,
btCollisionObject *  body1,
const btDispatcherInfo dispatchInfo,
btManifoldResult resultOut 
) [virtual]

Implements btCollisionAlgorithm.

Definition at line 166 of file btConvexConcaveCollisionAlgorithm.cpp.

{
       
       
       btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
       btCollisionObject* triBody = m_isSwapped ? body0 : body1;

       if (triBody->getCollisionShape()->isConcave())
       {


              btCollisionObject*   triOb = triBody;
              btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
              
              if (convexBody->getCollisionShape()->isConvex())
              {
                     btScalar collisionMarginTriangle = concaveShape->getMargin();
                                   
                     resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
                     m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);

                     //Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
                     //m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr);

                     m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);

                     concaveShape->processAllTriangles( &m_btConvexTriangleCallback,m_btConvexTriangleCallback.getAabbMin(),m_btConvexTriangleCallback.getAabbMax());
                     
                     resultOut->refreshContactPoints();
       
              }
       
       }

}

Here is the call graph for this function:


Member Data Documentation

Definition at line 78 of file btConvexConcaveCollisionAlgorithm.h.

Definition at line 57 of file btCollisionAlgorithm.h.

Definition at line 76 of file btConvexConcaveCollisionAlgorithm.h.


The documentation for this class was generated from the following files: