Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Aug 03, 2012 3:24 am 
Offline

Joined: Fri Aug 03, 2012 3:05 am
Posts: 1
I've been looking at bullet physics for quite a bit now, and I've recently decided to build an FPS that utilizes the API. I've been looking at the demo's and trying to put a prototype up that serves as an example for different game mechanics.

I've put up a demo app with static geometry and a basic sphere that moves around using WASD, that's all fair and simple but now I'm trying to fire projectiles from the sphere onto other objects. Projectiles in the game are handled in 2 ways. A sniper kind of weapon that does a raycast to determine if it hit an enemy. And all the other weapons will use sphere's as projectiles that move at slower speeds (not instant).

My problem is when shooting projectiles I would like to get more information on the object that it has collided with, when doing this:

Code:
const int manifoldCount(m_dispatcher->getNumManifolds());
   for(int loop = 0; loop < manifoldCount; loop++)
   {
      const btPersistentManifold *mf = m_dispatcher->getManifoldByIndexInternal(loop);
      const void *obja = mf->getBody0();
      const void *objb = mf->getBody1();

      if(obja == moveableBall || objb == moveableBall)
      {
      // This manifold deals with the btRigidBody we are looking for.
      // A manifold is a RB-RB pair containing a list of potential (predicted) contact points.
       const unsigned int numContacts(mf->getNumContacts());
         for(int check = 0; check < numContacts; check++)
         {
             const btManifoldPoint &pt(mf->getContactPoint(check));
             // do something here, in case you're interested.
         }
      }
   }


I can't really access what object types are colliding, is there any way to get more specific data on the objects that have collided?

For example I want to know when rockets collide with walls, characters, floor, etc. When rifle rounds collide with wall,characters...

Does anyone have a recommendation or any idea on how I could put this together?

Thank you very much,
Luis Lairet


Top
 Profile  
 
PostPosted: Mon Sep 24, 2012 11:55 pm 
Offline

Joined: Mon Sep 24, 2012 11:42 pm
Posts: 1
I'm not sure if this is a little late but what you need to do is use m_rigidBody->setUserPointer(void*), that pointer can point to any of your own classes. Have it point to a common base class of colliding objects(In my game, The common base class is GameObject, I just put m_rigidBody->setUserPointer(this) after i'd created the rigidBody info for the GameObject.

Then in your // do something here, in case you're interested bit
you need to call obja->getUserPointer() and cast it to your base class.

In mine it looks something like this:
m_numContacts = mp_manifold->getNumContacts();
for ( j=0; j < m_numContacts; j++)
{
btManifoldPoint& pt = mp_manifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
GameObject* go1 = static_cast<GameObject*>(mp_obA->getUserPointer());
GameObject* go2 = static_cast<GameObject*>(mp_obB->getUserPointer());
go1->BTCollided();
go2->BTCollided();
}
}

Hope this helps or at least helps someone else who's also struggling.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group