Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a big map with isometric tiles(3d camera), how can i draw only visible tiles ?

Whats the best way to do that ? space partitionning (octrees etc...)?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

If all the tiles are approximately the same size, lie roughly on a flat plane, and the camera is always a set distance from the plane, simply calculate the tile that the camera is looking directly at and then cull any tile whose distanceSquared() from the looked at tile is greater than a value that would place it outside the FOV.

When considering the 'value', consider the obliqueness of the vertical component of the FOV when using an isometric perspective.

Further optimization can be had by doing the same with small groups of tiles rather than each tile individually.

This method will usually give a number of false positives but will cull the vast majority in a big map situation and is relatively cheap.

share|improve this answer

Figure Out a visible rectangle of tiles. Only draw that. Isometric vies complicate things, but only slightly. Simply start at the leftmost, topmost tile and draw that row. Then the next. You should be able to convert between screen and world space, so converting and visible spot on the screen aligned visible rect to tile coords should be straightforward. It depends on your internal representation of the game world, so it's hard to give more specific math.

Spatial partitioning will help more with very very worlds. A simple fixed-scale quad tree is fine. Or even fixed size chunks.

share|improve this answer

This approach works for diamond shaped isometric maps.

1) Find out what the top left tile on the screen is.

2) Depending on how you draw the map offset this by 2 tiles in both directions off the screen. So now you chosen a tile outside the viewport area.

3) Calculate how many horizontal rows and how many vertical rows need to be drawn so you end up on the opposite site of the viewport.

4) Now draw your map row by row.

for (int row = 0; row < rowCount; row++)
{
for (int col = 0;col < colCount; col++)
{
tileXtoDraw = topLeftTile.x + col + (row / 2) + (row%2) //modulus there for each other row
tileYtoDraw = topLeftTile.y - col + (row / 2);
//check if this tile is within the map region(no -10 or more then length)
//
//Draw your map as you normally do. tileXtoDraw and tileYtoDraw are 
//just the [x,y] in the array, you just iterate them differently.
}
}

Hope this helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.