I'm trying to implement Bullet as the physics engine within my project, and I seem to have problems using it correctly:
I have a static object (ground) and a dynamic object (sphere).
I was following some tutorials/example codes and implemented the following:
Bullet initialization:
Code: Select all
mCollisionConfiguration = new btDefaultCollisionConfiguration();
mCollisionDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
btVector3 worldAabbMin(-150, -150, -150);
btVector3 worldAabbMax(150, 150, 150);
mWorldDimension = new btAxisSweep3(worldAabbMin,worldAabbMax);
mSolver = new btSequentialImpulseConstraintSolver;
mPhysicsWorld = new btDiscreteDynamicsWorld(mCollisionDispatcher, mWorldDimension, mSolver, mCollisionConfiguration);
if ( 0 == mPhysicsWorld )
{
std::string msg = "CGameSession::CGameSession: Error creating physics world";
MESSAGELOGGER.Log(msg);
throw std::exception(msg.c_str());
}
mPhysicsWorld->setGravity(btVector3(0, -9.81f, 0));
DEBUGLOGGER.Log("CGameSession::CGameSession: Successfully initialized physics");
Code: Select all
btRigidBody* CGameSession::CreateRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape)
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
shape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
btRigidBody* body = new btRigidBody(cInfo);
mPhysicsWorld->addRigidBody(body);
return body;
}
Code: Select all
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0, 0, 0));
mPlayingFieldGroundBodyShape = new btBoxShape(btVector3(groundSizeX, groundSizeY, groundSizeZ));
mPlayingFieldGroundBody = CreateRigidBody(mPlayingFieldMass, groundTransform, mPlayingFieldGroundBodyShape);
Code: Select all
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(mSphereStartPosX, mSphereStartPosY, mSphereStartPosZ));
mSphereBodyShape = new btSphereShape(mSphereRadius);
mSphereBody = CreateRigidBody(mSphereMass, transform, mSphereBodyShape);
Code: Select all
void UpdatePhysics(float ms) { mPhysicsWorld->stepSimulation(ms / 1000.0f , 60); }
mPlayingFieldMass is 0 and mSphereMass is 1.0f
What am I doing wrong?
Thanks a lot in advance for any help.
Greets,
Chris