- Home /
Camera frustums + custom field of view
I got the planes of my camera frustum using GeometryUtility.CalculateFrustumPlanes and they seem to be created at random positions and rotations. I am using the example script from the documentation.
Another thing I need to do is set the camera's field of view to custom angles, vertically and horizontally. The vertical angle can be set by the camera's field of view value, and I've read that using the aspect ratio is the only way of adjusting the horizontal field of view. Will this distort the image, or will it simply adjust the size of the game view to keep it in proportion if necessary?
Is this:
static function CalculateFrustumPlanes (worldToProjectionMatrix : Matrix4x4) : Plane[]
the best way to go about it?
Thanks
Answer by StephanK · Mar 23, 2011 at 09:47 AM
If you want to create an asymmetric frustum (used for headtracking, stereo rendering etc.) you are better off modifying the projection matrix directly. If you want to do something else a little more info would be appreciated.
Thanks for the quick reply. What I am basically doing is making a system that allows users to manipulate cameras in the scene. They can adjust the vertical and horizontal angles of the field of view, and can also "see" which areas are being looked at by a particular camera (this is where the frustum comes into play).
No headtracking or stereo rendering is involved.
I still think if you need to set the horizontal opening angle you'll need to modify the projection matrix. As you know Unity only allows to set the fov which is the vertical angle directly.
Answer by sean · Sep 09, 2011 at 09:33 PM
I've been able to get any combination of render rect and field of view I've needed so far using just the fieldOfView and viewportRect/pixelInset, and I've needed to do some obscure edge-use-case stuff. By default, Unity will set the aspect ratio and field of view to be consistent with the size of the viewport rect. From there, however, you can manually adjust any of the above in script without the others being auto-adjusted. So say your viewport is square but you want to render a wider horizontal angle: just change camera.aspect to a larger value. The field of view (vertical angle) will stay the same, the horizontal angle will increase, and the viewport contents will be proportionally distorted (unless you then change the viewport rect or screen size). If you want to render taller than square, you'll need to increase the field of view but decrease the aspect ratio proportionally (say, multiply the FoV by 4/3, but then multiply aspect by 3/4). If you want an asymmetric frustum... yeh. That's actually going to be one of my upcoming questions if I don't see anything in the Answers after a bit of searching.