Collision detection with bullet

fish
Posts: 4
Joined: Sun Aug 12, 2007 8:10 pm

Collision detection with bullet

Post by fish »

Hi.
I'm new to bullet.

What I like to do:
I have a terrain which is a btBvhTriangleMeshShape in bullet I think.
Now I like to test multiple positions for a collision with that terrain.
This should be done with a box I can move around and give me the information if it's
colliding with that terrain.

My current code looks so:

Code: Select all

    btVector3 worldAabbMin(-10000,-10000,-10000);
    btVector3 worldAabbMax(10000,10000,10000);
    btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax);
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
    btCollisionWorld* world = new btCollisionWorld(dispatcher, broadphase, collisionConfiguration);

    // Terrain:
    btTriangleMesh* groundMesh = new btTriangleMesh(true, false);
    groundMesh->addTriangle(btVector3(0,0,0), btVector3(100,0,0), btVector3(0,0,100));
    btBvhTriangleMeshShape* groundMeshShape = new btBvhTriangleMeshShape(groundMesh, true, true);
    btCollisionObject* terrain = new btCollisionObject();
    terrain->setCollisionShape(groundMeshShape);
    world->addCollisionObject(terrain);

    // Test box:
    btBoxShape* boxShape = new btBoxShape(btVector3(1.f, 1.f, 1.f));
    btCollisionObject* box = new btCollisionObject();
    box->setCollisionShape(boxShape);
    world->addCollisionObject(box);


    // Setting positions:
    terrain->setWorldTransform(btTransform(btQuaternion(0,0,0,1), btVector3(0,0,0)));
    box->setWorldTransform(btTransform(btQuaternion(0,0,0,1), btVector3(100,0,100)));

    // Check for collisions
    world->performDiscreteCollisionDetection();

    // With this configuration this methods returns 1. But why?
    std::cout << world->getDispatcher()->getNumManifolds() << std::endl;
Can someone tell me why the sample puts out 1?
I think the scene should look something like that:

Code: Select all

*    []
***
*****
******
where * is the mesh and [] is the box (beautiful heh? 8) )

I really need a solution for this and I am near to become crazy...

Thanks
fish
Posts: 4
Joined: Sun Aug 12, 2007 8:10 pm

Re: Collision detection with bullet

Post by fish »

65 views and no answer?
Is something wrong with my question? I thought it shouldn't be that hard to find a solution.

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

Re: Collision detection with bullet

Post by Erwin Coumans »

Code: Select all

world->getDispatcher()->getNumManifolds();
This just returns the number of contact manifolds.

A contract manifold is generated between all _potential_ overlapping pairs. Each btPersistentManifold is a contact cache that can contain a maximum of 4 points, but it might be empty. So for each manifold, you need to check the number of actual contact points it contains.

See Bullet/Demos/CollisionInterfaceDemo how to do this:

Code: Select all

        int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
        for (i=0;i<numManifolds;i++)
        {
                btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);

                int numContacts = contactManifold->getNumContacts();
                for (int j=0;j<numContacts;j++)
                {
                        btManifoldPoint& pt = contactManifold->getContactPoint(j);
                }
        }
Hope this helps,
Erwin
fish
Posts: 4
Joined: Sun Aug 12, 2007 8:10 pm

Re: Collision detection with bullet

Post by fish »

hmm ok that was really simple.
thank you erwin.
xSilv
Posts: 4
Joined: Mon Nov 17, 2008 8:40 am

Re: Collision detection with bullet

Post by xSilv »

Hello,

I have got a similar question like fish. For my master paper i am trying to model an industrial process: Single Point Incremental Forming where the metal plate will be bend by an automatic robot arm.

Video real life: http://www.youtube.com/watch?v=d3aD98SiBXA
Video animated: http://www.youtube.com/watch?v=mPpqQnsdp6A

I am trying to do it with the bullet collision. First i need to know how do:
1. how do u decide the contact points? I suppose it works with the narrowphase collision?
2. i need to know where the points are stored in?
3. where are the parameters for deforming the mesh? Thus i want to alter the coordinates of the meshe of the plate. And give it a certain linear springcoefficient. So if i remove the tool, the plate will jump a bit backwards.

For step 3, can i use this? http://www.bulletphysics.com/mediawiki- ... tionStates

If there is anything unclear plz ask ^^