Hi!
I'm a total noob to the Bullet (and ANY real physics simulation in general, so I don't understand all those "broadphases" and all that), and I have a question.
I've got, for example two rigid bodies, a sphere and a concave mesh, for example (a representation of a game's world and, for example, a tank shell). I want a very simple event to happen - if the tank shell (a spherical rigid body) hits the ground (a concave rigid body) I want the tank shell (a spherical body) removed.
Therefore, I need a function like this:
bool IsThereACollision(btRigidBody body1, btRigidBody body2){
//something here. returns true if collided, and false if not.
}
How do I do this?
Exact C++ code required would be very appreciated.
I'm asking, because I was unable to find a simple answer to this simple question in a simple form, so sorry for it's "noobness".
Easy collision check required (Newbie question)
-
- Posts: 1
- Joined: Sat Sep 06, 2008 3:33 pm
-
- Posts: 69
- Joined: Sat May 10, 2008 8:39 am
Re: Easy collision check required (Newbie question)
You can use two options:
- Set and use the gContactAdded and gContactRemoved callbacks. These callbacks will fire off whenever a collision contact is made. It passes along a contact manifold as well as the two objects that are colliding. With this information you should have enough information to determine what to do. One drawback: you cannot rely on the m_appliedImpulse which is passed to the contactAdded callback. So if you need to have the correct collision impulse on impact, don't use this.
Another pitfall: global callbacks are very dangerous if not reset properly. I.e., if you remove the object that contains the callback or contains data that is used inside the callback BEFORE you remove bullet, things will go horribly wrong! Unfortunately Bullet doesn't handle this gracefully, the whole contact callback mechanism seems to be hacked into Bullet. So I'd vote for option 2:
- Use setInternalTickCallback(). See
http://www.bulletphysics.com/Bullet/php ... 68&p=10269
http://www.bulletphysics.com/Bullet/php ... 331&p=9179
You can trust the m_appliedImpulse, however the "velocity on impact" information seems to be lost. For that I guess you need option 1.
Hope this makes sense? Good luck with it!
Cheers
- Set and use the gContactAdded and gContactRemoved callbacks. These callbacks will fire off whenever a collision contact is made. It passes along a contact manifold as well as the two objects that are colliding. With this information you should have enough information to determine what to do. One drawback: you cannot rely on the m_appliedImpulse which is passed to the contactAdded callback. So if you need to have the correct collision impulse on impact, don't use this.
Another pitfall: global callbacks are very dangerous if not reset properly. I.e., if you remove the object that contains the callback or contains data that is used inside the callback BEFORE you remove bullet, things will go horribly wrong! Unfortunately Bullet doesn't handle this gracefully, the whole contact callback mechanism seems to be hacked into Bullet. So I'd vote for option 2:
- Use setInternalTickCallback(). See
http://www.bulletphysics.com/Bullet/php ... 68&p=10269
http://www.bulletphysics.com/Bullet/php ... 331&p=9179
You can trust the m_appliedImpulse, however the "velocity on impact" information seems to be lost. For that I guess you need option 1.
Hope this makes sense? Good luck with it!
Cheers