Prince of Persia (1989) uses oblique projection – the same as is used for furniture diagrams – to give a sense of depth to an otherwise flat 2D platformer.
The problem is that oblique projection, while it gives an intuitive depiction of objects, is not really physically possible, for say a camera.
To do any kind of realistic lighting of a game in this perspective, we need to understand how the light rays are received by the camera.
We can write down, just by looking at the screenshot, the screen space coordinates for some world space coordinates :
up to a choice of origin, for some scaling factors . We have noticed here that the lines of depth in the screenshot go along two pixels for every one they go up, to give smooth lines in the pixel art, at a good angle.
This gives a coordinate conversion, but we have no idea which direction the light rays are coming in, so we could not position reflections. We also do not know how far points in the world are from the projection plane.
Oblique projection, and parallel projection in general, is based upon light rays in a particular direction hitting a plane.
The difference between a perspective camera and a parallel camera is easily thought of as the difference between a point light and a directional light. In the same way we can think of a directional light as a point light at infinity (that is, in some sense, infinitely bright), we can think of an orthographic camera as a perspective camera at infinity (with infinite zoom).
An orthographic camera is one where the normal of the plane and the direction of incoming light are opposite. The particular case of isometric perspective is given by (given that we want and both to be unit vectors) .
In general, a point on the projection plane satisfies (if we assume the plane goes through the origin)
and projecting a point in world space in the direction by a distance gives a coordinate
Putting these together gives , so that
which gives the projected position as
To convert this into screen space coordinates, we must choose basis vectors on the plane. These ought to be orthogonal, so that .
Then we have screen space coordinates
Comparing this with the original formula for the projection we wrote down earlier, it seems we should take
and let .
Equating the two forms then gives and .
We also need, for a unit vector,
so , where we have taken the negative square root so that points in the opposite direction to . So we can finally write down
It seems sensible to take , so that squares appear as squares, and in the case of Prince of Persia, we might guess that the pillars in the screen shot have a square cross section, giving , so . Of course, this value can be varied to taste.
That would give . In screen space, this maps to the zero vector, as expected. Reflections off the floor would have light rays , which maps to the screen space vector , so since there is no horizontal component, reflections appear below objects, and we can now calculate the correct distance.