Collision questions.

vidjogamer
Posts: 13
Joined: Thu Apr 29, 2010 11:59 pm

Collision questions.

Post by vidjogamer »

I read on the wiki that this is the best way to do collisions:

Code: Select all

int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
	btPersistentManifold* contactManifold =  dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
	//btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
	//btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
}
Why does getBody0() and getBody1() return a void* as opposed to a btRigidBody?

Why does the wiki say this is the best way to do collisions?

Can there be more than 1 manifold per collision pair?
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

Why does getBody0() and getBody1() return a void* as opposed to a btRigidBody?
I don't know the reason for sure. If you check the Header file of btPersistentManifold:

Code: Select all

void* m_body0;
void* m_body1;
These two pointers are initialized as void pointer, so in the getBody0() and getBody1(), they should return a void pointer. void* will allow any collision class, including GhostObject, SoftObject and RigidObject. But definitely you can point these two to btRigidBody. Just use the commented line in your pasted code:

Code: Select all

btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
Why does the wiki say this is the best way to do collisions?
I suppose there are two reasons. First is that it is fast, you don't need to do the collision detection by yourself. Second is that it is accurate, you won't miss a collision when iterating through all the collision pairs.
Can there be more than 1 manifold per collision pair?
Definitely, there can be more than 1 manifold inside per collision pair. and that's this loop for:

Code: Select all

for (int i=0;i<numManifolds;i++)
{
.........
}
vidjogamer
Posts: 13
Joined: Thu Apr 29, 2010 11:59 pm

Re: Collision questions.

Post by vidjogamer »

Thanks Dr.Shepherd!

So if I was only interested if two objects collided once, whats is the proposed way of ignoring the extra manifolds?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Collision questions.

Post by Mako_energy02 »

So if I was only interested if two objects collided once, whats is the proposed way of ignoring the extra manifolds?
Sorry I don't have anything really meaninful to contribute to this discussion currently, but I wanted to express my interest in this as well. Currently manifolds seem like a disgusting, counter-intuitive mess(not unlike bullet's soft bodies).

I've noticed in some simulations that have <15 objects having well over 200 contact manifolds. Even if each object was colliding with each other object (which they aren't...not even with AABB's) this shouldn't be possible so obviously duplicate manifolds are occurring, and en-masse. Even worse is that I have no idea what rationale the engine uses to determine if duplicates are necessary so for now I'm just reporting the first ones that show up for a given pair, which could mean important information is missed out on.

So yeah...once again I'd like to know of any methods others have used when working with manifolds to try and bring some order to this chaos.

Edit: @ vidjogamer
After I initially posted I realized I kinda do have a way of addressing it which is what you are getting at. I do not recommend this way (which is why I posted) but currently I have a class that stores a pair of objects and another class that stores collision data. When a manifold is made I make the collision data class and put it in a map with the object pair as the key. When another manifold is made I check to see if the pair is in the map already and skip it if it is. Again, not the best way to do it since you could be missing out on a lot of information.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

vidjogamer wrote:Thanks Dr.Shepherd!

So if I was only interested if two objects collided once, whats is the proposed way of ignoring the extra manifolds?
If you are specifically focusing on two objects, or one objects with some other objects, you may look into the btGhostObject. Collisionflags would be helpful as well.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

Mako_energy02 wrote: After I initially posted I realized I kinda do have a way of addressing it which is what you are getting at. I do not recommend this way (which is why I posted) but currently I have a class that stores a pair of objects and another class that stores collision data. When a manifold is made I make the collision data class and put it in a map with the object pair as the key. When another manifold is made I check to see if the pair is in the map already and skip it if it is. Again, not the best way to do it since you could be missing out on a lot of information.
Does it mean that you only keep 1 manifold for per collision pair?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Collision questions.

Post by Mako_energy02 »

Dr.Shepherd wrote:Does it mean that you only keep 1 manifold for per collision pair?
Yes and no. I have my own collision reporting system I've built on top of bullet. The internal manifolds are preserved, I don't mess around with that because well...that wouldn't work. But I only create a new collision "report" class instance if another one of the same pair doesn't exist. So my personal collision class, yes...they are unique to each pair.

I'm actually having an array of issues with this currently but I don't want to hyjack this thread. I may make my own post going into more detail soon if I can't sort this stuff out.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

Mako_energy02 wrote:
Dr.Shepherd wrote:Does it mean that you only keep 1 manifold for per collision pair?
Yes and no. I have my own collision reporting system I've built on top of bullet. The internal manifolds are preserved, I don't mess around with that because well...that wouldn't work. But I only create a new collision "report" class instance if another one of the same pair doesn't exist. So my personal collision class, yes...they are unique to each pair.

I'm actually having an array of issues with this currently but I don't want to hyjack this thread. I may make my own post going into more detail soon if I can't sort this stuff out.
So you keep all the collision points in the same manifold for per pair ? That's another solution. In my view, collision manifold provides advantage in keeping the points clustered according to their position. To be honest, this question should be left to someone who wrote this algorithm.

Cheers !
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Collision questions.

Post by Flix »

vidjogamer wrote:Can there be more than 1 manifold per collision pair?
As far as I know there can be as many as 4 contact points per contact between two collision shapes, but if one of the bodies is compound shaped, its (leaf) child shapes are used for collision detection, and so there can be more than one manifold per collision pair (and there can be more than 4 contact points for a collision between the same two bodies). I don't know if the same object pair can be present more than once in other cases (when none of them is compound shaped), and it would be interesting to know it.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

Flix wrote:As far as I know there can be as many as 4 contact points per contact between two collision shapes
Just to be check if my previous understanding is the same as you. A collision pair can have several collision manifold, while each manifold can only contain maximum 4 points.

If it is wrong, could anyone point it out? Cheers !
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Collision questions.

Post by Flix »

Code: Select all

   const int numManifolds = m_dynamicsWorld->getDispatcher()->getNumManifolds();
   for (int i=0;i<numManifolds;i++)
   {
   	  btPersistentManifold* contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
          
      btCollisionObject* objA = static_cast <btCollisionObject*> (contactManifold->getBody0());
      btCollisionObject* objB = static_cast <btCollisionObject*> (contactManifold->getBody1());    

      const int totContacts = contactManifold->getNumContacts();

      	for (int j=0;j<totContacts;j++)	{
        	btManifoldPoint& pt = contactManifold->getContactPoint(j);
                [...]  
      }
    }
Dr.Shepherd wrote:Just to be check if my previous understanding is the same as you. A collision pair can have several collision manifold, while each manifold can only contain maximum 4 points.
Yes, but I wanted to understand in which cases a collision pair (or, better, different collision pairs) with the same two collision objects can appear more than once in the contact manifolds (can it happen only if at least one of them is compound shaped?). Have you understood what I mean? This information can be useful to optimize contact point reduction systems.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Collision questions.

Post by Dr.Shepherd »

Flix wrote:Yes, but I wanted to understand in which cases a collision pair (or, better, different collision pairs) with the same two collision objects can appear more than once in the contact manifolds (can it happen only if at least one of them is compound shaped?). Have you understood what I mean? This information can be useful to optimize contact point reduction systems.
I think I understand your question, but I don't know the answer (Because I didn't try the compound shape, all the time I am using linked objects)

Search the forum if you want to get the answer, perhaps someone already discussed it before. Sorry I didn't provide much help.

Cheers