getting all bodys in a cart

hello.

i would like to get a a lit of all ball_bodys that were collected and put in a cart.
how would i go about this?
my first approach was to get the contact list of the cart and check for all bodys connected to it and the iterate through all bodys, get their contact list and see if they are connected to the bodys in the first list.

however i am sure there is a more elegant solution?

thanks
How about placing a sensor so that it covers the area of the cart in which a ball is considered to be in the cart. Then you can check which balls are touching the sensor.
problem is, the "balls" are actually different also notround items which can be stacked.
it is really difficult to guess, what area the player might use later in the game.
of course i could make the sensor huge but then there might be items touching it, which are not "in"
Does it matter what shape the balls are? As long as the cart is the same size then surely you can cover the carter with a sensor like irresistible force suggests. If the balls stack up high above the cart but still count as being in the cart maybe you can do some kind of check if a ball is touching a ball that is in the cart's sensor area and it stays in contact for more than 1 second say then its in the cart. That is, assuming the first ball in the cart actually goes into the cart's sensor area, then it goes into an array, then then next ball also goes into the array if it stays in the sensor area or stays in contact with a ball already in the array, and so on....
hi mkfield, and thanks for taking the time to answer.

well i already applied a sensor on the bottom of the cart.
then i tried to find all objects which touch this sensor
and then all objects which touch the objects that touch the sensor.

unfortunately it does not seem to work, or more so, i did something wrong.
(see my other post at viewtopic.php?f=3&t=6964)

so it registeres also object which are close to the sensor (outside the cart) as being inside just, because the function registeres them as touching the sensor.

i am a little bit lost now

thanks again for all suggestions
Ok, well I have done a similarish thing but i haven't used b2contactedge and I had a bin instead of a cart and I didn't need to check for items piling up on top of the bin but still count as in the bin, but that shouldn't be too hard to add in. I used a contact listener like in Ray's tutorial (http://www.raywenderlich.com/606/how-to ... s2d-iphone near the bottom) which would let me know every time one body came into contact with another. So if a body came into contact with (ie. overlapped) my bin sensor I added that body to an array of bodies in contact with the sensor.

Also, is you're cart basically like a container and things have to fall into it? If so, you could make a fixture around the outside bottom and sides that's not a sensor, so things can't get in and a fixture in the middle which is your sensor, and a gap on top for things to fall into the sensor. The sensor's area can be the area of the inside of the cart.
Quote:
Also, is you're cart basically like a container and things have to fall into it? If so, you could make a fixture around the outside bottom and sides that's not a sensor, so things can't get in and a fixture in the middle which is your sensor, and a gap on top for things to fall into the sensor. The sensor's area can be the area of the inside of the cart.


well, no, it is an open platform with no sides, so objects can indeed fall off the cart

Original thread: https://box2d.org/forum/viewtopic.php?t=6950