I'm currently at a loss rendering a tile-based 3D map with an orthographic projection in OpenGL. Imagine any isometric 3D game (using actual geometry instead of sprites).
Internally, the tiles of my map have x
and y
coordinates (for column
and row
position within the map respectively). The tile with x=0
and y=0
is the one in the "top left", the one with y=0
and x=1
the one to the right of the first tile and so on.
Since in OpenGL, the coordinate system is so that the X-Z-plane is the "ground" plane, I create the model matrix for each tile by using the tile's y
coordinate for the matrix' (or position vector's) z
component. I then set up an orthographic "camera" by using glm::ortho()
.
This seems to work fine at first, but I quickly ran into clipping issues when trying to render larger parts of the map. I assume this is due to the fact that the orthographic projection clips on z
. A quick and dirty attempt of having the map in the X-Y-plane confirmed this, as I didn't have clipping issues then.
Now, I'm not sure what's the best approach here?
- Change the code so the tiles are being layed out in the X-Y plane? In that case, it seems as if I would have to remember to rotate every single object around x accordingly, which seems wrong.
- Do I need to set up the orthographic projection manually to use Y as the clipping plane? Is that even possible? I think OpenGL always uses z for clipping, right?
- Some other approach? I think I'm lost in coordinates and matrices, really.
I assume this is a common problem with a well-known solution, so I'm hoping to learn about that before I go ahead, change a lot and then learn I did it the wrong way...