View Single Post
03-10-16, 02:40 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Turning this into a function of its own, this should do the trick. WorldMapButton is a child of WorldMapFrame that the map and all objects are placed on. TomTom used to use the AstroLab library for real coordinates of the map edges, but they are now provided through GetCurrentMapZone(). There's some additional complexity to using these if you want to include distances, but as you aren't including that in your design, this is a more simple approach.

Lua Code:
  1. function GetDirection(x,y)
  2. --  Only reset map if not shown
  3.     if not WorldMapFrame:IsShown() then SetMapToCurrentZone(); end
  4.  
  5.     local px,py=GetPlayerMapPosition("player");
  6.     if px==0 and py==0 then return nil; end--   Return nil if not on map
  7.     local w,h=WorldMapButton:GetSize();
  8.  
  9. --  Converts radians to degrees and normalizes range to -180 thru 180 (Player X and Y are multiplied by 100)
  10.     return ((GetPlayerFacing()-math.atan2((px*100-x)*w,(py*100-y)*h))*180/math.pi+180)%360-180;
  11. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 03-10-16 at 02:47 PM.
  Reply With Quote