Simple Collision Questions: Everyone must start somewhere.

TheJustinWalsh
Posts: 3
Joined: Fri Aug 25, 2006 4:02 pm
Location: Phoenix, AZ

Simple Collision Questions: Everyone must start somewhere.

Post by TheJustinWalsh »

Hello everyone,

I am a bit new here and had a few simple questions that will hopefully get me going in the world of Bullet. Currently I am interested in simple collision detection, simple as in Box on Box collisions with decent accuracy, performance is more important here.

I worked through the CollisionInterfaceDemo, and do not feel i have an understanding of what is needed to set up a simple callback system for collisions, or even realize the full potential of what i am able to do. If anyone would be willing to point me to the right classes to be using for said collisions, that would be splendid.

I currently understand that will need to use a CollisionWorld and Populate it with Collision objects, but the Dispatcher and BroadPhaseInterface still mystify me as to how to use them, or if this is even what i am looking for.

Thank you in advance,
Justin Walsh
dog
Posts: 40
Joined: Fri Jul 22, 2005 8:00 pm
Location: Santa Monica

Post by dog »

Buy Real-Time Collision Detection by Christer Ericson. Accessible to everyone, thorough and with source code.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Do you want to just use collision detection, and no rigid body dynamics?

CollisionInterfaceDemo should provide you with basic functionality. Just create the CollisionWorld (pass in the Dispatcher and Broadphase as in the demo. Dispatcher is an internal mechanism that chooses the algorithm for a pair of objects, broadphase is an optimization based on AABB's).

Add some objects to the CollisionWorld, and then each frame call
CollisionWorld::PerformDiscreteCollisionDetection

For each pair of collision objects that have their bounding box overlap (based on Broadphase) and is not filtered out by CollisionFiltering has a contactManifold that contains contact points. Usually, those are passed to the Rigid Body Dynamics for constraint handling. The CollisionInterfaceDemo shows how to iterate over all contactManifolds and get all contact points between all collision objects.

Alternatively, you can setup a callback when each contact points gets added and removed. For added contact points, assign a callback method to gContactAddedCallback. See ConcaveDemo how to do this. In Rigid Body dynamics, this can be handy to override friction, but you can also use it to do your own collision response.

If you just want box-box, you can also directly use the GjkPairDetector, it will give you 1 closest point. See CollisionDemo for this low-level usage. The benefit of using extra infrastructure is that it will collect more then 1 point.

What do you want to use it for exactly?
TheJustinWalsh
Posts: 3
Joined: Fri Aug 25, 2006 4:02 pm
Location: Phoenix, AZ

Post by TheJustinWalsh »

I will mainly be using it in a current game project that i am working on at school. The game is a throwback to old-school arcade shooters, just done in a 3D engine, but keeping the 2D game play in tact.

Most of the collisions will be in a local 2D coordinate system, however there are world level collisions that we would like to detect as well, Terrain, and other static world geometry. I figure our most complex collision well be against a properly generated collision mesh on the world geometry, and other statics vs a hit box for the player.

Our project team has decided that we will not require rigid body dynamics at this time, but by using Bullet instead of something like opcode, the option is there for later. We looked at several options, and for some reason keep ending back on Bullet's website. Being a complete newb to physics and 3D collisions in general does not help. So as dog suggested, i will most likely pick up that book, and as you suggested play with the demo's and look into the classes and functions mentioned above.

Thank You,
Justin Walsh
TheJustinWalsh
Posts: 3
Joined: Fri Aug 25, 2006 4:02 pm
Location: Phoenix, AZ

Post by TheJustinWalsh »

Well i decided i will implement more than just box on box, and do some sphere, plane, and triangle-mesh(world geometry). So far everything is going well.

If all i care about is knowing when two objects have a collision, and do not plan on using any of the dynamics, why might i want to collect more than one contact point, vs. doing just the pair detector?

Also, the CCD is for being able to time step the collisions right? Like to check if a collision possibly passed completely through an object in a given frame, but did not actually report a collision due to the object moving two fast per frame. Or is this something i need to write myself?

Thanks again,
Justin Walsh
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

TheJustinWalsh wrote:Well i decided i will implement more than just box on box, and do some sphere, plane, and triangle-mesh(world geometry). So far everything is going well.

If all i care about is knowing when two objects have a collision, and do not plan on using any of the dynamics, why might i want to collect more than one contact point, vs. doing just the pair detector?
It depends what information you want indeed. If you just want a boolean (collides yes/no?) some calculations can be discarded. You can either modify the Dispatcher, to return a special version of the PersistentManifold, or just clear all contact points every frame (shouldn't take any processor cycles really).
Also, the CCD is for being able to time step the collisions right? Like to check if a collision possibly passed completely through an object in a given frame, but did not actually report a collision due to the object moving two fast per frame. Or is this something i need to write myself?
The continuous collision detection (CCD) query is used for ray casting, for object sweep (character control) and for avoiding missing collision for fast moving rigidbodies.
The time-stepping in the dynamics loop needs to be improved to handle the time of impact queue properly. This is work in progress.
At the moment, I'm cleaning up the sample code (it became a mess of copy/paste). Then a demo showing a fork-lift vehicle (on Steve Bakers request), and a character controller, using the CCD sweep. After this, I will start working on the TOI dynamics, using ideas from Brian Mirtich's TimeWarp RigidBodies paper.

Erwin