Back to index

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

btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController More...

#include <btDiscreteDynamicsWorld.h>

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

List of all members.

Public Member Functions

 btDiscreteDynamicsWorld (btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
 this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
virtual ~btDiscreteDynamicsWorld ()
virtual int stepSimulation (btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))
 if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
void addConstraint (btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
void removeConstraint (btTypedConstraint *constraint)
void addVehicle (btRaycastVehicle *vehicle)
void removeVehicle (btRaycastVehicle *vehicle)
btSimulationIslandManagergetSimulationIslandManager ()
const btSimulationIslandManagergetSimulationIslandManager () const
btCollisionWorldgetCollisionWorld ()
virtual void setGravity (const btVector3 &gravity)
virtual btVector3 getGravity () const
virtual void addRigidBody (btRigidBody *body)
virtual void addRigidBody (btRigidBody *body, short group, short mask)
virtual void removeRigidBody (btRigidBody *body)
void debugDrawObject (const btTransform &worldTransform, const btCollisionShape *shape, const btVector3 &color)
virtual void debugDrawWorld ()
virtual void setConstraintSolver (btConstraintSolver *solver)
virtual btConstraintSolvergetConstraintSolver ()
virtual int getNumConstraints () const
virtual btTypedConstraintgetConstraint (int index)
virtual const btTypedConstraintgetConstraint (int index) const
btContactSolverInfogetSolverInfo ()
virtual btDynamicsWorldType getWorldType () const
virtual void clearForces ()
 the forces on each rigidbody is accumulating together with gravity. clear this after each timestep.
virtual void applyGravity ()
 apply gravity, call this once per timestep
void setInternalTickCallback (btInternalTickCallback cb)
 Set the callback for when an internal tick (simulation substep) happens.
btBroadphaseInterfacegetBroadphase ()
btOverlappingPairCachegetPairCache ()
btDispatchergetDispatcher ()
virtual void updateAabbs ()
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

virtual void predictUnconstraintMotion (btScalar timeStep)
void integrateTransforms (btScalar timeStep)
void calculateSimulationIslands ()
void solveConstraints (btContactSolverInfo &solverInfo)
void updateActivationState (btScalar timeStep)
void updateVehicles (btScalar timeStep)
void startProfiling (btScalar timeStep)
virtual void internalSingleStepSimulation (btScalar timeStep)
void synchronizeMotionStates ()
void saveKinematicState (btScalar timeStep)
void debugDrawSphere (btScalar radius, const btTransform &transform, const btVector3 &color)

Protected Attributes

btConstraintSolverm_constraintSolver
btSimulationIslandManagerm_islandManager
btAlignedObjectArray
< btTypedConstraint * > 
m_constraints
btVector3 m_gravity
btScalar m_localTime
bool m_ownsIslandManager
bool m_ownsConstraintSolver
btContactSolverInfo m_solverInfo
btAlignedObjectArray
< btRaycastVehicle * > 
m_vehicles
int m_profileTimings
btAlignedObjectArray
< btCollisionObject * > 
m_collisionObjects
btDispatcherm_dispatcher1
btDispatcherInfo m_dispatchInfo
btStackAllocm_stackAlloc
btBroadphaseInterfacem_broadphasePairCache
btIDebugDrawm_debugDrawer

Detailed Description

btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController

Definition at line 35 of file btDiscreteDynamicsWorld.h.


Constructor & Destructor Documentation

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

this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those

Definition at line 62 of file btDiscreteDynamicsWorld.cpp.

:btDynamicsWorld(dispatcher,pairCache,collisionConfiguration),
m_constraintSolver(constraintSolver),
m_gravity(0,-10,0),
m_localTime(btScalar(1.)/btScalar(60.)),
m_profileTimings(0)
{
       if (!m_constraintSolver)
       {
              void* mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
              m_constraintSolver = new (mem) btSequentialImpulseConstraintSolver;
              m_ownsConstraintSolver = true;
       } else
       {
              m_ownsConstraintSolver = false;
       }

       {
              void* mem = btAlignedAlloc(sizeof(btSimulationIslandManager),16);
              m_islandManager = new (mem) btSimulationIslandManager();
       }

       m_ownsIslandManager = true;
}

Definition at line 88 of file btDiscreteDynamicsWorld.cpp.

Here is the call graph for this function:


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:

void btDiscreteDynamicsWorld::addConstraint ( btTypedConstraint constraint,
bool  disableCollisionsBetweenLinkedBodies = false 
) [virtual]

Reimplemented from btDynamicsWorld.

Definition at line 481 of file btDiscreteDynamicsWorld.cpp.

{
       m_constraints.push_back(constraint);
       if (disableCollisionsBetweenLinkedBodies)
       {
              constraint->getRigidBodyA().addConstraintRef(constraint);
              constraint->getRigidBodyB().addConstraintRef(constraint);
       }
}

Here is the call graph for this function:

Implements btDynamicsWorld.

Definition at line 408 of file btDiscreteDynamicsWorld.cpp.

{
       if (!body->isStaticOrKinematicObject())
       {
              body->setGravity(m_gravity);
       }

       if (body->getCollisionShape())
       {
              bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
              short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
              short collisionFilterMask = isDynamic?    short(btBroadphaseProxy::AllFilter) :     short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);

              addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
       }
}

Here is the call graph for this function:

void btDiscreteDynamicsWorld::addRigidBody ( btRigidBody body,
short  group,
short  mask 
) [virtual]

Definition at line 425 of file btDiscreteDynamicsWorld.cpp.

{
       if (!body->isStaticOrKinematicObject())
       {
              body->setGravity(m_gravity);
       }

       if (body->getCollisionShape())
       {
              addCollisionObject(body,group,mask);
       }
}

Here is the call graph for this function:

Reimplemented from btDynamicsWorld.

Definition at line 498 of file btDiscreteDynamicsWorld.cpp.

{
       m_vehicles.push_back(vehicle);
}

Here is the call graph for this function:

apply gravity, call this once per timestep

Definition at line 216 of file btDiscreteDynamicsWorld.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->isActive())
              {
                     body->applyGravity();
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 648 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("calculateSimulationIslands");

       getSimulationIslandManager()->updateActivationState(getCollisionWorld(),getCollisionWorld()->getDispatcher());

       {
              int i;
              int numConstraints = int(m_constraints.size());
              for (i=0;i< numConstraints ; i++ )
              {
                     btTypedConstraint* constraint = m_constraints[i];

                     const btRigidBody* colObj0 = &constraint->getRigidBodyA();
                     const btRigidBody* colObj1 = &constraint->getRigidBodyB();

                     if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
                            ((colObj1) && ((colObj1)->mergesSimulationIslands())))
                     {
                            if (colObj0->isActive() || colObj1->isActive())
                            {

                                   getSimulationIslandManager()->getUnionFind().unite((colObj0)->getIslandTag(),
                                          (colObj1)->getIslandTag());
                            }
                     }
              }
       }

       //Store the island id in each body
       getSimulationIslandManager()->storeIslandActivationState(getCollisionWorld());

       
}

Here is the call graph for this function:

Here is the caller graph for this function:

the forces on each rigidbody is accumulating together with gravity. clear this after each timestep.

Implements btDynamicsWorld.

Definition at line 200 of file btDiscreteDynamicsWorld.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:

void btDiscreteDynamicsWorld::debugDrawObject ( const btTransform worldTransform,
const btCollisionShape shape,
const btVector3 color 
)

for polyhedral shapes

Definition at line 808 of file btDiscreteDynamicsWorld.cpp.

{
       // Draw a small simplex at the center of the object
       {
              btVector3 start = worldTransform.getOrigin();
              getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(1,0,0), btVector3(1,0,0));
              getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,1,0), btVector3(0,1,0));
              getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,0,1), btVector3(0,0,1));
       }

       if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
       {
              const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
              for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--)
              {
                     btTransform childTrans = compoundShape->getChildTransform(i);
                     const btCollisionShape* colShape = compoundShape->getChildShape(i);
                     debugDrawObject(worldTransform*childTrans,colShape,color);
              }

       } else
       {
              switch (shape->getShapeType())
              {

              case SPHERE_SHAPE_PROXYTYPE:
                     {
                            const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
                            btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
                            
                            debugDrawSphere(radius, worldTransform, color);
                            break;
                     }
              case MULTI_SPHERE_SHAPE_PROXYTYPE:
                     {
                            const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);

                            for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
                            {
                                   btTransform childTransform = worldTransform;
                                   childTransform.getOrigin() += multiSphereShape->getSpherePosition(i);
                                   debugDrawSphere(multiSphereShape->getSphereRadius(i), childTransform, color);
                            }

                            break;
                     }
              case CAPSULE_SHAPE_PROXYTYPE:
                     {
                            const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);

                            btScalar radius = capsuleShape->getRadius();
                            btScalar halfHeight = capsuleShape->getHalfHeight();

                            // Draw the ends
                            {
                                   btTransform childTransform = worldTransform;
                                   childTransform.getOrigin() = worldTransform * btVector3(0,halfHeight,0);
                                   debugDrawSphere(radius, childTransform, color);
                            }

                            {
                                   btTransform childTransform = worldTransform;
                                   childTransform.getOrigin() = worldTransform * btVector3(0,-halfHeight,0);
                                   debugDrawSphere(radius, childTransform, color);
                            }

                            // Draw some additional lines
                            btVector3 start = worldTransform.getOrigin();
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(-radius,halfHeight,0),start+worldTransform.getBasis() * btVector3(-radius,-halfHeight,0), color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(radius,halfHeight,0),start+worldTransform.getBasis() * btVector3(radius,-halfHeight,0), color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(0,halfHeight,-radius),start+worldTransform.getBasis() * btVector3(0,-halfHeight,-radius), color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * btVector3(0,halfHeight,radius),start+worldTransform.getBasis() * btVector3(0,-halfHeight,radius), color);

                            break;
                     }
              case CONE_SHAPE_PROXYTYPE:
                     {
                            const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
                            btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
                            btScalar height = coneShape->getHeight();//+coneShape->getMargin();
                            btVector3 start = worldTransform.getOrigin();

                            int upAxis= coneShape->getConeUpIndex();
                            

                            btVector3     offsetHeight(0,0,0);
                            offsetHeight[upAxis] = height * btScalar(0.5);
                            btVector3     offsetRadius(0,0,0);
                            offsetRadius[(upAxis+1)%3] = radius;
                            btVector3     offset2Radius(0,0,0);
                            offset2Radius[(upAxis+2)%3] = radius;

                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color);



                            break;

                     }
              case CYLINDER_SHAPE_PROXYTYPE:
                     {
                            const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
                            int upAxis = cylinder->getUpAxis();
                            btScalar radius = cylinder->getRadius();
                            btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
                            btVector3 start = worldTransform.getOrigin();
                            btVector3     offsetHeight(0,0,0);
                            offsetHeight[upAxis] = halfHeight;
                            btVector3     offsetRadius(0,0,0);
                            offsetRadius[(upAxis+1)%3] = radius;
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
                            getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
                            break;
                     }

                     case STATIC_PLANE_PROXYTYPE:
                            {
                                   const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
                                   btScalar planeConst = staticPlaneShape->getPlaneConstant();
                                   const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
                                   btVector3 planeOrigin = planeNormal * planeConst;
                                   btVector3 vec0,vec1;
                                   btPlaneSpace1(planeNormal,vec0,vec1);
                                   btScalar vecLen = 100.f;
                                   btVector3 pt0 = planeOrigin + vec0*vecLen;
                                   btVector3 pt1 = planeOrigin - vec0*vecLen;
                                   btVector3 pt2 = planeOrigin + vec1*vecLen;
                                   btVector3 pt3 = planeOrigin - vec1*vecLen;
                                   getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color);
                                   getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color);
                                   break;

                            }
              default:
                     {

                            if (shape->isConcave())
                            {
                                   btConcaveShape* concaveMesh = (btConcaveShape*) shape;
                                   
                                   //todo pass camera, for some culling
                                   btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
                                   btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));

                                   DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
                                   concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);

                            }

                            if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
                            {
                                   btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
                                   //todo: pass camera for some culling                    
                                   btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
                                   btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
                                   //DebugDrawcallback drawCallback;
                                   DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
                                   convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
                            }


                            if (shape->isPolyhedral())
                            {
                                   btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;

                                   int i;
                                   for (i=0;i<polyshape->getNumEdges();i++)
                                   {
                                          btPoint3 a,b;
                                          polyshape->getEdge(i,a,b);
                                          btVector3 wa = worldTransform * a;
                                          btVector3 wb = worldTransform * b;
                                          getDebugDrawer()->drawLine(wa,wb,color);

                                   }

                                   
                            }
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btDiscreteDynamicsWorld::debugDrawSphere ( btScalar  radius,
const btTransform transform,
const btVector3 color 
) [protected]

Definition at line 781 of file btDiscreteDynamicsWorld.cpp.

{
       btVector3 start = transform.getOrigin();

       const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0);
       const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0);
       const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius);

       // XY 
       getDebugDrawer()->drawLine(start-xoffs, start+yoffs, color);
       getDebugDrawer()->drawLine(start+yoffs, start+xoffs, color);
       getDebugDrawer()->drawLine(start+xoffs, start-yoffs, color);
       getDebugDrawer()->drawLine(start-yoffs, start-xoffs, color);

       // XZ
       getDebugDrawer()->drawLine(start-xoffs, start+zoffs, color);
       getDebugDrawer()->drawLine(start+zoffs, start+xoffs, color);
       getDebugDrawer()->drawLine(start+xoffs, start-zoffs, color);
       getDebugDrawer()->drawLine(start-zoffs, start-xoffs, color);

       // YZ
       getDebugDrawer()->drawLine(start-yoffs, start+zoffs, color);
       getDebugDrawer()->drawLine(start+zoffs, start+yoffs, color);
       getDebugDrawer()->drawLine(start+yoffs, start-zoffs, color);
       getDebugDrawer()->drawLine(start-zoffs, start-yoffs, color);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements btDynamicsWorld.

Definition at line 126 of file btDiscreteDynamicsWorld.cpp.

{
       if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb))
       {
              int i;

              //todo: iterate over awake simulation islands!
              for (  i=0;i<m_collisionObjects.size();i++)
              {
                     btCollisionObject* colObj = m_collisionObjects[i];
                     if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
                     {
                            btVector3 color(btScalar(255.),btScalar(255.),btScalar(255.));
                            switch(colObj->getActivationState())
                            {
                            case  ACTIVE_TAG:
                                   color = btVector3(btScalar(255.),btScalar(255.),btScalar(255.)); break;
                            case ISLAND_SLEEPING:
                                   color =  btVector3(btScalar(0.),btScalar(255.),btScalar(0.));break;
                            case WANTS_DEACTIVATION:
                                   color = btVector3(btScalar(0.),btScalar(255.),btScalar(255.));break;
                            case DISABLE_DEACTIVATION:
                                   color = btVector3(btScalar(255.),btScalar(0.),btScalar(0.));break;
                            case DISABLE_SIMULATION:
                                   color = btVector3(btScalar(255.),btScalar(255.),btScalar(0.));break;
                            default:
                                   {
                                          color = btVector3(btScalar(255.),btScalar(0.),btScalar(0.));
                                   }
                            };

                            debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
                     }
                     if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
                     {
                            btPoint3 minAabb,maxAabb;
                            btVector3 colorvec(1,0,0);
                            colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
                            m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
                     }

              }
       
              for (  i=0;i<this->m_vehicles.size();i++)
              {
                     for (int v=0;v<m_vehicles[i]->getNumWheels();v++)
                     {
                            btVector3 wheelColor(0,255,255);
                            if (m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_isInContact)
                            {
                                   wheelColor.setValue(0,0,255);
                            } else
                            {
                                   wheelColor.setValue(255,0,255);
                            }
              
                            btVector3 wheelPosWS = m_vehicles[i]->getWheelInfo(v).m_worldTransform.getOrigin();

                            btVector3 axle = btVector3( 
                                   m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[0][m_vehicles[i]->getRightAxis()],
                                   m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[1][m_vehicles[i]->getRightAxis()],
                                   m_vehicles[i]->getWheelInfo(v).m_worldTransform.getBasis()[2][m_vehicles[i]->getRightAxis()]);


                            //m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_wheelAxleWS
                            //debug wheels (cylinders)
                            m_debugDrawer->drawLine(wheelPosWS,wheelPosWS+axle,wheelColor);
                            m_debugDrawer->drawLine(wheelPosWS,m_vehicles[i]->getWheelInfo(v).m_raycastInfo.m_contactPointWS,wheelColor);

                     }
              }
       }
}

Here is the call graph for this function:

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;
       }

Definition at line 114 of file btDiscreteDynamicsWorld.h.

       {
              return this;
       }

Here is the caller graph for this function:

Reimplemented from btDynamicsWorld.

Definition at line 1016 of file btDiscreteDynamicsWorld.cpp.

{
       return m_constraints[index];
}
const btTypedConstraint * btDiscreteDynamicsWorld::getConstraint ( int  index) const [virtual]

Reimplemented from btDynamicsWorld.

Definition at line 1020 of file btDiscreteDynamicsWorld.cpp.

{
       return m_constraints[index];
}

Implements btDynamicsWorld.

Definition at line 1006 of file btDiscreteDynamicsWorld.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 397 of file btDiscreteDynamicsWorld.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:

Reimplemented from btDynamicsWorld.

Definition at line 1012 of file btDiscreteDynamicsWorld.cpp.

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file btCollisionWorld.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 104 of file btDiscreteDynamicsWorld.h.

       {
              return m_islandManager;
       }

Here is the caller graph for this function:

Definition at line 109 of file btDiscreteDynamicsWorld.h.

       {
              return m_islandManager;
       }

Definition at line 143 of file btDiscreteDynamicsWorld.h.

       {
              return m_solverInfo;
       }

Here is the caller graph for this function:

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

Implements btDynamicsWorld.

Reimplemented in btContinuousDynamicsWorld.

Definition at line 148 of file btDiscreteDynamicsWorld.h.

Definition at line 685 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("integrateTransforms");
       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->isStaticOrKinematicObject()))
                     {
                            body->predictIntegratedTransform(timeStep, predictedTrans);
                            body->proceedToTransform( predictedTrans);
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btDiscreteDynamicsWorld::internalSingleStepSimulation ( btScalar  timeStep) [protected, virtual]

apply gravity, predict motion

perform collision detection

solve contact and other joint constraints

CallbackTriggers();

integrate transforms

update vehicle simulation

Reimplemented in btContinuousDynamicsWorld.

Definition at line 340 of file btDiscreteDynamicsWorld.cpp.

{
       
       BT_PROFILE("internalSingleStepSimulation");

       predictUnconstraintMotion(timeStep);

       btDispatcherInfo& dispatchInfo = getDispatchInfo();

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

       performDiscreteCollisionDetection();

       calculateSimulationIslands();

       
       getSolverInfo().m_timeStep = timeStep;
       


       solveConstraints(getSolverInfo());
       

       integrateTransforms(timeStep);

       updateVehicles(timeStep);


       updateActivationState( timeStep );

       if(0 != m_internalTickCallback) {
              (*m_internalTickCallback)(this, timeStep);
       }      
}

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:

void btDiscreteDynamicsWorld::predictUnconstraintMotion ( btScalar  timeStep) [protected, virtual]

Definition at line 706 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("predictUnconstraintMotion");
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                     if (!body->isStaticOrKinematicObject())
                     {
                            if (body->isActive())
                            {
                                   body->integrateVelocities( timeStep);
                                   //damping
                                   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:

Reimplemented from btDynamicsWorld.

Definition at line 491 of file btDiscreteDynamicsWorld.cpp.

{
       m_constraints.remove(constraint);
       constraint->getRigidBodyA().removeConstraintRef(constraint);
       constraint->getRigidBodyB().removeConstraintRef(constraint);
}

Here is the call graph for this function:

Implements btDynamicsWorld.

Definition at line 403 of file btDiscreteDynamicsWorld.cpp.

Here is the call graph for this function:

Reimplemented from btDynamicsWorld.

Definition at line 503 of file btDiscreteDynamicsWorld.cpp.

{
       m_vehicles.remove(vehicle);
}

Here is the call graph for this function:

void btDiscreteDynamicsWorld::saveKinematicState ( btScalar  timeStep) [protected]

Definition at line 104 of file btDiscreteDynamicsWorld.cpp.

{

       for (int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              btRigidBody* body = btRigidBody::upcast(colObj);
              if (body)
              {
                            btTransform predictedTrans;
                            if (body->getActivationState() != ISLAND_SLEEPING)
                            {
                                   if (body->isKinematicObject())
                                   {
                                          //to calculate velocities next frame
                                          body->saveKinematicState(timeStep);
                                   }
                            }
              }
       }
}

Here is the call graph for this function:

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 btDiscreteDynamicsWorld::setGravity ( const btVector3 gravity) [virtual]

Implements btDynamicsWorld.

Definition at line 383 of file btDiscreteDynamicsWorld.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.

we don't split islands, so all constraints/contact manifolds/bodies are passed into the solver regardless the island id

only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive

solve all the constraints for this island

Definition at line 536 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("solveConstraints");
       
       struct InplaceSolverIslandCallback : public btSimulationIslandManager::IslandCallback
       {

              btContactSolverInfo& m_solverInfo;
              btConstraintSolver*         m_solver;
              btTypedConstraint**         m_sortedConstraints;
              int                                       m_numConstraints;
              btIDebugDraw*               m_debugDrawer;
              btStackAlloc*               m_stackAlloc;
              btDispatcher*               m_dispatcher;

              InplaceSolverIslandCallback(
                     btContactSolverInfo& solverInfo,
                     btConstraintSolver*  solver,
                     btTypedConstraint** sortedConstraints,
                     int    numConstraints,
                     btIDebugDraw* debugDrawer,
                     btStackAlloc*               stackAlloc,
                     btDispatcher* dispatcher)
                     :m_solverInfo(solverInfo),
                     m_solver(solver),
                     m_sortedConstraints(sortedConstraints),
                     m_numConstraints(numConstraints),
                     m_debugDrawer(debugDrawer),
                     m_stackAlloc(stackAlloc),
                     m_dispatcher(dispatcher)
              {

              }

              InplaceSolverIslandCallback& operator=(InplaceSolverIslandCallback& other)
              {
                     btAssert(0);
                     (void)other;
                     return *this;
              }
              virtual       void   ProcessIsland(btCollisionObject** bodies,int numBodies,btPersistentManifold**       manifolds,int numManifolds, int islandId)
              {
                     if (islandId<0)
                     {
                            m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,&m_sortedConstraints[0],m_numConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher);
                     } else
                     {
                                   //also add all non-contact constraints/joints for this island
                            btTypedConstraint** startConstraint = 0;
                            int numCurConstraints = 0;
                            int i;
                            
                            //find the first constraint for this island
                            for (i=0;i<m_numConstraints;i++)
                            {
                                   if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId)
                                   {
                                          startConstraint = &m_sortedConstraints[i];
                                          break;
                                   }
                            }
                            //count the number of constraints in this island
                            for (;i<m_numConstraints;i++)
                            {
                                   if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId)
                                   {
                                          numCurConstraints++;
                                   }
                            }

                            if (numManifolds + numCurConstraints)
                            {
                                   m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher);
                            }
              
                     }
              }

       };

       //sorted version of all btTypedConstraint, based on islandId
       btAlignedObjectArray<btTypedConstraint*>  sortedConstraints;
       sortedConstraints.resize( m_constraints.size());
       int i; 
       for (i=0;i<getNumConstraints();i++)
       {
              sortedConstraints[i] = m_constraints[i];
       }

//     assert(0);
              
       

       sortedConstraints.quickSort(btSortConstraintOnIslandPredicate());
       
       btTypedConstraint** constraintsPtr = getNumConstraints() ? &sortedConstraints[0] : 0;
       
       InplaceSolverIslandCallback solverCallback(      solverInfo,   m_constraintSolver, constraintsPtr,sortedConstraints.size(),   m_debugDrawer,m_stackAlloc,m_dispatcher1);
       
       m_constraintSolver->prepareSolve(getCollisionWorld()->getNumCollisionObjects(), getCollisionWorld()->getDispatcher()->getNumManifolds());
       
       m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld()->getCollisionObjectArray(),&solverCallback);

       m_constraintSolver->allSolved(solverInfo, m_debugDrawer, m_stackAlloc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btDiscreteDynamicsWorld::startProfiling ( btScalar  timeStep) [protected]

Definition at line 731 of file btDiscreteDynamicsWorld.cpp.

{
       (void)timeStep;

#ifndef BT_NO_PROFILE
       CProfileManager::Reset();
#endif //BT_NO_PROFILE

}

Here is the call graph for this function:

Here is the caller graph for this function:

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

if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's

Implements btDynamicsWorld.

Definition at line 273 of file btDiscreteDynamicsWorld.cpp.

{
       startProfiling(timeStep);

       BT_PROFILE("stepSimulation");

       int numSimulationSubSteps = 0;

       if (maxSubSteps)
       {
              //fixed timestep with interpolation
              m_localTime += timeStep;
              if (m_localTime >= fixedTimeStep)
              {
                     numSimulationSubSteps = int( m_localTime / fixedTimeStep);
                     m_localTime -= numSimulationSubSteps * fixedTimeStep;
              }
       } else
       {
              //variable timestep
              fixedTimeStep = timeStep;
              m_localTime = timeStep;
              if (btFuzzyZero(timeStep))
              {
                     numSimulationSubSteps = 0;
                     maxSubSteps = 0;
              } else
              {
                     numSimulationSubSteps = 1;
                     maxSubSteps = 1;
              }
       }

       //process some debugging flags
       if (getDebugDrawer())
       {
              gDisableDeactivation = (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_NoDeactivation) != 0;
       }
       if (numSimulationSubSteps)
       {

              saveKinematicState(fixedTimeStep);

              applyGravity();

              //clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
              int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps;

              for (int i=0;i<clampedSimulationSteps;i++)
              {
                     internalSingleStepSimulation(fixedTimeStep);
                     synchronizeMotionStates();
              }

       } 

       synchronizeMotionStates();

       clearForces();

#ifndef BT_NO_PROFILE
       CProfileManager::Increment_Frame_Counter();
#endif //BT_NO_PROFILE
       
       return numSimulationSubSteps;
}

Here is the call graph for this function:

Definition at line 233 of file btDiscreteDynamicsWorld.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() && !body->isStaticOrKinematicObject())
                     {
                            //we need to call the update at least once, even for sleeping objects
                            //otherwise the 'graphics' transform never updates properly
                            //so todo: add 'dirty' flag
                            //if (body->getActivationState() != ISLAND_SLEEPING)
                            {
                                   btTransform interpolatedTransform;
                                   btTransformUtil::integrateTransform(body->getInterpolationWorldTransform(),
                                          body->getInterpolationLinearVelocity(),body->getInterpolationAngularVelocity(),m_localTime,interpolatedTransform);
                                   body->getMotionState()->setWorldTransform(interpolatedTransform);
                            }
                     }
              }
       }

       if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
       {
              for ( int i=0;i<this->m_vehicles.size();i++)
              {
                     for (int v=0;v<m_vehicles[i]->getNumWheels();v++)
                     {
                            //synchronize the wheels with the (interpolated) chassis worldtransform
                            m_vehicles[i]->updateWheelTransform(v,true);
                     }
              }
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionWorld::updateAabbs ( ) [virtual, inherited]

Reimplemented in btSimpleDynamicsWorld.

Definition at line 116 of file btCollisionWorld.cpp.

{
       BT_PROFILE("updateAabbs");
       
       btTransform predictedTrans;
       for ( int i=0;i<m_collisionObjects.size();i++)
       {
              btCollisionObject* colObj = m_collisionObjects[i];
              
              //only update aabb of active objects
              if (colObj->isActive())
              {
                     btPoint3 minAabb,maxAabb;
                     colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
                     btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;

                     //moving objects should be moderately sized, probably something wrong if not
                     if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < btScalar(1e12)))
                     {
                            bp->setAabb(colObj->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1);
                     } else
                     {
                            //something went wrong, investigate
                            //this assert is unwanted in 3D modelers (danger of loosing work)
                            colObj->setActivationState(DISABLE_SIMULATION);
                            
                            static bool reportMe = true;
                            if (reportMe && m_debugDrawer)
                            {
                                   reportMe = false;
                                   m_debugDrawer->reportErrorWarning("Overflow in AABB, object removed from simulation");
                                   m_debugDrawer->reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n");
                                   m_debugDrawer->reportErrorWarning("Please include above information, your Platform, version of OS.\n");
                                   m_debugDrawer->reportErrorWarning("Thanks.\n");
                            }
                     }
              }
       }
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 450 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("updateActivationState");

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

                     if (body->wantsSleeping())
                     {
                            if (body->isStaticOrKinematicObject())
                            {
                                   body->setActivationState(ISLAND_SLEEPING);
                            } else
                            {
                                   if (body->getActivationState() == ACTIVE_TAG)
                                          body->setActivationState( WANTS_DEACTIVATION );
                            }
                     } else
                     {
                            if (body->getActivationState() != DISABLE_DEACTIVATION)
                                   body->setActivationState( ACTIVE_TAG );
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btDiscreteDynamicsWorld::updateVehicles ( btScalar  timeStep) [protected]

Definition at line 439 of file btDiscreteDynamicsWorld.cpp.

{
       BT_PROFILE("updateVehicles");
       
       for ( int i=0;i<m_vehicles.size();i++)
       {
              btRaycastVehicle* vehicle = m_vehicles[i];
              vehicle->updateVehicle( timeStep);
       }
}

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 43 of file btDiscreteDynamicsWorld.h.

Definition at line 39 of file btDiscreteDynamicsWorld.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 46 of file btDiscreteDynamicsWorld.h.

Definition at line 90 of file btDynamicsWorld.h.

Definition at line 41 of file btDiscreteDynamicsWorld.h.

Definition at line 49 of file btDiscreteDynamicsWorld.h.

Definition at line 53 of file btDiscreteDynamicsWorld.h.

Definition at line 52 of file btDiscreteDynamicsWorld.h.

Definition at line 60 of file btDiscreteDynamicsWorld.h.

Definition at line 55 of file btDiscreteDynamicsWorld.h.

Definition at line 91 of file btCollisionWorld.h.

Definition at line 58 of file btDiscreteDynamicsWorld.h.


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