Looking around

If you look at the screenshot right at the top of the page, you'll see that the view is not dead on. In fact, we almost appear to moving around and looking at the inside the tunnel... how have I done that?

If you have ever seen Duke Nukem 3D's faked mouselook (DOOM only let you look left and right, Duke Nukem 3D let you look up and down a little as well) you'll know that the effect isn't perfect - it seems to just stretch the view up or down. In fact, it's even lower tech than that - as you look up or down, it just scrolls the rendered area up or down!

This effect is how we can make our tunnel more interesting. Make your lookup tables twice the width and twice the height of the screen area, but calculate the values in exactly the same way. Well, almost - when calculating the relative_x and relative_y, do not subtract half the screen width (or height), but half the lookup table width (or height) instead. If you run your program now, you should just have the top-left part of your tunnel (similar to the screenshot just above) rendered. To look around, add an x-offset and a y-offset to the (x,y) values used to read values from the lookup tables. An x-offset of half the screen width and a y-offset of half the screen height should centre the tunnel again.