Get Objects In Radius or By Point

Is it possible to return a list of Objects found within a given radius on screen? I did not see anything in the API that does this. What about returning a list of objects at a given point on screen?

Any help would be appreciated.

Thanks. [import]uid: 10753 topic_id: 4174 reply_id: 304174[/import]

i imagine you want to use some kind of spatial indexing to optimize this
http://drdave.co.uk/blog/archive/2010/10/4/Spatial-Indexing

basically the further away objects the less likely it is you need to check them as this will slow your game loop down. or do you only have a small world of objects anyway?

if the number of objects is small enough to loop through without affecting performance you could just get the square of the length of their hypotenuse distance from your original point (no need to squareroot it, you can just work with the square length for speed)

which would be something like (x2-x1)*(y2-y1)

just check that value is within your (radius*radius) value.

for your second question…

if you want to get a list of objects at a point, you could just keep an array of an array

objectsAtPoint[x][y] = {obj1, obj2, obj3} etc

i believe 1-dimensional array would be faster tho (combine x ,y into one value)

see here:
http://www.lua.org/pil/11.2.html

so you’d have objectsAtPoint[1] = {obj1,obj2,obj3} etc

where point 1 is [0,0], point 2 is [1,0], point 3 is [2,0], point 4 is [0,1], point 5 is [1,1] etc

(thats in a 3x3 grid for simplicity of example)

however if your objects are moving, i’m not sure this is the most optimal array to store the data as you’ll have to keep moving objects from 1 array point to another

[import]uid: 6645 topic_id: 4174 reply_id: 12966[/import]

If I understand you properly I think at least for your ‘get objects at point’ is how I was thinking of doing it. I just wanted to make sure there was not anything built in to corona like getObjectsAtPoint(). I can certainly build a table and store objects around a point in it. It just seemed quicker if there was some sort of function that got this information for me. If not no big deal. I will build the table for each list of objects I want to track I guess. If objects in my game move I will have to update the tables accordingly. Objects in my game won’t be constantly moving anyway.

Thanks.
[import]uid: 10753 topic_id: 4174 reply_id: 12969[/import]

The other idea I had was to use an invisible object and collision detection. Using collision detection I could build a list of objects collided with the invisible object. If I use a circle vector object as my invisible object then the circle would be my radius. This sounds plausible but honestly I have not looked enough into physics to know if this is possible in Corona.

What do you guys think? [import]uid: 10753 topic_id: 4174 reply_id: 12972[/import]

maybe you could set it up as a sensor and when an item collides with it set a flag on the item as being inside your area of interest on the “begin” phase and remove the flag on the “ended” phase…that might work. i’m not sure how optimized this is though. would be worth doing speed tests on the 2 mehods [import]uid: 6645 topic_id: 4174 reply_id: 12980[/import]

Great. Thanks for you input. [import]uid: 10753 topic_id: 4174 reply_id: 12981[/import]