View Single Post
  #157  
Unread 01-07-2005, 09:14 PM
SOE_Bobble SOE_Bobble is offline
EQII Developer
Yes this person is from Daybreak!
 
Join Date: Aug 2004
Posts: 82
Default How to determine ZoneRect

To end the suffering -- there is a simple formula to calculate the ZoneRect if you know a bit of information about the map and the zone.

You must know the /loc at 2 map locations. The ideal locations are the two opposite corners of the map. But if you had that, you wouldn't need the math. Any points will do -- but the farther apart the points, the more accurate the calculation.

Round worlds do not map exactly to flat maps but the areas in EQII are either small enough or perhaps the world is actually flat and so we don't need to worry about the projection used or any of the other more complicated cartography details.

So as far as we are concerned, the distance on the map is a constant and thus simple ratios work. The fundamental ratio is:
Code:
    locB - locA      locC - locD
  --------------- = ---------------
   mapB - mapA       mapC - mapD
(We know mapA, locA, mapB, locB, and mapC. So if we make point D the same as point A or point B, we know everything but 1 variable -- locC.)


To simplifiy, what we need to do first is calculate the world_distance_per_pixel in both x and y. That is the left side of the equation above.

LOC_Bx - LOC_Ax
-------------------- = wdpp_x (and repeat for wdpp_y)
MAP_Bx - MAP_Ax

LOC_Ax is the game x coordinate for location A.
MAP_Ax is the map x coordinate for location A.
Point A should be near the top-left and PointB should be near the bottom-right. But they don't have to be.

Unless the map is distorted, wpdd_x and wpdd_y should match.

Now solving the same equation for LOC_0x leads us to:
LOC_0x = LOC_Bx - (wdpp_x * (MAP_Bx - MAP_0x) )

Andn using the point farthest from the bottom we get:
LOC_1x = (wdpp_x * (MAP_1x - MAP_Ax) ) + LOC_Ax

Repeat for LOC_0y and LOC_1y.

LOC_0x is the game x coordinate for the upper left corner.
We know MAP_0x and MAP_0y is 0.
You should also know the MAP_1x, 1y, it is the map size.

Someone should check my math and double check the signs.
MrBobble