Hi Everyone, Jonathis here again. I am still whiling away on my Monster and Me 2.5 Client rebuild project. Looking for some help on the TQ Coordinate system, as I am not getting expected results. I have confirmed MaM uses the same coordinate system as Conquer Online, and read through a number of posts regarding the calculations, including the extremely useful post found here by unknownone: [Only registered and activated users can see links. Click Here To Register...]
The map dimensions are the following:
pixels: 3840 x 2400
tiles: 135 x 135 (according to the map file)
tile size is the standard 64 x 32
So here's my problem... Mouse Coordinate to Map Coordinate works nearly perfectly utilizing unknownone's algorithm:
I cross referenced the given coordinates in quite some detail with the coordinate system in game, with the only hiccup being the x coordinate was always 1 off. I can fix that by adding 1 to it, though I'm not completely sure why it is off given the above. Once I add the 1 offset, I get exact matches to the ingame coordinates.
Now comes the problem. I try to do the reverse, and apply the Map Coordinate to Screen Point algorithm, and get very odd results. Below is the implemented algorithm.
With this, I get a seemingly accurate x position, as can be seen by how the bounding rectangle bounds a tile that is in alignment with my mouse position. I am not completely sure it is right though, because the 0,60 calcs look iffy. The Y axis is definitely wrong though.
[Only registered and activated users can see links. Click Here To Register...]
Instead of starting in the middle, I figure take a simple example
The top left corner of the map is the coordinate 0,60. If I plug in the above I get the following results:
x = (0-60) * 32 + 1920 = 0
y = (0 + 60 - (135 - 1)) * 32 + 1200 = -49 * 32 + 1200 = -1168
Given the first tile origin is the very top left corner for the map, I would expect the tile and bounding rectangle to only be a quarter visible. Thus expected x and y should be -32,-16. Definitely not right! If I subtract an extra 1 from the x coordinate, I get the expected x values (which is obviously because I had to add 1 earlier). Still, the Y coordinate is really puzzling me.
If anyone has any suggestions, I'd much appreciate it. Thanks :)
The map dimensions are the following:
pixels: 3840 x 2400
tiles: 135 x 135 (according to the map file)
tile size is the standard 64 x 32
So here's my problem... Mouse Coordinate to Map Coordinate works nearly perfectly utilizing unknownone's algorithm:
Code:
int tempX = mouseX - (mouseX % tileWidth); int tempY = mouseY - (mouseY % tileHeight); int coordX = tempX / tileWidth + tempY / tileHeight; int coordY = tempY / tileHeight + (map->width - tempX) / tileWidth; //Array replicating 'Rainbow Tile' int posX = mouseX - tempX; int posY = mouseY - tempY; if (tileZone[posX][posY] == TileZone::TOPLEFT) coordX--; else if (tileZone[posX][posY] == TileZone::TOPRIGHT) coordY--; else if (tileZone[posX][posY] == TileZone::BOTTOMLEFT) coordY++; else if (tileZone[posX][posY] == TileZone::BOTTOMRIGHT) coordX++;
Now comes the problem. I try to do the reverse, and apply the Map Coordinate to Screen Point algorithm, and get very odd results. Below is the implemented algorithm.
Code:
SDL_Point GameMap::mapCoordinateToPoint(int x, int y) {
SDL_Point newPoint;
newPoint.x = (x - y) * tileHeight + (map->width / 2);
newPoint.y = (x + y - (mapTileHeight-1)) * (tileWidth / 2) + (map->height / 2);
return newPoint;
}
[Only registered and activated users can see links. Click Here To Register...]
Instead of starting in the middle, I figure take a simple example
The top left corner of the map is the coordinate 0,60. If I plug in the above I get the following results:
x = (0-60) * 32 + 1920 = 0
y = (0 + 60 - (135 - 1)) * 32 + 1200 = -49 * 32 + 1200 = -1168
Given the first tile origin is the very top left corner for the map, I would expect the tile and bounding rectangle to only be a quarter visible. Thus expected x and y should be -32,-16. Definitely not right! If I subtract an extra 1 from the x coordinate, I get the expected x values (which is obviously because I had to add 1 earlier). Still, the Y coordinate is really puzzling me.
If anyone has any suggestions, I'd much appreciate it. Thanks :)