09.02.2014, 22:24
Bottom left corner of the map is x = -3000, y = -3000 by default.
When you get your coordinates (GetPlayerPos for example), add 3000 to both the x and y coordinates.
Then your virtual coordinates in the bottom left corner is x = 0, y = 0, while the upper-right corner is x = 6000, y = 6000.
Dividing those by 60 gives you the grid you want (squares of 60x60 meters, 100 divisions in both directions).
To find the square you're in:
- get your coordinates (GetPlayerPos)
- add 3000. to both x and y
- divide those by 60.0
Then you have the X and Y positions of the grid.
You could give ID's to them by multiplying the X by 100, then add Y to that.
Example:
GetPlayerPos returns x = 1245 and y = 784.
We add 3000 to those:
x = 4245, y = 3784.
Divide both by 60:
x = 70.75, y = 63.06 (rounded down: x = 70, y = 63)
Square ID: (70 x 100) + 63 = 7063.
Example 2:
GetPlayerPos returns x = -2997 and y = -2998 (near bottom left corner).
Add 3000: x = 3, y = 2
Divide by 60: x = 0.05, y = 0.033 (rounded down: x = 0, y = 0)
Square ID: (0 x 100) + 0 = 0.
Example 3:
GetPlayerPos returns x = 2998, y = 2995 (top left corner)
Add 3000: x = 5998, y = 5995
Divide by 60: x = 99.96, y = 99.91 (rounded down: x = 99, y = 99)
Square ID: (99 x 100) + 99 = 9999.
When you get your coordinates (GetPlayerPos for example), add 3000 to both the x and y coordinates.
Then your virtual coordinates in the bottom left corner is x = 0, y = 0, while the upper-right corner is x = 6000, y = 6000.
Dividing those by 60 gives you the grid you want (squares of 60x60 meters, 100 divisions in both directions).
To find the square you're in:
- get your coordinates (GetPlayerPos)
- add 3000. to both x and y
- divide those by 60.0
Then you have the X and Y positions of the grid.
You could give ID's to them by multiplying the X by 100, then add Y to that.
Example:
GetPlayerPos returns x = 1245 and y = 784.
We add 3000 to those:
x = 4245, y = 3784.
Divide both by 60:
x = 70.75, y = 63.06 (rounded down: x = 70, y = 63)
Square ID: (70 x 100) + 63 = 7063.
Example 2:
GetPlayerPos returns x = -2997 and y = -2998 (near bottom left corner).
Add 3000: x = 3, y = 2
Divide by 60: x = 0.05, y = 0.033 (rounded down: x = 0, y = 0)
Square ID: (0 x 100) + 0 = 0.
Example 3:
GetPlayerPos returns x = 2998, y = 2995 (top left corner)
Add 3000: x = 5998, y = 5995
Divide by 60: x = 99.96, y = 99.91 (rounded down: x = 99, y = 99)
Square ID: (99 x 100) + 99 = 9999.