Detecting Specific child shape in CompoundShape Collision
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Detecting Specific child shape in CompoundShape Collision
In a combat flight sim I'm making, I obviously want the entire plane to be a rigid body, so it colliding with something / something colliding with it would behave properly. However, I also want to have regional hit detection, where shooting the tail will damage the tail, shooting the wing will damage the wing, etc. (similar to how FPS games differentiate between head, torso, and leg shots). Since the rigid body of the plane is already a collision object, what is the standard approach to do this with Bullet? If you use a btCompoundShape, will the contact manifold getBody0/getBody1 calls hold the individual child shape that collided, or just the parent compound shape?
Last edited by slavik262E on Mon Nov 08, 2010 5:39 pm, edited 1 time in total.
-
mi076
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: Regional Hit Detection
--------------------
Last edited by mi076 on Tue Nov 09, 2010 12:34 am, edited 1 time in total.
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Regional Hit Detection
Thank you very much for the help. I was starting to worry that nobody would ever get back to me.
-
gennoevus
- Posts: 39
- Joined: Sun Oct 10, 2010 4:39 am
Re: Regional Hit Detection
Thanks mi076, this is useful! I'm definitely going to dissect your code...
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Regional Hit Detection
Sorry to revive this thread so long, but I finally got a chance to review the sample code. From what I can understand of it (the complete lack of comments doesn't really help), the program gets an intersecting triangle form a ray cast. That's not really what I'm looking for.
Allow me to clarify. If two RigidBodies made of compound collision shpes collide, how can I get the specific child collision shape of each body that collided with the other? Is this possible?
Allow me to clarify. If two RigidBodies made of compound collision shpes collide, how can I get the specific child collision shape of each body that collided with the other? Is this possible?
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Detecting Specific child shape in CompoundShape Collisio
Another game developer suggested the solution of recursively checking if each collision shape in one of the compound shapes collides with the other compound shape. Is there a way to check if two collision shapes (not collision objects; I've found plenty of functions for that) with given transforms are colliding?
-
mi076
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: Detecting Specific child shape in CompoundShape Collisio
this is what u have asked about.... before you have changed the title of your post (was something about "regional hit detection")... i said you can also detect subparts, not only index... It is in fact not applicable now and am going to delete my post now...However, I also want to have regional hit detection, where shooting the tail will damage the tail, shooting the wing will damage the wing, etc.
Last edited by mi076 on Tue Nov 09, 2010 3:02 am, edited 1 time in total.
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Detecting Specific child shape in CompoundShape Collisio
I'm sorry. I should have been more clear. Your example was useful, just not what I was looking for.
-
mi076
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: Detecting Specific child shape in CompoundShape Collisio
No problem..I'm sorry. I should have been more clear. Your example was useful, just not what I was looking for.
For compound shapes the index returned by results/callbacks should be the index of child shape..
BTW, the custom ClosestRayResultCallback from the example does it. I have tested it just now. Looks like compound shape also has LocalShapeInfo, and if shape is compound - "index" is index of the child shape.
Here is another example, from ConvexDecompositionDemo, shows custom contact callback..
Code: Select all
///MyContactCallback is just an example to show how to get access to the child shape that collided
bool MyContactCallback (
btManifoldPoint& cp,
const btCollisionObject* colObj0,
int partId0,
int index0,
const btCollisionObject* colObj1,
int partId1,
int index1)
{
if (colObj0->getRootCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
{
btCompoundShape* compound = (btCompoundShape*)colObj0->getRootCollisionShape();
btCollisionShape* childShape;
childShape = compound->getChildShape(index0);
}
if (colObj1->getRootCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
{
btCompoundShape* compound = (btCompoundShape*)colObj1->getRootCollisionShape();
btCollisionShape* childShape;
childShape = compound->getChildShape(index1);
}
return true;
}
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Detecting Specific child shape in CompoundShape Collisio
Thanks! The example in the ConvexDecompositionDemo looks extremely useful, but I'm trying to figure out how it's used. Is gContactAddedCallback just a global variable that's automatically employed by Bullet? I see the extern in btManifoldResult.h. From what I can gather from the Bullet source, it's called when a collision pair is added, but then how would you determine when the pair is no longer colliding? I'm confused by how btManifoldResult is used. Also, what if the child of a compound shape is a compound shape? Will this method properly return the correct child shape of the child compound shape?
Thanks once again for all the help.
Could you elaborate on which callbacks these would be and how to set them up?For compound shapes the index returned by results/callbacks should be the index of child shape..
Thanks once again for all the help.
-
mi076
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: Detecting Specific child shape in CompoundShape Collisio
OK, "MyContactCallback" above is an example. SetCould you elaborate on which callbacks these would be and how to set them up?
Code: Select all
gContactAddedCallback = MyContactCallbackCode: Select all
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);Look into btCollisionWorld class reference, Demos.. choose what is better for your purpose,it's called when a collision pair is added, but then how would you determine when the pair is no longer colliding?
Just for example, look at contactPairTest / ContactResultCallback.
Code: Select all
void contactPairTest (btCollisionObject *colObjA, btCollisionObject *colObjB, ContactResultCallback &)And last, sometimes iterate over, for example, contact pairs may be not wrong too, it depends..
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Detecting Specific child shape in CompoundShape Collisio
I meant besides gContactAddedCallback, but ContactResultCallback looks very useful. Based on the information you've given, my procedure to generate a list of colliding collision shapes each frame would be to iterate through all contact manifolds, as suggested in the wiki, then do a contactPairTest on each pair to get the specific child shape that's colliding. Even though it performs redundant collision tests, I don't see another way to get the child shape that's involved in the collision. I'll also explore alternatively using gContactAddedCallback and gContactDestroyedCallback. Thanks for the patience and help.
-
Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Detecting Specific child shape in CompoundShape Collisio
The gContactAddedCallback provides the index of the child shape of a btCompoundShape.
See also the fracture demo work-in-progress, it has some code: http://code.google.com/p/bullet/issues/detail?id=90#c12
Thanks,
Erwin
See also the fracture demo work-in-progress, it has some code: http://code.google.com/p/bullet/issues/detail?id=90#c12
Thanks,
Erwin
-
slavik262E
- Posts: 11
- Joined: Mon Oct 18, 2010 5:47 pm
Re: Detecting Specific child shape in CompoundShape Collisio
Is there a reason gContactAddedCallback is a global variable and not the public member of a class?
Also, is there a reason why gContactDestroyedCallback doesn't pass a reference to the point, just like the other two functions?
Also, is there a reason why gContactDestroyedCallback doesn't pass a reference to the point, just like the other two functions?
-
almatea
- Posts: 29
- Joined: Mon Nov 02, 2009 10:15 am
Re: Detecting Specific child shape in CompoundShape Collisio
mi076 wrote: P.S. getRootCollisionShape() is not 100% clear for me, but is off-topic here...
for me too!
it is strange: if I use a getRootCollisionShape() inside my gContactAddedCallback function - all is ok; if i use a getCollisionShape() instead getRootCollisionShape() - my program have segmentation fault after first getChildShape() use.