Here is an example...
Strict
Type Vector2d
Field x:Double
Field y:Double
Method Copy:Vector2d()
Return point(x , y)
End Method
Method subtract(Vector:Vector2d)
x:-Vector.x
y:-Vector.y
End Method
Method DOT:Double( Vector:Vector2D )
Return ( X * Vector.X + Y * Vector.Y)
EndMethod
Method reverse()
x = -x
y = -y
End Method
End Type
Function point:Vector2d(x:Double , y:Double)
Local Vector:Vector2d = New Vector2d
Vector.x = x
Vector.y = y
Return Vector
End Function
'''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''' TEST
''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''' THE offsets of the polygons
Local offset1:Vector2d = point(300 , 300)
Local offSet2:Vector2d = point(300,300)
Local offset:Vector2d = offset1.copy()
offset.subtract(offset2)
Local Vel:Vector2d = point(10 , 0)
Local N:Vector2d = point(0,0) '''MTD
Local t:Float = 0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''' COPY PASTE THIS TO GET THE POLYGONS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Local Poly1:Vector2d[3]
Poly1[0] = point(0.00000000000000000 , 0.00000000000000000)
Poly1[1] = point(32.000000000000000 , -64.000000000000000)
Poly1[2] = point(104.00000000000000 , -57.000000000000000)
Local Poly2:Vector2d[2]
Poly2[0] = point(0.00000000000000000 , 0.00000000000000000)
Poly2[1] = point(15.000000000000000 , -40.000000000000000)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DebugStop()
If Collide(poly1 , Poly2 , offset , Vel , N , t)
Print "ok"
End If
Print "out"
Function Collide(A:Vector2d[], B:Vector2d[] , xOffset:Vector2d, xVel:Vector2d , N:Vector2d Var, t:Float Var)
If A = Null Or B = Null Then Return False
'// All the separation axes
Local xAxis:Vector2d[64] ' // note : a maximum of 32 vertices per poly is supported
Local taxis:Float[64]
Local iNumAxes:Int=0
xAxis[iNumAxes] = point(-xVel.y, xVel.x)
Local fVel2:Float = xVel.dot(xVel)
If fVel2 > 0.00001
' If Not IntervalIntersect(A , B , iNumAxes , xAxis[iNumAxes] , xOffset, xVel, taxis[iNumAxes], t)
' Return False
' End If
iNumAxes:+1
End If
'// test separation axes of A
Local j:Int = A.Length - 1
For Local i:Int = 0 To A.Length - 1
Local E0:Vector2d = A[j].copy()
Local E1:Vector2d = A[i].copy()
E1.subtract(E0)
Local E:Vector2d = E1.copy()
xAxis[iNumAxes] = point(-E.y, E.x)
' If Not IntervalIntersect( A , B , iNumAxes , xAxis[iNumAxes] , xOffset, xVel, taxis[iNumAxes], t)
' Return False
' End If
iNumAxes:+1
j = i
Next
'// test separation axes of B
j = B.Length - 1
For Local i:Int = 0 To B.Length - 1
Local E0:Vector2d = B[j].copy()
Local E1:Vector2d = B[i].copy()
E1.subtract(E0)
Local E:Vector2d = E1.copy()
xAxis[iNumAxes] = point(-E.y, E.x)
' If Not IntervalIntersect( A , B , iNumAxes , xAxis[iNumAxes], xOffset, xVel, taxis[iNumAxes], t)
' Return False
' End If
iNumAxes:+1
j = i
Next
' If Not FindMTD(xAxis, taxis, iNumAxes, N, t)
' Return False
' End If
'// make sure the polygons gets pushed away from each other.
If N.Dot(xOffset) < 0.0
N.reverse()
End If
Return True
End Function
Right now I don't get the error I said but only "Process complete "
When in debug mode I step in collide function and then make a step the program just ends.
If anyone can help me to pass this problem he will be grat help to me.