Wrong WvW Objective Coordinates ?
Side.3489:
Hi,
Got a little trouble placing the objectives on a map.
Should’ve been simple no ?
The map_rect for the desert borderlands is reported to be (i.e. https://api.guildwars2.com/v2/maps/1099) :
[
[-36864,
-36864
],
[36864,
36864
]
]
This is roughly saying that the map is a square with 73728 side’s length.And that the point (0,0) is the map’s center point.
My problem here is that NONE of the wvw Objectives coordinate’s (i.e. https://api.guildwars2.com/v2/wvw/objectives/1099-99) have a negative part in their coordinates. Placing them all in the top-right corner of the map.
Well that’s not a problem, we’ll assume that the map center point is at the top-left corner of the map (thus allowing placing the objectives all over the map using only positive numbers)
New problem eatch component of the objectives coordinates are between 9000-15000
That’s a little hard to play with…. Our map being 73728 units large….. All objectives are grouped tighly.
So did I miss something (didn’t get the Objectives coordinates or the map size from the good place) ? Or is there something wrong with the API ?
Thanks for reading
smiley.1438:
See this thread: https://forum-en.guildwars2.com/forum/community/api/Event-Details-API-location-coordinates
I made a silly picture
All events are within map_rect of their respective map.
All maps are within continent_rect of their continent.To figure out where something is on the continent you need to know their place within map_rect on the map, then fit map_rect inside continent_rect on the continent.
So you have to do basically this:
I was using a numpy matrix, but even if I only built it once per map your pile of random characters is a lot faster.
All condensed in one ugly block of code so I don’t have to look at it so much:
def continent_coords(continent_rect, map_rect, point, game=False): return ( (point[0]-map_rect[0][0])/(map_rect[1][0]-map_rect[0][0])*(continent_rect[1][0]-continent_rect[0][0])+continent_rect[0][0], ((-point[1] if game else point[1])-map_rect[0][1])/(map_rect[1][1]-map_rect[0][1])*(continent_rect[1][1]-continent_rect[0][1])+continent_rect[0][1] )
PHP version here: https://github.com/codemasher/gw2-database/blob/master/classes/gw2api.class.php#L248
JS version: (can’t find it…)
Side.3489:
Don’t worry about the JS version i’m working in C# here, the PHP was clear enough to replicate it on my end
But….
What does this code actually do ?
Gives the objective coordinates in the map_rect ?
Where is the origin point of the resulting coordinates ? (top-left ? center ?)
Just to make sure it’s said : I’m not trying to place the objectives in a Continent map, but in a “Borderlands” map
Just so I know how to handle that afterwards
(Still trying to work things out on my end but in the event you’re faster to answer than me to find out…)
smiley.1438:
Wait no. (it’s been a hard day…)
The above answer is correct when you get the coordinates from ingame, e.g. the Mumble link or the /v1/event_details API. It translates the relative map coordinate system into the continent’s absolute.
The solution to your problem is simpler: just don’t use the map_rect at all. continent_rect is what you need since the coordinates in the /v2/ APIs are already calculated to absolute.
Side.3489:
Np, can understand that :p
Ok so what i did in my first post is good, just change the map_rect with continent_rect ?
smiley.1438:
I think, you’re pretty much looking for this: https://gist.github.com/codemasher/75d8e1a24b2363cabebf
Side.3489:
Huuum, nope, don’t think that was what I looked for ^^’
But….
Got that one !
It’ late and i stumbled a little on the map size….. Silly me.
Thanks for the tip for the continent_rect though
For future reference :
https://github.com/sidewinder94/GWvW_Overlay/blob/cb024272cbe41b3ce703434209f78b158d1d34b5/ArenaNET/Objective.cs#L29
Side.3489:
Not on topic !
Marked this as a Q/A and it turned to be a discussion…. I don’t seem to be able to remove the Q/A format…. if someone with moderators rights could do this, i’d be grateful