I'm trying to implement collision detection using the latest JiglibX. I am working off of this example. I chose creating a callback. I'm trying to detect a collision only once. When the object falls through, the callback is invoked multiple times, not only once. Is there any way how to ignore other calls? Thanks for advice.
What you need is to create a system to manage this for you. I have a list of bodies that each body is colliding with at any given time, I build this list based on the events I receive from JigLibX. At the end of each physics simulation step I update the list. Any new entries in the list that weren't there during the last step are new collisions, and I will send out an event for each of those that I find. Any collisions that were there during the last step that aren't there now are collisions that have ended, and I send out an event for all of those. And any collisions that I receive that were already in the list I do nothing for. Here's a visualization
Simulation Step # Collision pairs 1 1<->2, 1<->3, 2<->4 2 1<->3, 2<->4, 2<->5
My list for collisions is currently empty before step 1. After step one my list looks like:
Body Collisions with 1 2, 3 2 1, 4 3 1 4 2
After simulation step 2, my list looks like this:
Body Collisions with 1 3 2 4, 5 (new) 3 1 4 2 5 2 (new)
You can see here we have a collision in the above list that is new (2<->5), I would send out events for that collision. There is also a collision from the first list that is no longer in the list after step 2, and that is 1<->2, which I would send out events for as well.
Using a system like I've described above means that you only have to receive a collision event when a new collision occurs, or when a collision ends.
You can see this system implemented in the QuickStart Game Engine, which uses XNA with JigLibX, it's a free download.
I don't know of any way to make JigLibX not send collision events each frame. Each physics engine I've used did this every frame (simulation step).