@luke810
You need to know the screen width and height, and the field of view. It's basically right triangle trig.
I use the screen height because it keeps things unskewed and matches pretty accurately to the 3d screen in DBC:
halfh=screen height()/2
fov#=3.14/2.905
degrees#=(fov#*(180.0/3.14))/2.0
zdist#=(halfh)/(tan(degrees#))
What this does is, gets the field of view (in radians) coverts that to degrees and divides it in half. So now degrees ~ 31. We do that because we are going to make a triangle from the camera, to the center of the viewing plane, then to the edge of the screen. I use the screen height because that will keeps things nice and square so the FOV isn't skewed because of a larger width.
Next we divide half of the screen height by the tan(degrees) and that gives us the zdist to the camera.
This formula is taken from the right triangle math.
SOHCAHTOA which is
sine(angle) = opposite/hypotenuse
cosine(angle = adjacent/hypotenuse
tangent(angle) = opposite/adjacent
I used the last formula where the adjacent value is what we are solving for. The opposite value is half of the screen height, and angle is approxiametly 31 degrees in this case.
Enjoy your day.