Aug 26, 2009 at 1:49 AM
Edited Aug 26, 2009 at 1:54 AM
Thanks for the answer,
Sadly, it seems like my first impression was right and it will not be easy to achieve this in Farseer. As I mentioned in my original post, static CollisionCategories don't really work for what I want, and it's not a matter of dynamically created joints.
Suppose A links to B. This setup is a composite object (e.g. a Composite class which creates A, B, and the link). What I want is to be able to instantiate 2 Composite objects and have all bodies collide with all bodies except those which are linked under
the same Composite. I'm sorry if I'm not making myself clear, but the situation is really very simple, and indeed natural for many complex articulated systems I've worked on before.
About your second proposal, it should indeed work, but unfortunately it places too much of a burden on geometries themselves (e.g. the OnCollision events of both geometries will have to be called and rejected). Also, it will lead to tightly coupled code.
Probably what I'll do is try to adapt the ODE solution to Farseer. Basically:
1. Keep a list of attached joints on the Body's Tag object. The list will have to be maintained when joints are attached or removed from the body.
2. Use this list to implement a helper IsConnectedTo() method that I can use to check whether a Body is connected to another via a joint.
3. Hook to the general BroadPhase OnCollision event and exclude pairs of geometries linked to bodies which are connected via joints.
In this way excluded collisions will be caught even before any narrow collision tests are made (i.e. more performant) and it can be applied generally to all geometries in a scene.
I think you're right that a generic solution shouldn't be on the engine. ODE engine also doesn't assume this, but there is an easy and engine-integrated way to find out which bodies are connected, which helps tremendously in implementing this and other collision
Edit: I just noticed that things will be even more complicated since the abstract Joint class interface doesn't have information about the bodies linked to the Joint. So every solution will have to be tailor-made for each joint type, for each object scenario.