Hi to All,
I have a model which consists of several linked and non-linked objects. What I want is for the physics engine to inform me as soon as it detects a collision between two specific objects. I also want the physicis engine to delete the two objects and replace them by a single object which will model the two joint objects. I know that I have to use :
gContactAddedCallback
gContactProcessedCallback
gContactDestroyedCallback
but can someone explain to me how I have to implement this in my model ?
thank you for you help
Question About Detection Collision !
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Question About Detection Collision !
This was discussed just recently:
http://www.bulletphysics.com/Bullet/php ... f=9&t=1943
Saliently, grep the Demos/ dir for gContactAddedCallback. The code can be as simple as:
and then, somewhere in your initialisation code...
And for each rigid body you create that you want callbacks on...
The "g" prefix is short for "global". Just make it point to your function of choice.
Hope that helps,
Gary (-;
http://www.bulletphysics.com/Bullet/php ... f=9&t=1943
Saliently, grep the Demos/ dir for gContactAddedCallback. The code can be as simple as:
Code: Select all
extern ContactAddedCallback gContactAddedCallback;
static bool TWContactAddedCallback(btManifoldPoint& cp,
const btCollisionObject* colObj0,int partId0,int index0,
const btCollisionObject* colObj1,int partId1,int index1) {
printf("There was a collision of some sort\n");
}
Code: Select all
gContactAddedCallback = TWContactAddedCallback;
Code: Select all
rigidBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
Hope that helps,
Gary (-;
-
- Posts: 40
- Joined: Sun Jan 27, 2008 2:55 pm
Re: Question About Detection Collision !
Hi to all,
Thanks you for your quick replay chunky,
I was able to implement the part of code that allows me to know when the collision was happened. Now my model informs me as soon as it detects a collision between two objects. What I want now is : how I have to do for that at each contact, I can have the identity of objects that collide.
Thank You very much
Youne
Thanks you for your quick replay chunky,
I was able to implement the part of code that allows me to know when the collision was happened. Now my model informs me as soon as it detects a collision between two objects. What I want now is : how I have to do for that at each contact, I can have the identity of objects that collide.
Thank You very much
Youne
-
- Posts: 145
- Joined: Tue Oct 30, 2007 9:23 pm
Re: Question About Detection Collision !
const btCollisionObject* colObj0 and const btCollisionObject* colObj1 are the two objects that collided.
You'll want to look up the btCollisionObject::{set,get}UserPointer functions.
Gary (-;
You'll want to look up the btCollisionObject::{set,get}UserPointer functions.
Gary (-;
-
- Posts: 40
- Joined: Sun Jan 27, 2008 2:55 pm
Re: Question About Detection Collision !
Hi to all
My model informs me as soon as it detects a collision between two objects. What I want now is : how I have to do for that at each contact, I can have the identity of objects that collide. I looked but at btCollisionObjet but I don't understand how can I go from btCollisionObjet to btRigidbody.
Thank You very much
Youne
My model informs me as soon as it detects a collision between two objects. What I want now is : how I have to do for that at each contact, I can have the identity of objects that collide. I looked but at btCollisionObjet but I don't understand how can I go from btCollisionObjet to btRigidbody.
Thank You very much
Youne
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: Question About Detection Collision !
You can do this to check if it's a rigidbody, and if so, get a proper pointer to it:
Cheers,
Ola
Code: Select all
btRigidBody* rigidbody = dynamic_cast<btRigidBody*>(collision_object);
if(rigidbody)
{
// It's a rigid body!!
rigidbody->doSomething();
}
Ola