For a given Z depth, how do I find the rectangle of the viewable area?
Or, to ask the same thing another way: For a given Z depth开发者_高级运维 in a 3D scene, I want the X and Y coordinates that will allow me to place an object just outside of the viewable area.
I'm using three.js for this.
If you know the horizontal field of view $\alpha$, for example, you can just use some trigonometry to get : $xmin = tan \alpha/2 * Z$ . This $xmin$ is the $x$ coordinate of the begining of the frustum, in the frame of the camera : if you want to use global coordinates, you thus have to rotate and translate this point according to the position and orientation of the camera (basically, multiplying by the inverse of your camera matrix).
精彩评论