Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fbgfx.bi"
- Randomize Timer
- screenres 640,480,32
- Const As Single PI = 3.1415926535897932, PI2 = PI*2, PId2 = PI/2, PID180 = PI/180
- Type vec2f
- As Single x,y
- End Type
- Declare Operator + ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Declare Operator + ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Declare Operator - ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Declare Operator - ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Declare Operator * ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Declare Operator * ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Declare Operator / ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Declare Operator / ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Declare Operator / ( Byval lhs As vec2f, Byval rhs As Integer ) As vec2f
- Declare Function Lines_Intersect( Byref ipoint As vec2f, Byref va As vec2f, Byref vb As vec2f, Byref vc As vec2f, Byref vd As vec2f ) As Integer
- Dim As vec2f Line1(1 To 2), Line2(1 To 20)
- For i As Integer = 1 To Ubound(Line2)-1
- Dim As Single rad = i * ( PI2 / ( Ubound(Line2) - 1 ) )
- Dim As Integer rSize = 100 + Int( Rnd * 50)
- Line2(i) = Type( 320 + rSize * Cos(rad), 240 + rSize * -Sin(rad) )
- Next
- Line2( Ubound(Line2) ).X = Line2(1).X
- Line2( Ubound(Line2) ).Y = Line2(1).Y
- dim as integer mx, my
- dim as vec2f p1, p2, center
- do
- getmouse(mx,my)
- Dim As Single rad = Timer * .25
- Line1(1) = Type(320, 240)
- Line1(2) = Type( 320 + 125 * Cos(rad), 240 + 125 * -Sin(rad) )
- p1 = Line1(1)
- p2 = type(mx, my)
- Dim As vec2f intersection_point
- dim as integer hCount
- For i As Integer = 1 To Ubound(Line2)-1
- If Lines_Intersect( intersection_point, Line2(i), Line2(i+1), p1, p2 ) then
- hCount+=1
- end if
- next
- screensync
- screenlock
- cls
- intersection_point = Line1(2)
- For i As Integer = 1 To Ubound(Line2)-1
- Dim As Integer linecol = &hffffff
- If Lines_Intersect( intersection_point, Line2(i), Line2(i+1), Line1(1), Line1(2) ) Then
- 'linecol = &h0000ff
- End If
- line(Line2(i).X, Line2(i).Y)-(Line2(i+1).X, Line2(i+1).Y),linecol
- Next
- if (hCount and 1) = 0 then
- print "Mouse inside"
- paint(320,240),&HFF0000,&HFFFFFF
- else
- print "Mouse outside"
- end if
- Line(Line1(1).X, Line1(1).Y)-(intersection_point.x, intersection_point.y),&hffff00
- circle(intersection_point.x, intersection_point.y), 3
- screenunlock
- Sleep 3,1
- Loop Until multikey(FB.SC_ESCAPE)
- Function Lines_Intersect( Byref ipoint As vec2f, Byref va As vec2f, Byref vb As vec2f, Byref vc As vec2f, Byref vd As vec2f ) As integer
- Dim As vec2f v1 = vb - va
- Dim As vec2f v2 = vd - vc
- Dim As vec2f v3 = vc - va
- Dim As single perp = (v1.x * v2.y) - (v1.y * v2.x)
- If perp<>0 Then
- Dim As Single d1 = ((v3.x * v2.y) - (v3.y * v2.x)) / perp
- If d1<=1 And d1>=0 Then
- Dim As Single d2 = ((v3.x * v1.y) - (v3.y * v1.x)) / perp
- If d2<=1 And d2>=0 Then
- Dim As Single m1, m2, c1, c2, recip
- If v1.x <> 0 Then
- m1 = v1.y / v1.x
- Else
- m1 = 10000000000
- End If
- If v2.x <> 0 Then
- m2 = v2.y / v2.x
- Else
- m2 = 10000000000
- End If
- c1 = va.y - (m1*va.x)
- c2 = vc.y - (m2*vc.x)
- recip = 1 / -(m1 - m2)
- ipoint.x = -(c2-c1) * recip
- ipoint.y = ((m2*c1) - (m1*c2)) * recip
- Return TRUE
- End If
- End If
- End If
- Return FALSE
- End Function
- Operator + ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Return type<vec2f>( lhs.x + rhs.x, lhs.y + rhs.y )
- End Operator
- Operator + ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Return type<vec2f>( lhs.x + rhs, lhs.y + rhs )
- End Operator
- Operator - ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Return type<vec2f>( lhs.x - rhs.x, lhs.y - rhs.y )
- End Operator
- Operator - ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Return type<vec2f>( lhs.x - rhs, lhs.y - rhs )
- End Operator
- Operator * ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Return type<vec2f>( lhs.x * rhs.x, lhs.y * rhs.y )
- End Operator
- Operator * ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Return type<vec2f>( lhs.x * rhs, lhs.y * rhs )
- End Operator
- Operator / ( Byval lhs As vec2f, Byval rhs As vec2f ) As vec2f
- Return type<vec2f>( lhs.x / rhs.x, lhs.y / rhs.y )
- End Operator
- Operator / ( Byval lhs As vec2f, Byval rhs As Single ) As vec2f
- Return type<vec2f>( lhs.x / rhs, lhs.y / rhs )
- End Operator
- Operator / ( Byval lhs As vec2f, Byval rhs As Integer ) As vec2f
- Return type<vec2f>( lhs.x / rhs, lhs.y / rhs )
- End Operator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement