• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Relating In Game Coordinates to Location on a Pictuere of Game Minimap

Status
Not open for further replies.
Level 6
Joined
Sep 19, 2005
Messages
169
I made some risk maps that send data of when cities are captured. The website interprets the data live and takes a minimap image and changes pictures on it based on who now owns the city.

Essentially its a live minimap with buildings only. I would like to add more images to the minimap of data going on in the game, but I'm wondering if there is any way I can relate the ingame location to the coordinates of the minimap image whilst opened in photoshop, for example.

Here is what I'm talking about, just click on any recent game to see the minimaps:
http://www.risknextgen.com/handler.php?request=games:stats


I want to add more data, such as locations of specific types of units. The building location was easily done because they are pre-placed.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You need to explain the coordinate system of photo shop more clearly. I use paint shop pro which uses pixels for coordinates.

The WorldEdit minimap is generated from the playable map bounds. Locations in WarCraft III use a map defined origin of (point 0,0) that is usually the middle of the map (in theory it could be anywhere).

What you want to do is translate from absolute WC3 coordinates into minimap relative coordinates. From this fractional quantity you can then compute the centre of the icon you want to place in a separate step.


1. Basic translation constants
Every tile in WarCraft III is about (floating point precision) 128 units in height and width. As the centre (0,0) is in the middle of the map you can compute the offset of the centre as half the map height times 128.

Example
64*64 sized map
The offset will be in the middle meaning 32 tiles up from the south edge and 32 tiles right of the west edge of the map.

xoff = 64*128/2 = 4096
yoff = 64*128/2 = 4096

This is the offset of the origin of the map. We can use this to find the absolute position of any unit with respects to the lower left of the map.

Alternative you can read it from...
Scenario -> Map Size and Camera Bounds...
It is the Negative Map values.

2. Map bounds translation constant
The Playable area define the area of the minimap and are smaller than the actual map. To do a proper translation of coordinate space we need to know the low and high bounds of the playable area.

Example...
I measured to the nearest tile (last tile mostly not off bounds) using my cursor. Results for default map...
Right = 7424
Left = 768
Top = 7168
Bottom = 512

I already added 4096 to them to translate them to absolute map locations.

3. Playable map size constants.
Simple offset mathematics to find the size of the playable map area.

Example...
Width = Right - Left = 6656
Height = Top - Bottom = 6656

4. Location offset constants.
A simple optimization for later. Instead of translating to absolute map position and then to playable area position we can go straight to playable area position.

Example...
lxoff = xoff - Left = 4096 - 768 = 3328
lyoff = yoff - Bottom = 4096 - 512 = 3584

5. Translating a location and normalizing it
Using the location offset constants we can quickly translate a location to be relative to the playable field area. By normalizing this using the playable field size we get a fractional value.

We have a location with components x and y.
outx = ( x + lxoff ) / width
outy = ( y + lyoff ) / height

Example...
If we have a unit at -1427.2 and -2577.1 then...
outx = ( -1427.2 + 3328 ) / 6656 = 0.28557692307692307692307692307692
outy = ( -2577.1 + 3584 ) / 6656 = 0.15127704326923076923076923076923

This is the value you send to your servers as a real. The precision might not be as high as shown above but will be more than enough for a reasonable sized image.

6. Converting to a picture.
This is if you want a pixel offset from your fraction (mostly GPU stuff will use the fraction directly). It is a matter of multiplying by image size and compensating for the integer nature that images have.
pixelx = round( outx * ( imagex - 1 ) )
pixely = round( outy * ( imagey - 1 ) )

Example...
Say we have a 64*64 pixel mini-map and want the centre pixel of the previous example.

pixelx = round( 0.28557692307692307692307692307692 * ( 64 - 1 ) ) = 18
pixely = round( 0.15127704326923076923076923076923 * ( 64 - 1 ) ) = 10

This is in pixel space from the lower left corner assuming elements run from [0 to dimension - 1] pixels. Add 1 if it runs from [1 to dimension] pixels.

If the images are not centre aligned, then a offset will be required to compensate.
 
Level 6
Joined
Sep 19, 2005
Messages
169
Wow thanks dsg. You are sure of the accuracy of your post though right? Not to second guess you, but this is not something I can probably figure out or edit your idea to fit my needs, so if your post is incorrect at all I'm fucked :p.

I actually use paint.net which is a free similar image editing program. I know photoshop and paint.net both go off of pixels, so I would assume most image editing programs do the same.
 
Status
Not open for further replies.
Top