Ever wondered how you can compute a view and projection matrix given the eye position and
any arbitrarily positioned and oriented near plane rectangle, such as what Johnny Lee did with his WiiRemote virtual reality hack using a simple monitor and the WiiRemote? Or do you own a TrackIR device and don't know what to do with it?
It's pretty simple. Here is how:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 public static void projViewFromRectangle(Vector3f eye, Vector3f p, Vector3f x, Vector3f y, float nearFarDist, Matrix4f projDest, Matrix4f viewDest) { float zx = y.y * x.z  y.z * x.y, zy = y.z * x.x  y.x * x.z, zz = y.x * x.y  y.y * x.x; float zd = zx * (p.x  eye.x) + zy * (p.y  eye.y) + zz * (p.z  eye.z); float zs = zd >= 0 ? 1 : 1; zx *= zs; zy *= zs; zz *= zs; zd *= zs; viewDest.setLookAt(eye.x, eye.y, eye.z, eye.x + zx, eye.y + zy, eye.z + zz, y.x, y.y, y.z); float px = viewDest.m00 * p.x + viewDest.m10 * p.y + viewDest.m20 * p.z + viewDest.m30; float py = viewDest.m01 * p.x + viewDest.m11 * p.y + viewDest.m21 * p.z + viewDest.m31; float tx = viewDest.m00 * x.x + viewDest.m10 * x.y + viewDest.m20 * x.z; float ty = viewDest.m01 * y.x + viewDest.m11 * y.y + viewDest.m21 * y.z; float len = (float) Math.sqrt(zx * zx + zy * zy + zz * zz); float near = zd / len; projDest.setFrustum(px, px + tx, py, py + ty, near, near + nearFarDist); }

This is JOML code, however setLookAt() and setFrustum() are semantically exactly identical to glLoadIdentity() + gluLookAt() and glLoadIdentity() + glFrustum().