Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <GDIPlus.au3>
- #include "GWCAConstants.au3"
- Opt("MouseCoordMode", 2)
- #region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("Form1", 800, 800)
- GUISetState(@SW_SHOW)
- #endregion ### END Koda GUI section ###
- Global $ThetaDeg
- _GDIPlus_Startup()
- $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
- While 1
- $cbType = "int"
- CmdCB($CA_GetCurrentTarget)
- If $cbvar[0] <> 0 Then
- _GDIPlus_GraphicsDrawEllipse($hGraphic, 195, 330, 210, 210)
- _GDIPlus_GraphicsDrawRect($hGraphic, 300, 435, 2, 2)
- $cbType = "float"
- $distance = CmdCB($CA_GetMyDistanceToAgent, 1)
- $owncoords = CmdCB($CA_Getcoords, -2)
- $targetcoords = CmdCB($CA_Getcoords, -1)
- $angle = -1 * ATan2($owncoords[1] - $targetcoords[1], $owncoords[0] - $targetcoords[0])
- $x = 300 + $distance[0] * Cos($angle)
- $y = 435 + $distance[0] * Sin($angle)
- _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, 2, 2)
- EndIf
- WEnd
- Func atan2($x, $y)
- $Pi = 4 * ATan(1)
- If StringIsInt($x) Or StringIsFloat($x) Then
- If StringIsInt($y) Or StringIsFloat($y) Then
- ; OK
- Else
- SetError(1)
- Return ""
- EndIf
- Else
- SetError(1)
- Return ""
- EndIf
- Dim $PolarAnswer[3] ; $Results[0]=Radius, [1]=Theta (in Radians), [2]=Theta (in Degrees)
- $r = Sqrt(($x ^ 2) + ($y ^ 2))
- $PolarAnswer[0] = $r
- Select
- Case $x = 0 And $y = 0
- $ThetaRad = 0
- $ThetaDeg = 0
- Case $x >= 0 And $y >= 0 ; +x/+y = 0-90deg quadrant
- $ThetaRad = ATan($x / $y)
- $ThetaDeg = $ThetaRad * 180 / $Pi
- Case $x >= 0 And $y < 0 ; +x/-y = 90-180deg quadrant
- $ThetaRad = ATan(Abs($y) / $x)
- $ThetaDeg = $ThetaRad * 180 / $Pi + 90
- $ThetaRad = $ThetaRad + $Pi / 2
- Case $x < 0 And $y < 0 ; -x/-y = 180-270deg quadrant
- $ThetaRad = ATan(Abs($x) / Abs($y))
- $ThetaDeg = $ThetaRad * 180 / $Pi + 180
- $ThetaRad = $ThetaRad + $Pi
- Case $x < 0 And $y >= 0 ; -x/+y = 2700-360deg quadrant
- $ThetaRad = ATan($y / Abs($x))
- $ThetaDeg = $ThetaRad * 180 / $Pi + 270
- $ThetaRad = $ThetaRad + 3 * $Pi / 2
- EndSelect
- $PolarAnswer[2] = $ThetaDeg
- SetError(0)
- Return $ThetaDeg
- EndFunc ;==>atan2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement