VBGamer |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Try something like this: Rag on a Stick (2 replies, 0 views) (2000-Sep-28) Have you heard of BSP trees? Basically, you put your data into some sort of order, so maybe you can always rely on the fact that node(5) will be to the left of node(6), node(7) and node(8), but to the right of node(4). It would mean you would have to sort the nodes everytime you placed a new one, but that could easily be optimised. Using that, you could do something like this
Sub select (x,y,blaaaa shift and so on)
dim i As Integer
Dim Start As Integer, Finish As Integer
i = MaxNodes \ 2
If Node(i).x > x Then
'Search top half
i = MaxNodes \ 4 * 3
If Node(i).x > x Then
'Search top quarter
Start = (MaxNodes \ 4 * 3) - 1
Finish = MaxNodes
Else
'Search middle top quarter
Start = (MaxNodes \ 2) - 1
Finish = (MaxNodes \ 4 * 3) + 1
End if
Else
'Search bottom half
i = MaxNodes \ 4
If Node(i).x > x Then
'Search middle bottom quarter
Start = (MaxNodes \ 4) - 1
Finish = (MaxNodes \ 2) + 1
Else
'Search bottom quarter
Start = 0
Finish = (MaxNodes \ 4) + 1
End if
End if
For i = Start to Finish
if node(i).isused = true Then
If x > node(i).x - 5 and node(i).x+ 5 Then
If y > node(i).y - 5 And node(i).y + 5 Then
take info out of it
Exit For
End if
End if
End if
end if
next
There is a better way to do the top thing a bit better, so that you can specify how many levels deep, but it is just a simple demonstration of one way to use them. If you use a Collection to store the nodes, then adding them in order will be easy.
hth
|