Should I use the X-Y-plane when using an orthographic projection in OpenGL?

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

No, you don't need to rotate each object, you can just modify your projection matrix accordingly.

How to do that is explained below, but first I need to make some things clean.

in OpenGL, the coordinate system is so that the X-Z-plane is the "ground" plane

This is not true. XZ plane being ground is a widely-used convention, but OpenGL does not enforce it in any way.

There is such thing as a window plane, which is XY, and you can't change it. But it is completely unrelated to the issue.

A quick and dirty attempt of having the map in the X-Y-plane confirmed this, as I didn't have clipping issues then.

You seem to have done something wrong. It should work completely same. Simply saying, the clippling is done in "window space" (not a proper term), so it does not matter in which coordinate system you have your world, only camera settings matter.

Also, you should know that stricly saying all 3 axes are clipped. You can see Z clipping when objects dissappear in the distance or when you get too close too them, but you can't really see X and Y clipping, because it happens right where your window frame is.

To swap the axes you need to multiply your projection matrix by

1  0  0  0
0  0  1  0
0 -1  0  0
0  0  0  1


if you want world Z to become camera Y and world Y to become camera -Z.

Or by

1  0  0  0
0  0 -1  0
0  1  0  0
0  0  0  1


for Z -> -Y and Y -> Z.

Just try both to see which works better.

• This was an eye opener. Sometimes it really helps to get some input on stuff when your brain is stuck in the same thought pattern for hours. Thank you! This answered my question(s) and the second matrix works perfectly for my purpose. – domsson Aug 26 '16 at 1:02