Exclude objects from For Next loop

BlitzMax Forums/BlitzMax Beginners Area/Exclude objects from For Next loop

Baz(Posted 2008) [#1]
Hi,
let's say I want to check each variable inside an array of an object with each variable of the array in each other object . After looping through all the variables of object A, it has to be blocked from the list so that the loop does not produce equal AB / BA pairs NOR does it allow object A to be compared with any other object during that frame.
It's basically an intersecting lines detection, where the lines are "reconstructed" to vertex and edge by another function, based on the array number. The current code looks like this and does not work for more than two bodies(i.e. if body A collides with body B, both are somewhy "blocked" for the rest of the simulation"):


Function DetectRectCollision() '''''''''''''loops through all bodies and their edges in the list to
''''''''''''find intersecting lines
Local pass% = True

Local EliminateList:TList = CreateList()


For Local Rect1:Rect = EachIn RectList
For Local Rect2:Rect = EachIn RectList

pass = True

For Local ERect:Rect = EachIn EliminateList

If (ERect = Rect1) Or (ERect = Rect2)
pass = False

EndIf
Next


If (Rect1 <> Rect2) And pass = True

ListAddLast(EliminateList, Rect1)
ListAddLast(EliminateList, Rect2)

For Local c% = 0 To 3
For Local k% = 0 To 3


Local u1#
Local u2#

Local nom1#
Local nom2#

Local denom#


Local d1x# = Rect1.LineArr[c].x
Local d1y# = Rect1.LineArr[c].y

Local d2x# = Rect2.LineArr[k].x
Local d2y# = Rect2.LineArr[k].y

Local d12x# = ((Rect1.Pos.x + Rect1.VertArr[c].x) - (Rect2.Pos.x + Rect2.VertArr[k].x))
Local d12y# = ((Rect1.Pos.y + Rect1.VertArr[c].y) - (Rect2.Pos.y + Rect2.VertArr[k].y))



nom1 = d2x * d12y - d2y * d12x
nom2 = d1x * d12y - d1y * d12x

denom = d2y * d1x - d2x * d1y


u1 = nom1/denom
u2 = nom2/denom


If (u1 > 0 And u1 < 1) And (u2 > 0 And u2 < 1) >>>>>> INTERSECTION of line segments occured


Local Cross:Vector = New Vector
Cross.Assign(c, k)

Rect1.AddIntersection(Cross) ''''''stores
each intersection as a vector in an array



EndIf


Next
Next

Rect1.ProcessIntersection(Rect2) '''''''''''''''

EndIf

Next
Next


End Function


Jesse(Posted 2008) [#2]
use "continue"


Baz(Posted 2008) [#3]
thanks I didn't know anything about continue . But when I try it this way I get "duplicate" collisions just like without any exclusions. At the moment I really can't wrap my head around what's causing the problem.
Maybe you could take a look at the actual program:
http://www.megafileupload.com/en/file/37615/rigid-bmx.html
sorry for that link. I don't have any webspace.
You can pull on the rects with the mouse. Notice that body 3 won't collide with the other two unless you comment out
the "EliminateList Loop", but then you get multiple
collisions. I remember that I had it working before I recoded some parts of the function.

P.s.: What are the tags to format your posted code?
Thanks


Jesse(Posted 2008) [#4]
I'll take a look. you know, you can post the whole code here but not the executable. just use a codebox. here are the forum codes:
http://www.blitzmax.com/faq/faq_entry.php?id=2


Jesse(Posted 2008) [#5]
you know you can change your object elimination to something like this
code sample:
Local List:TList= New TList
list.addlast("apple")
list.addlast("pear")
list.addlast("mango")
list.addlast("peach")
list.addlast("cherry")

Local list2:TList = list.copy()

For Local a$ = EachIn list
	Print a$
	list2.removefirst()
	For Local b$ = EachIn list2
		Print "  "+b$
	Next
Next 


I don't have too much experience with the time comsumption of list.copy() but I dought it will affect program execution that much.
[edit]
note: it only copy addresses, not objects but you knew that right?.