Collision detection using bounding box as primitive shape

amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Collision detection using bounding box as primitive shape

Post by amrishkum »

Hi
I was trying to use the collision detection using bullet physics. I had some problems regarding that. I am a new to bullet physics.
I used the code from the demos for collision detection (App_CollisionInterfaceDemo). Please see the code below. Is this right way to check for two boxes collision? Also how do I know if the boxes collided? Is this the right method to check for collision detection using oriented bounding box or is there another method? Can anyone help me to get started on this? Also if some someone has a demo code for checking whether two objects collide or not, it would be greatly appreciated.

btCollisionObject objects[maxNumObjects];
btCollisionWorld* collisionWorld = 0;
btMatrix3x3 basisA;
basisA.setIdentity();

btMatrix3x3 basisB;
basisB.setIdentity();

objects[0].getWorldTransform().setBasis(basisA);
objects[1].getWorldTransform().setBasis(basisB);

btBoxShape* boxA = new btBoxShape(btVector3(1,1,1));
boxA->setMargin(0.f);

btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5));
boxB->setMargin(0.f);
objects[0].setCollisionShape(boxA);//&hullA;
objects[1].setCollisionShape(boxB);//&hullB;

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btVector3 worldAabbMin(-1000,-1000,-1000);
btVector3 worldAabbMax(1000,1000,1000);

btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);

//SimpleBroadphase is a brute force alternative, performing N^2 aabb overlap tests
//SimpleBroadphase* broadphase = new btSimpleBroadphase;

collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);



objects[0].getWorldTransform().setOrigin(btVector3(0.0f,3.f,0.f));

btQuaternion rotA(0.739f,-0.204f,0.587f,0.257f);
rotA.normalize();

objects[0].getWorldTransform().setRotation(rotA);

objects[1].getWorldTransform().setOrigin(btVector3(0.0f,4.248f,0.f));

collisionWorld->addCollisionObject(&objects[0]);
collisionWorld->addCollisionObject(&objects[1]);
collisionWorld->performDiscreteCollisionDetection();

btDrawingResult renderCallback;

collisionWorld->contactPairTest(&objects[0],&objects[1],renderCallback);


Thanks
Amrish Kumar
You do not have the required permissions to view the files attached to this post.
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: Collision detection using bounding box as primitive shap

Post by amrishkum »

Can anyone help??????????????
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: Collision detection using bounding box as primitive shap

Post by amrishkum »

Hi
I got some of the bounding box collision detection code working but it is not able to detect collision.

I am attaching the file in this regard. I made two boxes and using broad phase collision method.

Can anyone look and tell why btManifoldpt (contact points) are empty while in reality the boxes are hitting

Thanks
amrish Kumar
You do not have the required permissions to view the files attached to this post.
Ebon
Posts: 3
Joined: Thu Apr 12, 2012 11:54 pm

Re: Collision detection using bounding box as primitive shap

Post by Ebon »

It seems like you want to use bullet to check for collisions, then resolve the effects of the collision yourself? Instead of just adding some boxes and have them bounce around on their own. Have a look at the example here, it's two boxes colliding (text mode).

Of course, maybe you want to do something else and need to check for collisions. In which case I can't help. :D
You do not have the required permissions to view the files attached to this post.
en51nm
Posts: 8
Joined: Mon May 21, 2012 7:44 am

Re: Collision detection using bounding box as primitive shap

Post by en51nm »

I got your pm.

I ended up using Newton as opposed to Bullet physics as it seemed to be able to handle simple shapes more easily. I was also interested in just detecting the collision. My solution (with the problems I faced) is fairly well documented on Newtons forum in this thread:

http://newtondynamics.com/forum/viewtop ... f=9&t=7230

This is a video showing (except a rendering error) my final solution.

http://www.youtube.com/watch?v=eiaZBUgsQAQ

Hope this helps.