[SOLVED] box2d categories + masks problem
Posted: Thu Nov 07, 2013 12:14 am
The problem is that I have been using the following structure to define categories and masks of objects in my game:
As you can see, it's getting kinda big with lots of numbers there, and the maximum number of different categories you can have is 16. While that won't happen any time soon, I'd be at peace if I could figure out a way of not having to deal with those categories and masks directly and to be able to define what should ignore what in a nicer way. The nicer way I have in mind is:
a)
and automagically something like this would be generated:
b)
This example looks obvious, so I thought it was going to be easy to translate this into a nice simple algorithm. But it's actually really hard and I don't know how to do it. Does anyone have any ideas?
tldr: need help creating an algorithm that translates a) into b) while using the least number of categories possible (so the 16 limit isn't reached).
The structures (collision_mask(s), .ignores, and other tables) are meaningless, I'm interested in a high level description of an algorithm to solve this. Or just another completely different way of handling categories + masks with box2d, that would work too.
As you can see, it's getting kinda big with lots of numbers there, and the maximum number of different categories you can have is 16. While that won't happen any time soon, I'd be at peace if I could figure out a way of not having to deal with those categories and masks directly and to be able to define what should ignore what in a nicer way. The nicer way I have in mind is:
a)
Code: Select all
A.ignores = {'A', 'B', 'C', 'D'}
B.ignores = {'C'}
C.ignores = {'B'}
D.ignores = {'A', 'C', 'D'}
b)
Code: Select all
collision_masks['A'] = collision_mask({1}, {1, 2, 3, 4})
collision_masks['B'] = collision_mask({2}, {3})
collision_masks['C'] = collision_mask({3}, {2})
collision_masks['D'} = collision_mask({4}, {1, 3, 4})
tldr: need help creating an algorithm that translates a) into b) while using the least number of categories possible (so the 16 limit isn't reached).
The structures (collision_mask(s), .ignores, and other tables) are meaningless, I'm interested in a high level description of an algorithm to solve this. Or just another completely different way of handling categories + masks with box2d, that would work too.