Adding bullet collisions

Published October 24, 2010
Advertisement
Bullet Collision


After reading the bullet manual, I only figured out I needed to add a callback at the Tick level. The problem with callbacks and C++ is they dont mix well. Anyway I added a static function to my main Bullet class which holds the Dynamics World, called lsTickCallback. Then I added the following to my constructor.

	dynamicsWorld = new btDiscreteDynamicsWorld( dispatcher, axis_sweep3, solver, collisionConfiguration );	dynamicsWorld->setGravity(btVector3(0,-10,0));    // NEW set callback    dynamicsWorld->setInternalTickCallback( &lsTickCallback, static_cast<void *>(this) );


Here is the full static function.

void lsBulletWorld::lsTickCallback( btDynamicsWorld *world, btScalar timeStep ){    lsBulletWorld *w = static_cast(world->getWorldUserInfo());    w->lsProcessCallback( timeStep );}


As you can see I pull the real class instance I need to call from the User defined pointer I set in the first listing. Once I have the pointer I call my function.

Now I just need to read in all the hit pairs from the cashe. Not to hard. Here's my full debug function.

void lsBulletWorld::lsProcessCallback( btScalar timeStep ){    // local instance callback     cout << scene->getName() << " : bullet world just ticked by " << timeStep << " seconds" << endl;        lsNode* obj_A;    lsNode* obj_B;        // get hits    int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();    for (int i=0;i    {        btPersistentManifold* contactManifold =  dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);        btCollisionObject* obA = static_cast(contactManifold->getBody0());        btCollisionObject* obB = static_cast(contactManifold->getBody1());                // Scene nodes        obj_A = (lsNode*)obA->getUserPointer();        obj_B = (lsNode*)obB->getUserPointer();        if( obj_A )            cout << "Node A : " << obj_A->getName() << endl;        if( obj_B )            cout << "Node B : " << obj_B->getName() << endl;                int numContacts = contactManifold->getNumContacts();        for (int j=0;j        {            btManifoldPoint& pt = contactManifold->getContactPoint(j);            if (pt.getDistance()<0.f)            {                const btVector3& ptA = pt.getPositionWorldOnA();                const btVector3& ptB = pt.getPositionWorldOnB();                const btVector3& normalOnB = pt.m_normalWorldOnB;                                cout << "Hit B: " << ptB.getX();                cout << ", " << ptB.getY();                cout << ", " << ptB.getZ();                cout << endl;                                cout << "Normal B: " << normalOnB.getX();                cout << ", " << normalOnB.getY();                cout << ", " << normalOnB.getZ();                cout << endl;                            }        }    }    }


I should explain how I set the UserPointer that I get from obj_A = (lsNode*)obA->getUserPointer();. When any bullet object is set to a lsNode in my scenes I automaticlly set the UserPointer to that node. So now its just an easy operation to tell the nodes what happened. Just keep in mind if your scene objects are deleted, you may not be able to access them. Call in the right order.
Previous Entry Background
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

vortxGE : Threads

2330 views

C++11 Threads

3033 views

My Business

2188 views

Still Alive

2017 views

vortxEDIT : video

2130 views

vortxGE : Update

5980 views

vortxEDIT : Save

1888 views
Advertisement