1
\$\begingroup\$

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...)?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$

You must log in to answer this question.

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