Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
btSimpleDynamicsWorld Class Reference

btSimpleDynamicsWorld serves as unit-test and to verify more complicated and optimized dynamics worlds. Please use btDiscreteDynamicsWorld instead (or btContinuousDynamicsWorld once it is finished). More...

#include <btSimpleDynamicsWorld.h>

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

List of all members.

Public Member Functions

 btSimpleDynamicsWorld (btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
 this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
virtual ~btSimpleDynamicsWorld ()
virtual int stepSimulation (btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))
 maxSubSteps/fixedTimeStep for interpolation is currently ignored for btSimpleDynamicsWorld, use btDiscreteDynamicsWorld instead
virtual void setGravity (const btVector3 &gravity)
virtual btVector3 getGravity () const
virtual void addRigidBody (btRigidBody *body)
virtual void removeRigidBody (btRigidBody *body)
virtual void updateAabbs ()
void synchronizeMotionStates ()
virtual void setConstraintSolver (btConstraintSolver *solver)
virtual btConstraintSolvergetConstraintSolver ()
virtual btDynamicsWorldType getWorldType () const
virtual void clearForces ()
virtual void debugDrawWorld ()=0
virtual void addConstraint (btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
virtual void removeConstraint (btTypedConstraint *constraint)
virtual void addVehicle (btRaycastVehicle *vehicle)
virtual void removeVehicle (btRaycastVehicle *vehicle)
virtual int getNumConstraints () const
virtual btTypedConstraintgetConstraint (int index)
virtual const btTypedConstraintgetConstraint (int index) const
void setInternalTickCallback (btInternalTickCallback cb)
 Set the callback for when an internal tick (simulation substep) happens.
btBroadphaseInterfacegetBroadphase ()
btOverlappingPairCachegetPairCache ()
btDispatchergetDispatcher ()
virtual void setDebugDrawer (btIDebugDraw *debugDrawer)
virtual btIDebugDrawgetDebugDrawer ()
int getNumCollisionObjects () const
void rayTest (const btVector3 &rayFromWorld, const btVector3 &rayToWorld, RayResultCallback &resultCallback, short int collisionFilterMask=-1)
 rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
void convexSweepTest (const btConvexShape *castShape, const btTransform &from, const btTransform &to, ConvexResultCallback &resultCallback, short int collisionFilterMask=-1)
void addCollisionObject (btCollisionObject *collisionObject, short int collisionFilterGroup=1, short int collisionFilterMask=1)
btCollisionObjectArraygetCollisionObjectArray ()
const btCollisionObjectArraygetCollisionObjectArray () const
void removeCollisionObject (btCollisionObject *collisionObject)
virtual void performDiscreteCollisionDetection ()
btDispatcherInfogetDispatchInfo ()

Static Public Member Functions

static void rayTestSingle (const btTransform &rayFromTrans, const btTransform &rayToTrans, btCollisionObject *collisionObject, const btCollisionShape *collisionShape, const btTransform &colObjWorldTransform, RayResultCallback &resultCallback, short int collisionFilterMask=-1)
 rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest. In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape. This allows more customization.
static void objectQuerySingle (const btConvexShape *castShape, const btTransform &rayFromTrans, const btTransform &rayToTrans, btCollisionObject *collisionObject, const btCollisionShape *collisionShape, const btTransform &colObjWorldTransform, ConvexResultCallback &resultCallback, short int collisionFilterMask=-1)
 objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.

Public Attributes

btInternalTickCallback m_internalTickCallback

Protected Member Functions

void predictUnconstraintMotion (btScalar timeStep)
void integrateTransforms (btScalar timeStep)

Protected Attributes

btConstraintSolverm_constraintSolver
bool m_ownsConstraintSolver
btVector3 m_gravity
btAlignedObjectArray
< btCollisionObject * > 
m_collisionObjects
btDispatcherm_dispatcher1
btDispatcherInfo m_dispatchInfo
btStackAllocm_stackAlloc
btBroadphaseInterfacem_broadphasePairCache
btIDebugDrawm_debugDrawer

Detailed Description

btSimpleDynamicsWorld serves as unit-test and to verify more complicated and optimized dynamics worlds. Please use btDiscreteDynamicsWorld instead (or btContinuousDynamicsWorld once it is finished).

Definition at line 27 of file btSimpleDynamicsWorld.h.


Constructor & Destructor Documentation

btSimpleDynamicsWorld::btSimpleDynamicsWorld ( btDispatcher dispatcher,
btBroadphaseInterface pairCache,
btConstraintSolver constraintSolver,
btCollisionConfiguration collisionConfiguration 
)

this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver

Definition at line 35 of file btSimpleDynamicsWorld.cpp.

:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
m_constraintSolver(constraintSolver),
m_ownsConstraintSolver(false),
m_gravity(0,0,-10)
{

}

Member Function Documentation

void btCollisionWorld::addCollisionObject ( btCollisionObject *  collisionObject,
short int  collisionFilterGroup = 1,
short int  collisionFilterMask = 1 
) [inherited]

Definition at line 84 of file btCollisionWorld.cpp.

{

       //check that the object isn't already added
              btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());

              m_collisionObjects.push_back(collisionObject);

              //calculate new AABB
              btTransform trans = collisionObject->getWorldTransform();

              btVector3     minAabb;
              btVector3     maxAabb;
              collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb);

              int type = collisionObject->getCollisionShape()->getShapeType();
              collisionObject->setBroadphaseHandle( getBroadphase()->createProxy(
                     minAabb,
                     maxAabb,
                     type,
                     collisionObject,
                     collisionFilterGroup,
                     collisionFilterMask,
                     m_dispatcher1,0
                     ))     ;

              



}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void btDynamicsWorld::addConstraint ( btTypedConstraint constraint,
bool  disableCollisionsBetweenLinkedBodies = false 
) [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 56 of file btDynamicsWorld.h.

{ (void)constraint;};

Here is the caller graph for this function:

Implements btDynamicsWorld.

Definition at line 134 of file btSimpleDynamicsWorld.cpp.

{
       body->setGravity(m_gravity);

       if (body->getCollisionShape())
       {
              addCollisionObject(body);
       }
}

Here is the call graph for this function:

virtual void btDynamicsWorld::addVehicle ( btRaycastVehicle vehicle) [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 60 of file btDynamicsWorld.h.

{(void)vehicle;};

Here is the caller graph for this function:

Implements btDynamicsWorld.

Definition at line 94 of file btSimpleDynamicsWorld.cpp.

{
       //todo: iterate over awake simulation islands!
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     body->clearForces();
              }
       }
}      

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::convexSweepTest ( const btConvexShape *  castShape,
const btTransform from,
const btTransform to,
ConvexResultCallback resultCallback,
short int  collisionFilterMask = -1 
) [inherited]

go over all objects, and if the ray intersects their aabb + cast shape aabb,

Definition at line 618 of file btCollisionWorld.cpp.

{
       btTransform   convexFromTrans,convexToTrans;
       convexFromTrans = convexFromWorld;
       convexToTrans = convexToWorld;
       btVector3 castShapeAabbMin, castShapeAabbMax;
       /* Compute AABB that encompasses angular movement */
       {
              btVector3 linVel, angVel;
              btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
              btTransform R;
              R.setIdentity ();
              R.setRotation (convexFromTrans.getRotation());
              castShape->calculateTemporalAabb (R, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
       }

       // do a ray-shape query using convexCaster (CCD)
       int i;
       for (i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject*   collisionObject= m_collisionObjects[i];
              //only perform raycast if filterMask matches
              if(collisionObject->getBroadphaseHandle()->m_collisionFilterGroup & collisionFilterMask) { 
                     //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
                     btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
                     collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
                     AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
                     btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
                     btVector3 hitNormal;
                     if (btRayAabb(convexFromWorld.getOrigin(),convexToWorld.getOrigin(),collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
                     {
                            objectQuerySingle(castShape, convexFromTrans,convexToTrans,
                                   collisionObject,
                                          collisionObject->getCollisionShape(),
                                          collisionObject->getWorldTransform(),
                                          resultCallback);
                     }      
              }
       }

}

Here is the call graph for this function:

virtual void btDynamicsWorld::debugDrawWorld ( ) [pure virtual, inherited]

Implemented in btDiscreteDynamicsWorld.

Definition at line 106 of file btCollisionWorld.h.

       {
              return m_broadphasePairCache;
       }

Here is the caller graph for this function:

Definition at line 333 of file btCollisionWorld.h.

       {
              return m_collisionObjects;
       }

Here is the caller graph for this function:

Definition at line 338 of file btCollisionWorld.h.

       {
              return m_collisionObjects;
       }
virtual btTypedConstraint* btDynamicsWorld::getConstraint ( int  index) [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 79 of file btDynamicsWorld.h.

{      (void)index;         return 0;            }
virtual const btTypedConstraint* btDynamicsWorld::getConstraint ( int  index) const [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 81 of file btDynamicsWorld.h.

{      (void)index;  return 0;     }

Implements btDynamicsWorld.

Definition at line 236 of file btSimpleDynamicsWorld.cpp.

{
       return m_constraintSolver;
}
virtual btIDebugDraw* btCollisionWorld::getDebugDrawer ( ) [inline, virtual, inherited]

Definition at line 129 of file btCollisionWorld.h.

       {
              return m_debugDrawer;
       }

Here is the caller graph for this function:

Definition at line 117 of file btCollisionWorld.h.

       {
              return m_dispatcher1;
       }

Here is the caller graph for this function:

Definition at line 348 of file btCollisionWorld.h.

       {
              return m_dispatchInfo;
       }

Here is the caller graph for this function:

Implements btDynamicsWorld.

Definition at line 124 of file btSimpleDynamicsWorld.cpp.

{
       return m_gravity;
}
int btCollisionWorld::getNumCollisionObjects ( ) const [inline, inherited]

Definition at line 301 of file btCollisionWorld.h.

       {
              return int(m_collisionObjects.size());
       }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual int btDynamicsWorld::getNumConstraints ( ) const [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 77 of file btDynamicsWorld.h.

{      return 0;            }

Definition at line 111 of file btCollisionWorld.h.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual btDynamicsWorldType btSimpleDynamicsWorld::getWorldType ( ) const [inline, virtual]

Implements btDynamicsWorld.

Definition at line 69 of file btSimpleDynamicsWorld.h.

void btSimpleDynamicsWorld::integrateTransforms ( btScalar  timeStep) [protected]

Definition at line 164 of file btSimpleDynamicsWorld.cpp.

{
       btTransform predictedTrans;
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     if (body->isActive() && (!body->isStaticObject()))
                     {
                            body->predictIntegratedTransform(timeStep, predictedTrans);
                            body->proceedToTransform( predictedTrans);
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::objectQuerySingle ( const btConvexShape *  castShape,
const btTransform rayFromTrans,
const btTransform rayToTrans,
btCollisionObject *  collisionObject,
const btCollisionShape collisionShape,
const btTransform colObjWorldTransform,
ConvexResultCallback resultCallback,
short int  collisionFilterMask = -1 
) [static, inherited]

objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.

Definition at line 393 of file btCollisionWorld.cpp.

{
       if (collisionShape->isConvex())
       {
              btConvexCast::CastResult castResult;
              castResult.m_fraction = btScalar(1.);//??

              btConvexShape* convexShape = (btConvexShape*) collisionShape;
              btVoronoiSimplexSolver      simplexSolver;
              btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);

              if (convexCaster.calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
              {
                     //add hit
                     if (castResult.m_normal.length2() > btScalar(0.0001))
                     {                                  
                            if (castResult.m_fraction < resultCallback.m_closestHitFraction)
                            {
                                   castResult.m_normal.normalize();
                                   btCollisionWorld::LocalConvexResult localConvexResult
                                                        (
                                                               collisionObject, 
                                                               0,
                                                               castResult.m_normal,
                                                               castResult.m_hitPoint,
                                                               castResult.m_fraction
                                                        );

                                   bool normalInWorldSpace = true;
                                   resultCallback.AddSingleResult(localConvexResult, normalInWorldSpace);

                            }
                     }
              }
       } else {
              if (collisionShape->isConcave())
              {
                     if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
                     {
                            btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
                            btTransform worldTocollisionObject = colObjWorldTransform.inverse();
                            btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
                            btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
                            // rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
                            btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());

                            //ConvexCast::CastResult
                            struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback 
                            {
                                   btCollisionWorld::ConvexResultCallback* m_resultCallback;
                                   btCollisionObject*   m_collisionObject;
                                   btTriangleMeshShape* m_triangleMesh;

                                   BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
                                          btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld):
                                          btTriangleConvexcastCallback(castShape, from,to, triangleToWorld),
                                                 m_resultCallback(resultCallback),
                                                 m_collisionObject(collisionObject),
                                                 m_triangleMesh(triangleMesh)
                                          {
                                          }


                                   virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
                                   {
                                          btCollisionWorld::LocalShapeInfo   shapeInfo;
                                          shapeInfo.m_shapePart = partId;
                                          shapeInfo.m_triangleIndex = triangleIndex;
                                          if (hitFraction <= m_resultCallback->m_closestHitFraction)
                                          {

                                                 btCollisionWorld::LocalConvexResult convexResult
                                                 (m_collisionObject, 
                                                        &shapeInfo,
                                                        hitNormalLocal,
                                                        hitPointLocal,
                                                        hitFraction);
                                                 
                                                 bool   normalInWorldSpace = true;

                                   
                                                 return m_resultCallback->AddSingleResult(convexResult,normalInWorldSpace);
                                          }
                                          return hitFraction;
                                   }

                            };

                            BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
                            tccb.m_hitFraction = resultCallback.m_closestHitFraction;
                            btVector3 boxMinLocal, boxMaxLocal;
                            castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
                            triangleMesh->performConvexcast(&tccb,convexFromLocal,convexToLocal,boxMinLocal, boxMaxLocal);
                     } else
                     {
                            btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
                            btTransform worldTocollisionObject = colObjWorldTransform.inverse();
                            btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
                            btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
                            // rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
                            btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());

                            //ConvexCast::CastResult
                            struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback 
                            {
                                   btCollisionWorld::ConvexResultCallback* m_resultCallback;
                                   btCollisionObject*   m_collisionObject;
                                   btTriangleMeshShape* m_triangleMesh;

                                   BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
                                          btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld):
                                          btTriangleConvexcastCallback(castShape, from,to, triangleToWorld),
                                                 m_resultCallback(resultCallback),
                                                 m_collisionObject(collisionObject),
                                                 m_triangleMesh(triangleMesh)
                                          {
                                          }


                                   virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
                                   {
                                          btCollisionWorld::LocalShapeInfo   shapeInfo;
                                          shapeInfo.m_shapePart = partId;
                                          shapeInfo.m_triangleIndex = triangleIndex;
                                          if (hitFraction <= m_resultCallback->m_closestHitFraction)
                                          {

                                                 btCollisionWorld::LocalConvexResult convexResult
                                                 (m_collisionObject, 
                                                        &shapeInfo,
                                                        hitNormalLocal,
                                                        hitPointLocal,
                                                        hitFraction);
                                                 
                                                 bool   normalInWorldSpace = false;

                                                 return m_resultCallback->AddSingleResult(convexResult,normalInWorldSpace);
                                          }
                                          return hitFraction;
                                   }

                            };

                            BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
                            tccb.m_hitFraction = resultCallback.m_closestHitFraction;
                            btVector3 boxMinLocal, boxMaxLocal;
                            castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
                            
                            btVector3 rayAabbMinLocal = convexFromLocal;
                            rayAabbMinLocal.setMin(convexToLocal);
                            btVector3 rayAabbMaxLocal = convexFromLocal;
                            rayAabbMaxLocal.setMax(convexToLocal);
                            rayAabbMinLocal += boxMinLocal;
                            rayAabbMaxLocal += boxMaxLocal;
                            triangleMesh->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
                     }
              } else {
                     //todo: use AABB tree or other BVH acceleration structure!
                     if (collisionShape->isCompound())
                     {
                            const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
                            int i=0;
                            for (i=0;i<compoundShape->getNumChildShapes();i++)
                            {
                                   btTransform childTrans = compoundShape->getChildTransform(i);
                                   const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
                                   btTransform childWorldTrans = colObjWorldTransform * childTrans;
                                   objectQuerySingle(castShape, convexFromTrans,convexToTrans,
                                          collisionObject,
                                          childCollisionShape,
                                          childWorldTrans,
                                          resultCallback, collisionFilterMask);
                            }
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 159 of file btCollisionWorld.cpp.

{
       BT_PROFILE("performDiscreteCollisionDetection");

       btDispatcherInfo& dispatchInfo = getDispatchInfo();

       updateAabbs();

       {
              m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
       }


       btDispatcher* dispatcher = getDispatcher();
       {
              BT_PROFILE("dispatchAllCollisionPairs");
              if (dispatcher)
                     dispatcher->dispatchAllCollisionPairs(m_broadphasePairCache->getOverlappingPairCache(),dispatchInfo,m_dispatcher1);
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 184 of file btSimpleDynamicsWorld.cpp.

{
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     if (!body->isStaticObject())
                     {
                            if (body->isActive())
                            {
                                   body->applyGravity();
                                   body->integrateVelocities( timeStep);
                                   body->applyDamping(timeStep);
                                   body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
                            }
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::rayTest ( const btVector3 rayFromWorld,
const btVector3 rayToWorld,
RayResultCallback resultCallback,
short int  collisionFilterMask = -1 
) [inherited]

rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.

go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD)

terminate further ray tests, once the closestHitFraction reached zero

Definition at line 575 of file btCollisionWorld.cpp.

{

       
       btTransform   rayFromTrans,rayToTrans;
       rayFromTrans.setIdentity();
       rayFromTrans.setOrigin(rayFromWorld);
       rayToTrans.setIdentity();
       
       rayToTrans.setOrigin(rayToWorld);

       
       int i;
       for (i=0;i<m_collisionObjects.size();i++)
       {
              if (resultCallback.m_closestHitFraction == btScalar(0.f))
                     break;

              btCollisionObject*   collisionObject= m_collisionObjects[i];
              //only perform raycast if filterMask matches
              if(collisionObject->getBroadphaseHandle()->m_collisionFilterGroup & collisionFilterMask) { 
                     //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
                     btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
                     collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);

                     btScalar hitLambda = resultCallback.m_closestHitFraction;
                     btVector3 hitNormal;
                     if (btRayAabb(rayFromWorld,rayToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
                     {
                            rayTestSingle(rayFromTrans,rayToTrans,
                                   collisionObject,
                                          collisionObject->getCollisionShape(),
                                          collisionObject->getWorldTransform(),
                                          resultCallback);
                     }      
              }
              
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::rayTestSingle ( const btTransform rayFromTrans,
const btTransform rayToTrans,
btCollisionObject *  collisionObject,
const btCollisionShape collisionShape,
const btTransform colObjWorldTransform,
RayResultCallback resultCallback,
short int  collisionFilterMask = -1 
) [static, inherited]

rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest. In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape. This allows more customization.

optimized version for btBvhTriangleMeshShape

Definition at line 211 of file btCollisionWorld.cpp.

{
       btSphereShape pointShape(btScalar(0.0));
       pointShape.setMargin(0.f);
       const btConvexShape* castShape = &pointShape;

       if (collisionShape->isConvex())
       {
              btConvexCast::CastResult castResult;
              castResult.m_fraction = resultCallback.m_closestHitFraction;

              btConvexShape* convexShape = (btConvexShape*) collisionShape;
              btVoronoiSimplexSolver      simplexSolver;
#define USE_SUBSIMPLEX_CONVEX_CAST 1
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
              btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
#else
              //btGjkConvexCast    convexCaster(castShape,convexShape,&simplexSolver);
              //btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
#endif //#USE_SUBSIMPLEX_CONVEX_CAST
                     
              if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
              {
                     //add hit
                     if (castResult.m_normal.length2() > btScalar(0.0001))
                     {                           
                            if (castResult.m_fraction < resultCallback.m_closestHitFraction)
                            {
#ifdef USE_SUBSIMPLEX_CONVEX_CAST
                                   //rotate normal into worldspace
                                   castResult.m_normal = rayFromTrans.getBasis() * castResult.m_normal;
#endif //USE_SUBSIMPLEX_CONVEX_CAST

                                   castResult.m_normal.normalize();
                                   btCollisionWorld::LocalRayResult localRayResult
                                          (
                                                 collisionObject, 
                                                 0,
                                                 castResult.m_normal,
                                                 castResult.m_fraction
                                          );

                                   bool normalInWorldSpace = true;
                                   resultCallback.AddSingleResult(localRayResult, normalInWorldSpace);

                            }
                     }
              }
       } else {
              if (collisionShape->isConcave())
              {
                     if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
                     {
                            btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
                            btTransform worldTocollisionObject = colObjWorldTransform.inverse();
                            btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
                            btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();

                            //ConvexCast::CastResult
                            struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback 
                            {
                                   btCollisionWorld::RayResultCallback* m_resultCallback;
                                   btCollisionObject*   m_collisionObject;
                                   btTriangleMeshShape* m_triangleMesh;

                                   BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
                                          btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh):
                                          btTriangleRaycastCallback(from,to),
                                                 m_resultCallback(resultCallback),
                                                 m_collisionObject(collisionObject),
                                                 m_triangleMesh(triangleMesh)
                                          {
                                          }


                                   virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex )
                                   {
                                          btCollisionWorld::LocalShapeInfo   shapeInfo;
                                          shapeInfo.m_shapePart = partId;
                                          shapeInfo.m_triangleIndex = triangleIndex;
                                          
                                          btCollisionWorld::LocalRayResult rayResult
                                          (m_collisionObject, 
                                                 &shapeInfo,
                                                 hitNormalLocal,
                                                 hitFraction);
                                          
                                          bool   normalInWorldSpace = false;
                                          return m_resultCallback->AddSingleResult(rayResult,normalInWorldSpace);
                                   }

                            };

                            BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
                            rcb.m_hitFraction = resultCallback.m_closestHitFraction;
                            triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
                     } else
                     {
                            btTriangleMeshShape* triangleMesh = (btTriangleMeshShape*)collisionShape;
                            
                            btTransform worldTocollisionObject = colObjWorldTransform.inverse();

                            btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
                            btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();

                            //ConvexCast::CastResult

                            struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback 
                            {
                                   btCollisionWorld::RayResultCallback* m_resultCallback;
                                   btCollisionObject*   m_collisionObject;
                                   btTriangleMeshShape* m_triangleMesh;

                                   BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
                                          btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh):
                                          btTriangleRaycastCallback(from,to),
                                                 m_resultCallback(resultCallback),
                                                 m_collisionObject(collisionObject),
                                                 m_triangleMesh(triangleMesh)
                                          {
                                          }


                                   virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex )
                                   {
                                          btCollisionWorld::LocalShapeInfo   shapeInfo;
                                          shapeInfo.m_shapePart = partId;
                                          shapeInfo.m_triangleIndex = triangleIndex;
                                          
                                          btCollisionWorld::LocalRayResult rayResult
                                          (m_collisionObject, 
                                                 &shapeInfo,
                                                 hitNormalLocal,
                                                 hitFraction);
                                          
                                          bool   normalInWorldSpace = false;
                                          return m_resultCallback->AddSingleResult(rayResult,normalInWorldSpace);
                                          
                                          
                                   }

                            };


                            BridgeTriangleRaycastCallback      rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
                            rcb.m_hitFraction = resultCallback.m_closestHitFraction;

                            btVector3 rayAabbMinLocal = rayFromLocal;
                            rayAabbMinLocal.setMin(rayToLocal);
                            btVector3 rayAabbMaxLocal = rayFromLocal;
                            rayAabbMaxLocal.setMax(rayToLocal);

                            triangleMesh->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
                     }
              } else {
                     //todo: use AABB tree or other BVH acceleration structure!
                     if (collisionShape->isCompound())
                     {
                            const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
                            int i=0;
                            for (i=0;i<compoundShape->getNumChildShapes();i++)
                            {
                                   btTransform childTrans = compoundShape->getChildTransform(i);
                                   const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
                                   btTransform childWorldTrans = colObjWorldTransform * childTrans;
                                   rayTestSingle(rayFromTrans,rayToTrans,
                                          collisionObject,
                                          childCollisionShape,
                                          childWorldTrans,
                                          resultCallback, collisionFilterMask);

                            }
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::removeCollisionObject ( btCollisionObject *  collisionObject) [inherited]

Definition at line 183 of file btCollisionWorld.cpp.

{
       
       
       //bool removeFromBroadphase = false;
       
       {
              
              btBroadphaseProxy* bp = collisionObject->getBroadphaseHandle();
              if (bp)
              {
                     //
                     // only clear the cached algorithms
                     //
                     getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bp,m_dispatcher1);
                     getBroadphase()->destroyProxy(bp,m_dispatcher1);
                     collisionObject->setBroadphaseHandle(0);
              }
       }


       //swapremove
       m_collisionObjects.remove(collisionObject);

}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void btDynamicsWorld::removeConstraint ( btTypedConstraint constraint) [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 58 of file btDynamicsWorld.h.

{(void)constraint;};

Here is the caller graph for this function:

Implements btDynamicsWorld.

Definition at line 129 of file btSimpleDynamicsWorld.cpp.

Here is the call graph for this function:

virtual void btDynamicsWorld::removeVehicle ( btRaycastVehicle vehicle) [inline, virtual, inherited]

Reimplemented in btDiscreteDynamicsWorld.

Definition at line 62 of file btDynamicsWorld.h.

{(void)vehicle;};

Here is the caller graph for this function:

virtual void btCollisionWorld::setDebugDrawer ( btIDebugDraw debugDrawer) [inline, virtual, inherited]

Definition at line 124 of file btCollisionWorld.h.

       {
                     m_debugDrawer = debugDrawer;
       }

Here is the caller graph for this function:

void btSimpleDynamicsWorld::setGravity ( const btVector3 gravity) [virtual]

Implements btDynamicsWorld.

Definition at line 110 of file btSimpleDynamicsWorld.cpp.

{
       m_gravity = gravity;
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     body->setGravity(gravity);
              }
       }
}

Here is the call graph for this function:

Set the callback for when an internal tick (simulation substep) happens.

Definition at line 88 of file btDynamicsWorld.h.

int btSimpleDynamicsWorld::stepSimulation ( btScalar  timeStep,
int  maxSubSteps = 1,
btScalar  fixedTimeStep = btScalar(1.)/btScalar(60.) 
) [virtual]

maxSubSteps/fixedTimeStep for interpolation is currently ignored for btSimpleDynamicsWorld, use btDiscreteDynamicsWorld instead

apply gravity, predict motion

perform collision detection

solve contact constraints

integrate transforms

Implements btDynamicsWorld.

Definition at line 51 of file btSimpleDynamicsWorld.cpp.

{
       (void)fixedTimeStep;
       (void)maxSubSteps;


       predictUnconstraintMotion(timeStep);

       btDispatcherInfo&    dispatchInfo = getDispatchInfo();
       dispatchInfo.m_timeStep = timeStep;
       dispatchInfo.m_stepCount = 0;
       dispatchInfo.m_debugDraw = getDebugDrawer();

       performDiscreteCollisionDetection();

       int numManifolds = m_dispatcher1->getNumManifolds();
       if (numManifolds)
       {
              btPersistentManifold** manifoldPtr = ((btCollisionDispatcher*)m_dispatcher1)->getInternalManifoldPointer();
              
              btContactSolverInfo infoGlobal;
              infoGlobal.m_timeStep = timeStep;
              m_constraintSolver->prepareSolve(0,numManifolds);
              m_constraintSolver->solveGroup(0,0,manifoldPtr, numManifolds,0,0,infoGlobal,m_debugDrawer, m_stackAlloc,m_dispatcher1);
              m_constraintSolver->allSolved(infoGlobal,m_debugDrawer, m_stackAlloc);
       }

       integrateTransforms(timeStep);
              
       updateAabbs();

       synchronizeMotionStates();

       clearForces();

       return 1;

}

Here is the call graph for this function:

Definition at line 207 of file btSimpleDynamicsWorld.cpp.

{
       //todo: iterate over awake simulation islands!
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body && body->getMotionState())
              {
                     if (body->getActivationState() != ISLAND_SLEEPING)
                     {
                            body->getMotionState()->setWorldTransform(body->getWorldTransform());
                     }
              }
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from btCollisionWorld.

Definition at line 144 of file btSimpleDynamicsWorld.cpp.

{
       btTransform predictedTrans;
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     if (body->isActive() && (!body->isStaticObject()))
                     {
                            btPoint3 minAabb,maxAabb;
                            colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
                            btBroadphaseInterface* bp = getBroadphase();
                            bp->setAabb(body->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1);
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 93 of file btCollisionWorld.h.

btAlignedObjectArray<btCollisionObject*> btCollisionWorld::m_collisionObjects [protected, inherited]

Definition at line 85 of file btCollisionWorld.h.

Definition at line 31 of file btSimpleDynamicsWorld.h.

Definition at line 95 of file btCollisionWorld.h.

Definition at line 87 of file btCollisionWorld.h.

Definition at line 89 of file btCollisionWorld.h.

Definition at line 39 of file btSimpleDynamicsWorld.h.

Definition at line 90 of file btDynamicsWorld.h.

Definition at line 33 of file btSimpleDynamicsWorld.h.

Definition at line 91 of file btCollisionWorld.h.


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