Point in Area (mega!) von ???
Diese Routine funktioniert so:

alle Linien einer Fläche werden auf Überschneidung mit Linie von 0,0 bis Mauskoord. geprüft. Wenn die Anzahl der Überschneidungen ungerade ist, dann befinden sich der Punkt in der Fläche. Der Punkt 0,0 kann auch verschoben werden, wenn es Probleme gibt...

Durch Floats kann es je nach Fläche zu Falschmeldungen kommen - darum sollte man von Punkt 0,0 und zusätzlich von anderen Punkt(EN) auf Kollision testen - sind alle Ergebnisse positiv, dann gibts endgültig Kollision...

[code:1:ae03b4bbdf]
Graphics 640,480,0,2

SetBuffer BackBuffer()
area=area_create()
area_add(area,50,50)
area_add(area,100,300)
area_add(area,250,80)
area_add(area,130,200)

area_add(area,160,100)
area_add(area,120,150)


While Not KeyHit(1)
px=MouseX()
py=MouseY()
Cls
Color 180,180,180
Line 0,0,px,py
If area_point(area,px,py)=1 Then Color 255,0,0 Else Color 0,255,0
area_draw(area)
Flip
Wend





;---------------------------------------------------------------------
Function area_add(bank,x,y)
size=BankSize(bank)
ResizeBank bank,size+8
PokeInt bank,size,x
PokeInt bank,size+4,y
End Function





;---------------------------------------------------------------------
Function area_create()
bank=CreateBank(0)
Return bank
End Function





;---------------------------------------------------------------------
Function area_draw(bank)
count=BankSize(bank)/8
If count<3 Then Return
For i=0 To count
If i=count Then
x=PeekInt(bank,0)
y=PeekInt(bank,4)
Else
x=PeekInt(bank,i*8)
y=PeekInt(bank,i*8+4)
EndIf

If i>0 Then
Line x,y,oldx,oldy
EndIf
oldx=x
oldy=y
Next
End Function





;---------------------------------------------------------------------
Function area_point(bank,px,py)
count=BankSize(bank)/8
If count<3 Then Return

For i=0 To count
If i=count Then
x=PeekInt(bank,0)
y=PeekInt(bank,4)
Else
x=PeekInt(bank,i*8)
y=PeekInt(bank,i*8+4)
EndIf

If i>0 Then coll=coll+lines_intersect(x,y,oldx,oldy,0,0,px,py)
oldx=x
oldy=y
Next

Text 50,0,coll+" Überschneidungen"
Text 50,15,coll+" And 1 = "+(coll And 1)
Return coll And 1
End Function




;---------------------------------------------------------------------
Function lines_intersect(ax#, ay#, bx#, by#, cx#, cy#, dx#, dy#)
rn# = (ay#-cy#)*(dx#-cx#) - (ax#-cx#)*(dy#-cy#)
rd# = (bx#-ax#)*(dy#-cy#) - (by#-ay#)*(dx#-cx#)
If rd#<>0 Then
sn# = (ay#-cy#)*(bx#-ax#) - (ax#-cx#)*(by#-ay#)
intersection_ab# = rn# / rd#
intersection_cd# = sn# / rd#
intersection_x# = ax# + intersection_ab#*(bx#-ax#)
intersection_y# = ay# + intersection_ab#*(by#-ay#)
If intersection_ab#=>0 And intersection_ab#<=1 And intersection_cd#=>0 And intersection_cd#<=1 Then Return 1
EndIf
End Function
[/code:1:ae03b4bbdf]
===
von ???
Das ist ja geil! Respekt!
===
von ???
Hehe, cool!!! :D



Suche:
(unterstützt mySQL Wildcards ala %)
Titel:
Text:
Autor: