Search Unity

Vertical FOV plus Aspect Ratio

Discussion in 'Editor & General Support' started by nm8shun, Jun 7, 2010.

  1. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    I'm working with some stereoscopic projects in which the headset requires the horizontal FOV and vertical FOV to be set independently or the vertical FOV plus the aspect ratio to be set.

    So, for instance, the vertical FOV must be 45, with the horizontal FOV at 85.5 (it'll be on a screen at 1920x1200 for each eye (aspect ration of 1.6(?)). I know how to adjust the (vertical) FOV - but how to I lock in this other aspect ratio?

    Thank!
     
  2. jbk

    jbk

    Joined:
    Oct 21, 2009
    Posts:
    11
    I'm not at my Unity box just now, so can't test it, but:

    Camera.aspect should allow you to set the aspect
    While Camera.fieldOfView is used for the vertical FOV.
    Calling Camera.ResetAspect brings you back to normal.

    Alternatively you can set both the vFOV and hFOV using a custom frustum in the Camera.projectionMatrix. This is slightly more complicated, though - as you have to calculate things yourself. Check out the example, it is quite useful.
     
  3. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Thanks. I think I got it figured out.

    Just in case anyone else is doing something like this, here's the solution I ended up with.

    Code (csharp):
    1. var verticalFOV : float = 45;
    2. var forcedAspectRatio: float = 1.6;
    3. var manualNearClipPlane : float = .3;
    4. var manualFarClipPlane : float = 1000;
    5.  
    6. function Update(){
    7.     camera.projectionMatrix = Matrix4x4.Perspective(verticalFOV, forcedAspectRatio, manualNearClipPlane, manualFarClipPlane);
    8. }