Child Collision Filters

duser
Posts: 16
Joined: Wed Feb 02, 2011 6:48 pm

Child Collision Filters

Post by duser »

Hi,

Is it possible to setup individual collision filters for child shapes in compound shapes?

for reference
RB = rigid body COM = compound shape CON = convex shape - = spaces
General hierarchy of objects:
L1)---------------------------RB
L2----------------------------COM
L3)------COM--------------COM-------COM----------COM
L4)-CON-CON-CON----CON-CON---CON-CON---CON-CON


What I am trying to do is setup different filters in L3 and / or L4. I have read through the forum looking for answers.
Some solutions I have found through the forum are:
- create my own broadphase filter callback
- create my own near callback
- inherit and override btCollisionDispatcher

The problems are that all of these only give me access to L1 / L2.
Is there a way to get to L3 / L4?
(usually with the callbacks, "getCollisionShape" returns the colliding shape, but with these callbacks, its only L1/L2)

Thanks


FYI - the purpose is to have rigid bodies that are composed of these compound collision shapes to be able to have there own collision filters. I have it all mapped out for each child shape (L3/L4), but can't find a way to know which ones are colliding. Also, the ability to setup rigidbodies with constraints is difficult to convert to with the current setup of the game at this time (not sure if this would solve the problem, if so and if it is the only option, this is what I'll do, but if it's possible, the child shapes is what I would like at the moment, please).

Example: I have a ship that has a bubble shield in its middle (not covering its whole body, just a hole in the middle). It is one of the collision shapes, the ship also has a shape in front of this shield and on the back. Some ship types should be able to pass through this shield, but all ships can not pass through the front and back shapes. Also, bullets should be able to shoot all 3 shapes.
(NOTE: this is not an ACTUAL example for the game, but similar and it explains what I am trying to get at, multi shapes and be able to filter collisions on a shape / shape basis, please pretend the bullets are objects and not using rays, I do know about rays, but I'm trying to filter collisions)

Diag of Example:

=================================================================

----------------___________
----________/--____|____--\________
--/--------------/-------------\-------------\
-/--------------|---------------|-------------\
|------1--------|-------2------|------3-------|
-\--------------|---------------|-------------/
--\_________|---------------|________/
----------------\__________/

1) collide with SHIP-TYPE-A, SHIP-TYPE-B, BULLETS
2) collide with SHIP-TYPE-B, BULLETS
3) collide with SHIP-TYPE-A, SHIP-TYPE-B, BULLETS

=================================================================
duser
Posts: 16
Joined: Wed Feb 02, 2011 6:48 pm

Re: Child Collision Filters

Post by duser »

Does anyone have any suggestions, ideas, or links to other posts on how to get access to the child shapes as they are being tested for collision?


Thank you
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Child Collision Filters

Post by Dr.Shepherd »

I think this would be very difficult to achieve, based on your current status. Because most of the calls, masks, filters are based on CollisionObjects, rather than CollisionShape.

I am not an expert, so just gave my personal suggestions.

1) You may try attatch a btGhostObject to your individual shape, which is under discussion between me and SIngular,
http://bulletphysics.org/Bullet/phpBB3/ ... php?t=7496
(Although I personally think it is unnecessary to attach a GhostObject to a RigidBody, but you can try attach the GhostObject to individual CollisionShape)

2) If your model is not complex, then there might be a way to figure out which part is colliding:

Code: Select all

typedef bool (*ContactAddedCallback)( btManifoldPoint& cp,  const btCollisionObject* colObj0, int partId0,  int index0, const btCollisionObject* colObj1, int partId1, int index1);
Set up this callback, if there is contact added, then check this Pair to see your Object is colObj0 or colObj1, get the local contact point from the btManifoldPoint & cp, this is easy, because class btManifoldPoint has got these two variables as its public Attributes:

Code: Select all

btVector3 	m_localPointA
btVector3 	m_localPointB
Then see if you can determine where this contact is on your object

Hope that I explain it clearly, regardless of it's useful or not.... oooops.....
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Child Collision Filters

Post by mi076 »

Code: Select all

typedef bool (*ContactAddedCallback)( btManifoldPoint& cp,  const btCollisionObject* colObj0, int partId0,  int index0, const btCollisionObject* colObj1, int partId1, int index1);
btw, partId (or index, don't remember just now) is ID of child shape if shape is compound shape... so it is easy to identify child shapes.. not sure about many levels of compound shapes... but you have to know what kind of shape is colliding, because for different shapes partId is different, for triangle shapes it is id of submesh,, and index is triangle index... most or all ray tests and collision tests return partId...
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Child Collision Filters

Post by Dr.Shepherd »

wow....That's great...I thought the PartId is the Index for two objects in the Collision Pair, rather than the index for the child object...

Could you help me find some hints on this ? I searched in the documentation and forum, but found nothing...

Cheers, man ! You have been helpful !
duser
Posts: 16
Joined: Wed Feb 02, 2011 6:48 pm

Re: Child Collision Filters

Post by duser »

Thank you for your advice Dr. Shepherd and mi076.

The callback is something I have looked at, but doesn't it get triggered when a contact pnt is added?
I was hoping to get the test before it is added so that I can ignore it.
With this function, can you remove contact points from the list?


Thanks again, I really appreciate the help.