Boxes colliding even though they arn't touching

andrewaah
Posts: 6
Joined: Tue Sep 25, 2007 1:56 pm

Boxes colliding even though they arn't touching

Post by andrewaah »

When I have two boxes [each sized at (3,5,1)], they collide even though they arn't touching, its as if the boxes are bigger than what I have set them too, they also bounce weird when they hit the ground plane, as if the ground were made of water and the boxes were floating. And most of the time the boxes will come to rest hovering above the ground, but occasionally the will sit on it flat.

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
Also I've ruled out the problem being my rendering.

Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Boxes colliding even though they arn't touching

Post by Erwin Coumans »

It is hard to tell what the problem is, perhaps this is the typical collision margin (0.04)? You could try to make the physical box a bit smaller then the graphical one (just like the demos do, subtract the collision margin).


Bullet 2.67 will get improved COLLADA (debug) snapshot support, so you will be able to send us a .dea file to check for problems. However, there is no 'plane' support yet I think, so we should add that to analyse your issue,

hope this helps,
Erwin
andrewaah
Posts: 6
Joined: Tue Sep 25, 2007 1:56 pm

Re: Boxes colliding even though they arn't touching

Post by andrewaah »

I fix the problems, they were all my fault.
:oops:
thanks