Hi guys
I'm a beginner.
I'm learning the previous code ,but I can't find this method
b2World::Query(const b2AABB& aabb, b2Shape** shapes, int32 maxCount)
in the Box2D 2.2.0 or later.
There are other ways to achieve this function.
Thank you very much.
Correct, there are no b2World->Query() method anymore as of 2.2.0. This is due to a change in how shapes are added to a body in 2.1.0. Version 2.1.0 introduced fixtures. You add shapes (only the vertices or radius and position) to the fixtures, then you add fixtures to the bodies. And in the query callbacks, it reports fixtures.
I don't think there are anything that counts how many shapes or fixtures that are overlapping an AABB anymore. That should be taken care of in a query callback.
b2DynamicTree efficiency is faster than other query method.
If you can make a more efficient query function, then great! I was simply answering your question of where the b2World->Query() function went in the newer versions of Box2D.
I don't know about the old version, but the current version uses the dynamic tree:
void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const;
The advantage with the new version is that you are able to decide on an 'early-out' condition so that the search doesn't necessarily need to run to completion.
For example if you are making an RTS and you want to check if there are any units of a certain type in a given region, you can check the type of each unit as the query progresses, and if the unit is the type you're looking for then you can end the search right away. It also lets you use your own container type (eg. I prefer stl:set) instead of requiring you to use a linked list as before.
When I use b2DynamicTree's, I must use this CreateProxy () method to add the each Shape of b2World into b2DynamicTree ?
Thank you very much for your answer!