I've been working on this for a couple of days and I cannot work out what is wrong, I've been checking mine against the BasicDemo, and I can't see where I am going wrong.
Heres my init code:
Code: Select all
btDynamicsWorld *bDynamicsWorld;
btDefaultCollisionConfiguration *bCollisionConfiguration;
btCollisionDispatcher *bDispatcher;
btBroadphaseInterface* bPairCache;
btConstraintSolver* bConstraintSolver;
bCollisionConfiguration = new btDefaultCollisionConfiguration();
bDispatcher = new btCollisionDispatcher(bCollisionConfiguration);
bPairCache = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
bConstraintSolver = new btSequentialImpulseConstraintSolver();
bDynamicsWorld = new btDiscreteDynamicsWorld(bDispatcher, bPairCache, bConstraintSolver, bCollisionConfiguration);
bDynamicsWorld->setGravity(btVector3(0,-10,0));
//ground, pretty much copying from the BasicDemo
btRigidBody *bGround;
{
btCollisionShape *shape = new btStaticPlaneShape(btVector3(0,1,0),50);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-50,0));
btDefaultMotionState* motionState = new btDefaultMotionState(groundTransform);
bGround = new btRigidBody(0,motionState,shape);
bDynamicsWorld->addRigidBody(bGround);
}
//box shape
btCollisionShape *boxShape;
float boxMass;
{
btVector3 boxHalfExtent(3,5,1);
boxShape = new btBoxShape(boxHalfExtent);
boxMass = boxHalfExtent.dot(boxHalfExtent);
}
//add boxes
//box 1
{
btVector3 localInertia;
boxShape->calculateLocalInertia(boxMass, localInertia);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,10,0));
btDefaultMotionState *motionState = new btDefaultMotionState(startTransform);
btRigidBody *bBody = new btRigidBody(boxMass, motionState,boxShape, localInertia);
bDynamicsWorld->addRigidBody(bBody);
}
//box 2
{
btVector3 localInertia;
boxShape->calculateLocalInertia(boxMass, localInertia);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,20,0));
btDefaultMotionState *motionState = new btDefaultMotionState(startTransform);
btRigidBody *bBody = new btRigidBody(boxMass, motionState,boxShape, localInertia);
bDynamicsWorld->addRigidBody(bBody);
}
and my loop code:
Code: Select all
bDynamicsWorld->stepSimulation(deltaTime); //deltaTime is in seconds ...i think its is similar to the BasicDemo
Thanks.