3
\$\begingroup\$

How would I check if an object is inside the bounds of an isometric chunk? for example I have a player and I want to check if its inside the bounds of this isometric chunk. I draw the isometric chunk's tiles using OpenGL Quads.

My first try was checking in a square pattern kind of thing:

e = object;
this = isometric chunk;

    if (e.getLocation().getX() < this.getLocation().getX()+World.CHUNK_WIDTH*World.TILE_WIDTH && e.getLocation().getX() > this.getLocation().getX()) {
        if (e.getLocation().getY() > this.getLocation().getY() &&   e.getLocation().getY() < this.getLocation().getY()+World.CHUNK_HEIGHT*World.TILE_HEIGHT) {
            return true;
        }
    }
    return false;

What happens here is that it checks in a SQUARE around the chunk so not the real isometric bounds. Image example: (THE RED IS WHERE THE PROGRAM CHECKS THE BOUNDS)

What I have now:

enter image description here

Desired check:

enter image description here

Ultimately I want to do the same for each tile in the chunk.

EXTRA INFO:

Till now what I had in my game is you could only move tile by tile but now I want them to move freely but I still need them to have a tile location so no matter where they are on the tile their tile location will be that certain tile. then when they are inside a different tile's bounding box then their tile location becomes the new tile. Same thing goes with chunks. the player does have an area but the area does not matter in this case. and as long as the X and Y are inside the bounding box then it should return true. they don't have to be completely on the tile.

\$\endgroup\$
9
  • \$\begingroup\$ Are objects just points, or do they have an area? What are the coordinates? Can an object move freely or tile-by-tile? Does it matter if object isn't completely on a tile? \$\endgroup\$ Commented Sep 21, 2012 at 10:45
  • \$\begingroup\$ Till now what I had in my game is you could only move tile by tile but now I want them to move freely but I still need them to have a tile location so no matter where they are on the tile their tile location will be that certain tile. then when they are inside a different tile's bounding box then their tile location becomes the new tile. Same thing goes with chunks. they do have an area but the area does not matter in this case. and as long as the X and Y are inside the bounding box then it should return true. they don't have to be completely on the tile. \$\endgroup\$ Commented Sep 21, 2012 at 10:55
  • \$\begingroup\$ possible duplicate of Isometric rendering and picking? \$\endgroup\$
    – bummzack
    Commented Sep 21, 2012 at 11:04
  • \$\begingroup\$ Instead of trying to figure out whether some point is in some tile, it might be easier to track the current tile for each object. \$\endgroup\$ Commented Sep 21, 2012 at 11:13
  • 1
    \$\begingroup\$ You need to separate your drawing code from your data structures for storing your world and objects. The world and objects should simply be stored in a 2D or 3D array, then drawn in an isometric representation. You're really confusing things if you're trying to store everything in a isometric fashion. \$\endgroup\$
    – House
    Commented Sep 21, 2012 at 14:29

2 Answers 2

3
\$\begingroup\$
e = object;
this = isometric chunk;

//for readability(long version)//

pointX = e.getLocation().getX();
pointY = e.getLocation().getY();


chunkSizeX = World.CHUNK_WIDTH  * World.TILE_WIDTH;
chunkSizeY = World.CHUNK_HEIGHT * World.TILE_HEIGHT;


chunkCenterX = this.getLocation().getX() + chunkSizeX / 2.0;
chunkCenterY = this.getLocation().getY() + chunkSizeY / 2.0;


deltaX = pointX - chunkCenterX;
deltaY = pointY - chunkCenterY;

if(deltaX < 0) deltaX *= -1;
if(deltaY < 0) deltaY *= -1;

//these two are floating point number

distanceX = deltaX / chunkSizeX;
distanceY = deltaY / chunkSizeY;

if(distanceX + distanceY < 1.0) return true
else return false;

Basically, imagine each player starts in the center of the chunk. Assuming the player can only move: up, down, left and right and speed is adjusted proportionally when moving on the y-axis to:

TILE_HEIGHT / TILE_WIDTH * X_AXIS_SPEED

She will need at least n steps to get out of the player will need exactly n steps to get out. of the chunk area. I will not prove this unless requested. Therefore, we just check if the player took 100% of the necessary steps to get out of the chunk.

\$\endgroup\$
3
\$\begingroup\$

Have a look to my answer to Finding out which tile a mouse click landed in. Your error here is to forget that the isometric has a different coordinate system from the one used on the screen.

You should consider to store the players coordinate position in term of isometric coordinates; the position in term of (x-tile-index-and-fractions,y-tile-index-and-franctions) may work and help your game logic to be thought of as if it lives in an isometric world.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .