Hi. I've tried to figure this out myself, but I get extremely confused with coordinate system handedness after coming to 3D graphics from just working in 3D editors.
I am writing a program where a camera orbits a target from a fixed distance, and all I am rendering is just a height-displaced floor composed of just a simple square grid. In my world space, +x points to the right, +y points up, and +z points forwards.
To start everything, I take the target position and find where the camera should be located using these steps:
- Place camera at (0,0,-M)
- Rotate about x axis
- Rotate about y axis
- Translate to target position
This gives me the camera position in world space (this is all done using standard vector math, and is not part of the renderer pipeline).
I then plug this camera position and target position into a LookAt function to derive the world-to-camera matrix that my renderer will proceed to use… but this is where the problems start.
Let's say that my camera is located at (0,1,0), and I am looking at the point (0,0,1), both in world coordinates:
The resulting view matrix (to be multiplied with a column-vector vertex) is:
Such a matrix makes perfect sense for a right-handed coordinate system that assumes +z points backwards (since as far as the LookAt function is concerned, my camera was placed M units /in front of/ the target and is now turning around to look at it), but at this point during the camera setup, I am still working in world coordinates where the opposite is true.
Now with all that explanation out of the way, this is the situation:
The square grid I am rendering is actually a tilemap:

My setup is to shoot rays corresponding to the corners of the view space, and draw all cells that are within the view volume. This was fully functional in an earlier setup, but broke after I cleaned up and standardized all my 3D maths to use a right-handed coordinate system (I'd previously been using a hacked-together setup that was a mix of RH and LH and other nonstandard stuff until “it worked”). The way it's breaking is that everything has been horizontally mirrored (as expected from the example matrix earlier), and /something/ is off about what is actually being rendered (I have a reference of what it looked like before and after, and it's not the same even after accounting for the mirroring).
So finally, my question is: For a setup like the above, where I'm just rendering a grid, what is the “most correct” way of handling things? Do I just force everything to use the “+z = backwards” convention (including creating the grid's vertices to face the -z direction), or is there something really dumb that I'm missing here?

