I need to perform distance calculations between a number of fixed 'hotspots' 
and a draggable movie clip on a 2d plane.

To reduce the number of calcualtions I only want to be concerned with those 
'hotspots' that are 'closest to' the movieclip at any given time.

So I need to perform some sort of 'proximity test'

In an earlier post someone pointed out Grant Skinner's Proximity class, which 
is useful if all of your hot spots are moving.

Martin Wood alos opnend my eys to something called 'quadtrees' which is a 
method of spatial partitioning absolutely essential in reducing the number of 
calculations in 
games involving a lot of 3d rendering and spatial movement.
A great reference here:
http://www.gamedev.net/reference/articles/article1303.asp


The simple quadtree I have in mind would be composed of a 16X16 grid of cells 
or 'leaves'.
The dimensions of our draggable clip would also be smaller than each cell.
 To simplify things each 'base node' I would define as having 2X2 or 4 cells. 
So there would be a total of 256 cells and 64 'base nodes'. The total number of 
nodes in this scenario would be:
4   (1st level nodes)
+
4X4  (2nd level nodes)
+
4X(4X4) (3rd level or 'base nodes')
=
84 total nodes

So, to begin, I create this grid, then create my nodes array (or arrays). Each 
node in the array would be composed of x,y,width,height (probably simpler to do 
the width, height calculation up front than simply using bounding points)

At any given time there would be four 'base nodes' that would be considered 
'nearest neighbours'......we need to check for and return the current plus 3 
additional 'base nodes' depending on which one of four cells in the current 
'base node' we're 'over' at any given time (this is easier to ilustrate on a 
sheet of graph paper). 

But the net result is that we are dealing with only 4 as opposed to 64(the 
entire grid)  'base nodes' or 16 vs 256 cells...a savings or reduction of 16X.


So i guess what I'm asking is 
What is the best way to set up the node array(s)? (nested , associative, using 
objects, etc)
and
Given the current x,y coordinates of the draggable movieclip and the nodes 
array(s), how to perform the quadtrees calculaton?

Thanks
Jim Bachalo

[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca
--------------------------------------------
"...all improvisation is life in search of a style."
             - Bruce Mau,'LifeStyle'
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to