hippocoder wrote:
I would love to help, I just lack the experience to do so at the moment. I will often get stuck not understanding how to translate a couple of things.
No worries.
hippocoder wrote:
if (shape1.collided(shape2,optional index)... directly check a collision between two
if (shape1.collidedCategory(0x0002,optional index)... return true if collided with this category.
Oh yes, I was forgetting this request, this definitely needs sorting out before finalizing.
I see a few issues that need to be addressed, some with your proposal.
1)
"Collided" suggests that the method returns true if the shapes collided at any point in the previous step. This is actually quite a lot of work to store, I think, which is why it's been avoided in the first place. Would "IsTouching" work just as well?
2)
Even in that case, such functions are really just convenience wrappers for the contact list, which must be linearly iterated over. Currently Box2D doesn't store any data structures to quickly access this, and it could be difficult to do so efficiently. I'm not sure what sort of index you had in mind, but I think that sort of thing is ugly, people should not have to do manual caching. On the other hand, it is rare to have many contacts on a single shape, so perhaps linear iteration is fine as is.
Box2D doesn't use the STL, which makes a lot of caching annoyingly hard to do, as otherwise I'd just say put in a
Map<Tuple<b2Shape,ContactID>,b2ContactPoint>
in.
3)
Exposing the contact list. Having a binary test function is one thing, but I think it is equally important to be able to loop over all currently touching shapes. I can see a few ways of doing this:
a) Expose the underlying Box2D contact list. This is how it used to be, with GetContactList / m_contactList. This is dandy, but it kept tripping people up that it had speculative contacts in, and had this manifold/contact point structure that most people didn't want or understand. Perhaps better documentation would help, but is always going to have some usability issues.
b)Expose an iterator to the list. This can eliminate speculative contacts, and provide some help in browsing the list. The down side is that Box2D makes do without explicit iterator objects at the moment, preferring linked lists, so it'd be a bit of a depature.
c) Do a), but provide a GetNext() method that skips speculative contacts.
d)A function, or family of functions, to fill an array with info. I don't like this, but I don't like providing just a few options in any list of things
😉.
4)
Events are currently called during the world step, when everything is locked. People in general don't like this, despite the utility of pre-collision state being available for inspection.
I think Box2D could do with a canonical buffering event listener class, and possibly some API to smooth over it's use. Or alternatively, we could expand the event system further, having equivalent events that are buffered and not. The latter could be neater as certain things, such as the late filtering implemented above, cannot be buffered, while other things, like contact results, have little utility in not buffering.
Or we could try to lift the global ban on editing the world. Certainly, a lot of things are safe, such as setting velocities. With work, it is plausible that most world operations could be acceptable.