title: Bullet Physics Simplest Collision Example
body: <p>I'm trying to use Bullet Physics for collision detection only. I don't need it to move any objects for me or handle rendering with callbacks. I just want to update object locations every frame and use it to tell me when I have collisions. To get the simplest example going, I'm trying to find collisions between objects with btBoxShape as their shape. Everything runs fine without crashes or apparent memory leaks, but I get no collisions so I must be making some mistakes somewhere. I'll try to keep this as brief as I can without leaving anything important out.</p>
  
  <p>Here's my world setup function:</p>
  
  <pre><code>collisionConfig      = new btDefaultCollisionConfiguration();
  dispatcher           = new btCollisionDispatcher(collisionConfig);
  overlappingPairCache = new btDbvtBroadphase();
  solver               = new btSequentialImpulseConstraintSolver;
  dynamicsWorld        = new btDiscreteDynamicsWorld(dispatcher, 
  overlappingPairCache, solver, collisionConfig);         
  
  dynamicsWorld-&gt;setGravity(btVector3(0.0f, -9.8f, 0.0f));
  </code></pre>
  
  <p>Right now I have player and enemy objects of the type btCollisionObject*. I'm setting them up like this:</p>
  
  <pre><code>mPlayerBox = new btBoxShape(btVector3(1,3,1));
  mPlayerObject = new btCollisionObject();
  mPlayerObject-&gt;setCollisionShape(mPlayerBox);
  btTransform playerWorld;
  playerWorld.setIdentity();
  //playerPos is a D3DXVECTOR3 that holds the camera position.
  playerWorld.setOrigin(btVector3(playerPos.x, playerPos.y, playerPos.z));
  mPlayerObject-&gt;setWorldTransform(playerWorld);
  mPlayerObject-&gt;forceActivationState(DISABLE_DEACTIVATION);//maybe not needed
  dynamicsWorld-&gt;addCollisionObject(mPlayerObject);
  </code></pre>
  
  <p>I do essentially the same thing with my enemy objects.</p>
  
  <p>Then every frame I update all my objects with something like this:</p>
  
  <pre><code>btTransform updatedWorld;
  updatedWorld.setIdentity();
  updatedWorld.setOrigin(btVector3(position.x, position.y, position.z));
  mPlayerObject-&gt;setWorldTransform(updatedWorld);
  
  //do the same for my enemies, and then...
  
  dynamicsWorld-&gt;performDiscreteCollisionDetection();
  //Also tried doing this with stepSimulation(deltaTime, 7), but nothing changed.
  //stepSimulation seems to only be for letting Bullet set world Transforms?
  
  //check collisions with player
  dynamicsWorld-&gt;contactTest(mPlayerObject, resultCallback);
  int numManifolds = dynamicsWorld-&gt;getDispatcher()-&gt;getNumManifolds();
  if(numManifolds &gt; 0)
  {
     //there's a collision, execute blah blah blah
  }
  </code></pre>
  
  <p>And finally, here's the structure that defines my result callback:</p>
  
  <pre><code>struct rCallBack : public btCollisionWorld::ContactResultCallback
  {
   btScalar rCallback::addSingleResult(btManifoldPoint&amp; cp, const btCollisionObject*
   colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1,
   int index1)
   {
     btVector3 ptA = cp.getPositionWorldOnA();
     btVector3 ptB = cp.getPositionWorldOnB();
     return 0;
   }
  }
  </code></pre>
  
  <p>I've looked at a lot of the demos, but they seem to mostly be leaving the movement up to Bullet, and since I'm moving characters at a set speed without any special physics when they collide, I had trouble adapting the examples into my application. The result callback actually came from this post on the forums: 
  <a href="http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6816" rel="noreferrer">http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6816</a>
  It's about using triangle meshes, but it seemed closest to what I was trying to implement.</p>
  
  <p>Anyway, if you read this far, thank you!! Any advice or links you could spare would be very much appreciated. </p>