• Advertisement

Archived

This topic is now archived and is closed to further replies.

Zero Point in Isometric

This topic is 5267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been using an isometric engine for quite a long time, and feel very stupid for not noticing this before now. But here goes anyway: My tiles are 128x63 bitmaps of diamonds, but this problem would pertain to anything such as 64x31, 32x15, ect. The structure of the tile is like this (if this keeps shape):
      OOOO
    OOOOOOOO
  OOOOOOOOOOOO
OOOOOOOOOOOOOOOO
  OOOOOOOOOOOO
    OOOOOOOO
      OOOO  
Mine are much larger, but this is the same formation of pixels. And this would be the formation of the diamond tiles in my map:
    O
Z  O O  X
  O O O
 O O O O
  O O O
   O O
    O  
It would be a bit shorter in height, but you get the idea. I consider my zero point tile to be the top-most tile shown. The zero point of that tile would be in between the 4 top pixels shown on the first (picture?) thing. So how is that possible? To have a point in between those pixels? My problem is that my mouse is being translated into being over a tile when it's one pixel off of it. I know this is very hard to understand. The way I translate screen to world positions puts the zero point on the 3rd-pixel counting from the left to right (since I don't see how I could use a location in-between pixels). In other words, if my tiles had an odd number of top pixels (instead of 4), I could safely use the middle pixel as zero. This is my screen to world code: WorldX = (ScreenX >> 1) + (ScreenY); WorldZ = (ScreenY) - (ScreenX >> 1); (The reason I'm leaving the shifts is because dividing by 2 will return different (but still not correct) results). I can make everything OK by just adding (+ 1) to WorldX. Because X's 0 is starting on that 3rd pixel over, and from Z's point of view, it's 0 (the same pixel as X's 0) is on the wrong side, and is always one behind. If I were to subtract one from Z, it makes my mouse off on both axes instead of just X, so I'm almost sure I need to modify X. When I add one to X, it's 0 point ends up being the 2nd pixel over, and Z's will still be the 3rd. Like I said, I know this is very confusing, and I'm probably not making it better with my explanations and terrible diagrams. But if anyone has any clue about what I'm saying, I would really appreciate any input. Thanks Jiia [EDIT - I'm adding this to my list of problems ] If adding one to X (or whatever the fix may be) will fix this problem, will I also need to fix my world-to-screen code? Would I do that by doing the opposite and subtracting one from WorldX before I convert? This is that code: ScreenX = (WorldX - WorldZ); ScreenY = (WorldX + WorldZ) >> 1; Thanks again for any help [edited by - Jiia on August 16, 2003 3:41:31 AM]

Share this post


Link to post
Share on other sites
Advertisement
You might want to consider the approach explained in this article for performing tile picking. It's fairly straightforward, it shouldn't take that much tweaking to adapt your application to it if you decide you like it, and it will definitely solve the problem you're having now.

HTH

[Edit: Forgot to mention that the 'Mouse Matters' section is the one you're looking for.]

[edited by - SysOp_1101 on August 16, 2003 4:11:16 PM]

Share this post


Link to post
Share on other sites
I don''t have much of a problem figuring out which tile the mouse is over. My game needs to know the exact world location of the mouse, not just the tile it''s over. Thanks for the try though. It''s more than anyone else did.

I went ahead and added +1 to WorldX and everything turned candy. It''s all perfect (or at least seems to be). The reason I was asking about it was to see if I was doing something wrong to begin with. But I''m pretty sure it''s just because the center point of the tile needs to be different pixels for X and Z.

Anyway, I would still like to hear if anyone has a better idea.

Jiia

Share this post


Link to post
Share on other sites
have you ever considered that each of the tiles in your tile map are actually smaller tilemaps?

you are currently using 128x64 (when specifying tile sizes, i include the extra blank row of pixels on the bottom of the image). i, too, always use 2:1 aspect ratios for my iso tiles, as it makes the edges smoother than other aspect ratios, although i''ve done weird sizes, like 24x12 most recently(pocketpc game). also, my tiles always have a width that is a multiple of 4.

anyway, one thing that we can say about 2:1 aspect ratio tiles like these are that the topmost row contains 4 pixels that are within the tile itself, and that these can be broken down into smaller tiles that are factors of the original width.

the smallest possible tile like this is the 4x2 tile, which has a total of four visible pixels in it.

you can fill up any sized tile that has a 2:1 aspect and multiple of 4 width with 4x2 tiles, like so:

@@AAAA@@
BBBBCCCC
@@DDDD@@

A represents subtile(0,0), B subtile(0,1), C subtile (1,0) and D subtile (1,1). your coordinate system may vary.

what does this mean to you? simply this: if you can detect what tile the mouse is on, then you can also determine which subtile within that tile the mouse is on. a combination of tile and subtile indicate world position.

and, for even greater granularity, there are four positions within each subtile: far west, near west, near east, far east. that''s pixel granularity, and you just can''t get better than that on a raster display.

Share this post


Link to post
Share on other sites

  • Advertisement