## Isometric Tile Plotting

Piller187
Unregistered

Post: #16
I'm not following that at all.

OK so here is my tile:

I have 4 corners to the image, and 4 corners to the diamon shape inside the image. Can you relate to what you said to this tile image?

And actually some code is nice. I usually read code better than theory.

On a side note, what I got out of the drawing code from the website you posted was:

Code:
```for(row=0;row<MAP_ROW;row++)         {             for(col=0;col<MAP_COL;col++)             {                 drawX = col * (TILE_W/2) - row * (TILE_W/2);                 drawY = col * (TILE_H/2) + row * (TILE_H/2);                        }                 }```

Which is fine but it produces:

I thought the top one was supposed to show the middle of it
Moderator
Posts: 776
Joined: 2003.04
Post: #17
Quote:I have 4 corners to the image, and 4 corners to the diamon shape inside the image. Can you relate to what you said to this tile image?

Yes: The four corners I mentioned are the diamond's corners.

Quote:And actually some code is nice. I usually read code better than theory.

Sure... but I already gave you the code! Isn't the "fun" of making games actually making them?

OK, the code is fine, and in fact if you run thru it by hand, giving values to row, col and calculating the resulting values (drawX & drawY), you'll see that whatever is causing the "extra 32 pixels to the right" rendering is not in that code. Here are the results you get if you do the calculations by hand, following that code:
Code:
```(0,0) -> (0,0) (0,1) -> (-32,16) ... (1,0) -> (32,16) (1,1) -> (0,32)```

Why is it in the wrong position then, since the values are OK? Take a look at the tile picture you posted. When you draw, you are probably using drawX & drawY directly, but remember that those are the values for the top corner of the diamond, you seem to be taking them to be the coordinates of the top-left corner of the rectangle, which happens to be 32 pixels to the left.
So, just correct that (subtract 32 from drawX) and it should work as expected.

Note: Instead of
Code:
```drawX = col * (TILE_W/2) - row * (TILE_W/2); drawY = col * (TILE_H/2) + row * (TILE_H/2);```

just use
Code:
```drawX = (col - row) * (TILE_W/2); drawY = (col + row) * (TILE_H/2);```

Also, if you want to center the board on the middle of the screen, just add screenWidth/2 to your drawX variable.
Piller187
Unregistered

Post: #18
Quote:Sure... but I already gave you the code! Isn't the "fun" of making games actually making them?
Not when you've been trying to get this to work for many months, and no one seems to know what is going on, or are not willing to help you. But you seem to be a good job at it.

Now that is my drawing code. But the screen to map isn't working. I have:

Code:
```            screenX = mouse_x;             screenY = mouse_y;             testCol = screenY/TILE_W + screenX/TILE_H;             testRow = screenY/TILE_W - screenX/TILE_H;             mapCol = testCol;             mapRow = testRow;             if(mapCol > -1 && mapCol < MAP_COL && mapRow > -1 && mapRow < MAP_ROW)                 map[mapRow][mapCol].image = highlighted;```

At the moment I'm leaving the map centered at the top left of the screen, so I don't have to mess with offsets. Once I get this working I will do offsets. So what am I doing wrong with my screen->map coords?
Sage
Posts: 1,403
Joined: 2005.07
Post: #19
The easiest way to deal with converting a screen coordinate to an isometric system is to do a point in rectangle (by division) test for every even numbered row then a lookup, using an image like this:

(but with the four pink corners colored differently), do a lookup test and if its inside the tile then you already have the coordinate, if not you will need to add or subtract one from the y coordinate and modify the x as well.

This is slightly more complex with a diamond shaped system, its easier to deal with a staggered isometric layout but its easily adaptable.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Piller187
Unregistered

Post: #20
Ah, see I thought that article on the website where converting screen->map was used to check if mouse was in the tile (Diamond) area. So it's really not that simple. That is where my confusion was. So if the screen->map conversion on that website isn't for mapping the mouse, what is it used for?

If that's the case I'll just do a point in triangle, and make 2 triangles for each tile that represent the diamond.
Sage
Posts: 1,403
Joined: 2005.07
Post: #21
You could use it to test if it was inside the tile, but if it isn't you have to do another lookup for the odds. I prefer the other way though because it leads you to the answer immediatly (in one test).

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Moderator
Posts: 776
Joined: 2003.04
Post: #22
Quote:The easiest way to deal with converting a screen coordinate to an isometric system is to do a point in rectangle (by division) test for every even numbered row then a lookup, using an image

Er... easier than not using an image and not doing a pixel lookup followed by a switch based on the color of the pixel?
Sorry, that doesn't seem easier to me, compared with a simple transformation which accounts to nothing more than a sum and two divisions for each coordinate, giving you the selected diamond tile in one step.

Piller187 Wrote:Ah, see I thought that article on the website where converting screen->map was used to check if mouse was in the tile (Diamond) area. So it's really not that simple.

Yes, it is. Look at one of my previous posts (#13). The code I posted was:
Quote:mapX = screenY/32 + screenX/64
mapY = screenY/32 - screenX/64

In your code, mapX is testCol and mapY is testRow. So, the problem is that you've got TILE_W where it should be TILE_H and vice versa. The correct code would be:
Code:
```testCol = screenY/TILE_H + screenX/TILE_W; testRow = screenY/TILE_H - screenX/TILE_W;```

Possibly Related Threads...
 Thread: Author Replies: Views: Last Post Plotting a line through a grid cloke 3 2,897 Aug 22, 2004 08:50 PM Last Post: cloke Isometric tile plotting and such CarbonX 2 2,968 Aug 13, 2003 04:33 PM Last Post: aaronsullivan