Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.16 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <StaticConstants.au3>
  3. #include <WindowsConstants.au3>
  4. #include <GDIPlus.au3>
  5. #include "GWCAConstants.au3"
  6. Opt("MouseCoordMode", 2)
  7. #region ### START Koda GUI section ### Form=
  8. $Form1 = GUICreate("Form1", 800, 800)
  9. GUISetState(@SW_SHOW)
  10. #endregion ### END Koda GUI section ###
  11. Global $ThetaDeg
  12.  
  13. _GDIPlus_Startup()
  14. $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
  15. While 1
  16.     $cbType = "int"
  17.     CmdCB($CA_GetCurrentTarget)
  18.     If $cbvar[0] <> 0 Then
  19.         _GDIPlus_GraphicsDrawEllipse($hGraphic, 195, 330, 210, 210)
  20.         _GDIPlus_GraphicsDrawRect($hGraphic, 300, 435, 2, 2)
  21.         $cbType = "float"
  22.         $distance = CmdCB($CA_GetMyDistanceToAgent, 1)
  23.         $owncoords = CmdCB($CA_Getcoords, -2)
  24.         $targetcoords = CmdCB($CA_Getcoords, -1)
  25.  
  26.         $angle = -1 * ATan2($owncoords[1] - $targetcoords[1], $owncoords[0] - $targetcoords[0])
  27.         $x = 300 + $distance[0] * Cos($angle)
  28.         $y = 435 + $distance[0] * Sin($angle)
  29.  
  30.         _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, 2, 2)
  31.     EndIf
  32. WEnd
  33.  
  34. Func atan2($x, $y)
  35.     $Pi = 4 * ATan(1)
  36.     If StringIsInt($x) Or StringIsFloat($x) Then
  37.         If StringIsInt($y) Or StringIsFloat($y) Then
  38.             ; OK
  39.         Else
  40.             SetError(1)
  41.             Return ""
  42.         EndIf
  43.     Else
  44.         SetError(1)
  45.         Return ""
  46.     EndIf
  47.     Dim $PolarAnswer[3] ; $Results[0]=Radius, [1]=Theta (in Radians), [2]=Theta (in Degrees)
  48.     $r = Sqrt(($x ^ 2) + ($y ^ 2))
  49.     $PolarAnswer[0] = $r
  50.     Select
  51.         Case $x = 0 And $y = 0
  52.             $ThetaRad = 0
  53.             $ThetaDeg = 0
  54.         Case $x >= 0 And $y >= 0 ; +x/+y = 0-90deg quadrant
  55.             $ThetaRad = ATan($x / $y)
  56.             $ThetaDeg = $ThetaRad * 180 / $Pi
  57.         Case $x >= 0 And $y < 0 ; +x/-y = 90-180deg quadrant
  58.             $ThetaRad = ATan(Abs($y) / $x)
  59.             $ThetaDeg = $ThetaRad * 180 / $Pi + 90
  60.             $ThetaRad = $ThetaRad + $Pi / 2
  61.         Case $x < 0 And $y < 0 ; -x/-y = 180-270deg quadrant
  62.             $ThetaRad = ATan(Abs($x) / Abs($y))
  63.             $ThetaDeg = $ThetaRad * 180 / $Pi + 180
  64.             $ThetaRad = $ThetaRad + $Pi
  65.         Case $x < 0 And $y >= 0 ; -x/+y = 2700-360deg quadrant
  66.             $ThetaRad = ATan($y / Abs($x))
  67.             $ThetaDeg = $ThetaRad * 180 / $Pi + 270
  68.             $ThetaRad = $ThetaRad + 3 * $Pi / 2
  69.     EndSelect
  70.     $PolarAnswer[2] = $ThetaDeg
  71.     SetError(0)
  72.     Return $ThetaDeg
  73. EndFunc   ;==>atan2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement