Your picture with helping lines, and numbers:
- topleft.png (8 KiB) Viewed 2549 times
Code: Select all
#NoEnv
#SingleInstance Force
CoordMode, Mouse, Client
Gui, Margin, 0, 0
Gui, Add, Picture,, topleft.png
Gui, Show
global Pi := 3.14159265359
global CenterX := 210 ; by eye-ball measurement
global CenterY := 210 ; by eye-ball measurement
OnMessage(0x200, "onMouseMove") ; WM_MOUSEMOVE
return ; end of auto-execute section
GuiClose:
ExitApp
;-------------------------------------------------------------------------------
onMouseMove() { ; WM_MOUSEMOVE event
;-------------------------------------------------------------------------------
MouseGetPos, mX, mY
dx := mX - CenterX
dy := mY - CenterY
ToolTip, % Formula(dy, dx)
}
;-------------------------------------------------------------------------------
Formula(dy, dx) { ; testing
;-------------------------------------------------------------------------------
; need to invert Y (screen coords, not math coords)
Angle := atan2(-dy, dx)
; need to rotate 90 degrees (game chooses North = 0, we follow)
Angle -= Pi/2
; need to avoid negative result (we want range only from 0 .. 6.28)
if (Angle < 0)
Angle += 2 * Pi
return Angle
}
;-------------------------------------------------------------------------------
atan2(y, x) { ; 4-quadrant atan
;-------------------------------------------------------------------------------
Return DllCall("msvcrt\atan2", "Double", y, "Double", x, "CDECL Double")
}
All 4 quadrants work with new formula.
I hope that helps!