I request that QueryAABB be accompanied by a function that, rather than tests
AABBs, tests shapes.
Let me explain. With the way Box2D is right now, the only proper way to test
the entire world against a shape is to completely replicate the code that you
have written for b2Contact to allow for a wrapper between the b2Collide
functions.
Testing to see which fixtures are contained within a shape is definitely a
requested feature, and I can see many many uses for it; basically,
shape-testing without requiring to add overhead of the dynamic tree, etc, by
adding a new body and a new fixture to that body just to get the contact
information (which requires that the world be run for a frame anyways!).
I have successfully replicated the b2Contact class into a manner that allows me
to test the world against a shape, however the code is verbose and essentially
just a copy of b2Contact with slight changes (fixtures changed to shapes,
removed any body references and added transform members). I propose that these
changes also be made internally so that a "QueryShape" member may be added to
b2World, which would allow you to test the world against a shape to find
fixtures which are contained inside of it (optionally using "quick" settings,
which basically does what the "sensor" boolean does in your b2Contact code).
The callback would contain void ReportFixture(b2Fixture *fixture, b2Contact
*contact), where fixture is the fixture that was found to collide with the
shape, and contact is the generated, internal contact which contains manifold
information and the "IsTouching()" function (the other functions that do not
pertain to this QueryShape version of b2Contact will just return false or do
nothing).
Personally I find that this would replace the need for the b2Collide* functions
to be exposed publicly (not saying that they be made internal, by any means;
however, to be honest, implementers should not be required to use these
functions on their own accord, and shape-world/shape-shape testing should be
implemented by the physics engine for use by utilities and things like that).
My main reasoning for creating this is to reduce verboseness of testing simple
shapes against each other (poly-circle, in my case), and to add a method to
test shapes that don't include the growing/shrinking of AABBs, which sometimes
interfere with the results.
Anyway, that's all for now, let me know what everybody thinks. If required,
Erin, I can create a patch to implement this as best as I can, so you can
perhaps see what this would bring in real-time and in the testbed.
-P
Original issue reported on code.google.com by Jonno.5000 on 28 Jul 2011 at 11:44
Original issue reported on code.google.com by
Jonno.5000
on 28 Jul 2011 at 11:44