I'm new to using bullet. While trying to use it I can't get gravity to apply to my avatar.
The poor guy just hangs there suspended in mid air.
Here's a screen capture of the world with debug draw turned on: I'm using C++ with mingw-tdm. I use ogre and the btOgre wrapper to display the world.
Here's how I initialize bullet
Code: Select all
   collisionConfiguration = new btDefaultCollisionConfiguration();
   CollisionDispatcher = new btCollisionDispatcher( collisionConfiguration );
   /// btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
   overlappingPairCache = new btDbvtBroadphase();
   /// the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
   solver = new btSequentialImpulseConstraintSolver;
   dynamicsWorld = new btDiscreteDynamicsWorld( CollisionDispatcher, overlappingPairCache, solver, collisionConfiguration );
   dynamicsWorld->setGravity( btVector3( 0, -10, 0 ) );
   mDebugDrawer = new OgreDebugDrawer( mSceneMgr );
   mDebugDrawer->setDebugMode( btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawContactPoints ); //
   dynamicsWorld->setDebugDrawer( mDebugDrawer );
Here's my initialization for the avatar:
Code: Select all
      BtOgre::AnimatedMeshToShapeConverter* anConvert = new BtOgre::AnimatedMeshToShapeConverter( Entity, scale );
      Shape = anConvert->createTrimesh();
      //Calculate inertia.
      btScalar mass = 1.0f;
      btVector3 inertia;
      Shape->calculateLocalInertia( mass, inertia );
      // motion state tracks movement caused by physics
      State = new BtOgre::RigidBodyState( Node );
      Body = new btRigidBody( mass, State, Shape, inertia );
      Body->setCollisionFlags( Body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
      Body->setActivationState( DISABLE_DEACTIVATION );
      // reset interpolation between frames
      Body->setInterpolationWorldTransform( Body->getWorldTransform() );
      Body->setInterpolationLinearVelocity( btVector3( 0, 0, 0 ) );
      Body->setInterpolationAngularVelocity( btVector3( 0, 0, 0 ) );
I think debug draw shows I have the visible mesh and the physics mesh overlaid correctly.
Once the program is fully initialized I set his initial position like this:
Code: Select all
      btTransform xf;
      xf.setIdentity();
      xf.setOrigin( btVector3( x, y, z ) );
      Body->getMotionState()->setWorldTransform( xf );
      // reset interpolation between frames
      Body->setInterpolationWorldTransform( Body->getWorldTransform() );
      Body->setInterpolationLinearVelocity( btVector3( 0, 0, 0 ) );
      Body->setInterpolationAngularVelocity( btVector3( 0, 0, 0 ) );
it does the physics update like this:
Code: Select all
               struct timeval time;
               gettimeofday( &time, 0 );
               float TimeStep = ( time.tv_sec - LastPhysicsUpdateTime.tv_sec )
                  + float( time.tv_usec - LastPhysicsUpdateTime.tv_usec ) / 1000000.0f
                  ;
               // It's important that timeStep is always less than maxSubSteps*fixedTimeStep, otherwise you are losing time.
               int maxSubSteps = (int)( 60 * TimeStep ) + 1;
               dynamicsWorld->stepSimulation( TimeStep, maxSubSteps );
               LastPhysicsUpdateTime = time;
I've hooked up a button to try to debug motion. That button does this:
Code: Select all
Body->applyCentralImpulse( btVector3( 0.0f, 0.0f, 200.0f ) );
What does the red for the avatar indicate?
Any suggestions?
Thanks