Search Unity

Multi Screen

Discussion in 'Works In Progress - Archive' started by Dm1try, Feb 29, 2012.

  1. Dm1try

    Dm1try

    Joined:
    Jul 25, 2011
    Posts:
    8
    Hello everyone!

    I want to create 360 degrees panorama in my application. For this I write code that generates several cameras, every camera looks to special direction. There is no problem how many monitors or computers I want to use to draw panorama. The problem is in the next picture I see when I'm looking down to generated cameras.





    In example I generated 6 cameras and I saw that every camera didn't touch by left and right sides another cameras. So there will be "holes" between every two cameras in my panorama.

    I use exact geometrical formula, why the result is not as expected ?
    Angle around Y axis (I called it Alpha) is 60 degrees (FOV is equal to 48.02031).
    There is a formula to convert Alpha to FOV:
    tg(Alpha/2) / Screen.width == tg (FOV/2) / Screen.height


    Script below generates cameras. I have also attached project to topic.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4.  
    5. public class MultiScreenController : MonoBehaviour
    6. {
    7.  
    8.     public Camera LeftCamera = null;
    9.     public int Number = 6;
    10.     public Camera[] Cameras = null;
    11.  
    12.     private float angle = 60;
    13.     private float timer = 3.0f;
    14.     private bool exit = false;
    15.  
    16.     void Awake()
    17.     {
    18.         CreateCameras();
    19.     }
    20.  
    21.     private void CreateCameras()
    22.     {
    23.         print(Screen.width + " x " + Screen.height);
    24.         print(LeftCamera.aspect);
    25.         print(1.0f * Screen.width / Screen.height);
    26.  
    27.         //float aspect = LeftCamera.aspect;
    28.         float aspect = 1.0f * Screen.width / Screen.height;
    29.  
    30.         angle = 360.0f / Number;
    31.  
    32.         float fov = CalculateFOW(aspect, angle);
    33.         print("FOV = " + fov);
    34.         float alpha = CalculateAlpha(aspect, fov);
    35.         print("ALPHA = " + alpha);
    36.  
    37.         Cameras = new Camera[Number];
    38.         Cameras[0] = LeftCamera;
    39.         Cameras[0].fov = fov;
    40.         for (int i = 1; i < Number; i++)
    41.         {
    42.             Cameras[i] = Instantiate(LeftCamera, LeftCamera.transform.position, Quaternion.identity) as Camera;
    43.             if (null == Cameras[i])
    44.             {
    45.                 Debug.LogError("null == Cameras[i]");
    46.                 return;
    47.             }
    48.  
    49.             Cameras[i].gameObject.name = "0" + i + "Camera";
    50.             Cameras[i].transform.parent = LeftCamera.transform.parent;
    51.  
    52.             Cameras[i].fov = fov;
    53.             Cameras[i].transform.rotation = Quaternion.Euler(0, i * angle, 0);
    54.         }
    55.     }
    56.  
    57.     private float CalculateFOW(float aspect, float alpha)
    58.     {
    59.         float angle = alpha * Mathf.Deg2Rad;
    60.  
    61.         float fovRadians = 2 * Mathf.Atan(Mathf.Tan((1.0f / aspect) * (angle / 2.0f)));
    62.  
    63.         float fovDegrees = fovRadians * Mathf.Rad2Deg;
    64.  
    65.         return fovDegrees;
    66.     }
    67.  
    68.     private float CalculateAlpha(float aspect, float fov)
    69.     {
    70.         float fovRadians = fov * Mathf.Deg2Rad;
    71.  
    72.         float alphaRadians = 2 * Mathf.Atan(Mathf.Tan(aspect * (fovRadians / 2.0f)));
    73.  
    74.         float alphaDegrees = alphaRadians * Mathf.Rad2Deg;
    75.  
    76.         return alphaDegrees;
    77.     }
    78. }
    79.  
     

    Attached Files:

  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The correct formula for calculating the camera's field of view (vertical) from the horizontal field of view is:-

    Code (csharp):
    1. camera.fieldOfView = 2f * Mathf.Rad2Deg * Mathf.Atan(Mathf.Tan(.5f * Mathf.Deg2Rad * horizFOV) / camera.aspect);
     
  3. Dm1try

    Dm1try

    Joined:
    Jul 25, 2011
    Posts:
    8
    Thank you for quick answer !

    I did a mistake then I was transforming my formula.

    Your formula is actually correct.