Multi Screen

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.

using UnityEngine;


public class MultiScreenController : MonoBehaviour 
{

    public Camera LeftCamera = null;
    public int Number = 6;
    public Camera[] Cameras = null;

    private float angle = 60;
    private float timer = 3.0f;
    private bool exit = false;

    void Awake()
    {
        CreateCameras();
    }

    private void CreateCameras()
    {
        print(Screen.width + " x " + Screen.height);
        print(LeftCamera.aspect);
        print(1.0f * Screen.width / Screen.height);

        //float aspect = LeftCamera.aspect;
        float aspect = 1.0f * Screen.width / Screen.height;

        angle = 360.0f / Number;

        float fov = CalculateFOW(aspect, angle);
        print("FOV = " + fov);
        float alpha = CalculateAlpha(aspect, fov);
        print("ALPHA = " + alpha);

        Cameras = new Camera[Number];
        Cameras[0] = LeftCamera;
        Cameras[0].fov = fov;
        for (int i = 1; i < Number; i++)
        {
            Cameras[i] = Instantiate(LeftCamera, LeftCamera.transform.position, Quaternion.identity) as Camera;
            if (null == Cameras[i])
            {
                Debug.LogError("null == Cameras[i]");
                return;
            }

            Cameras[i].gameObject.name = "0" + i + "Camera";
            Cameras[i].transform.parent = LeftCamera.transform.parent;

            Cameras[i].fov = fov;
            Cameras[i].transform.rotation = Quaternion.Euler(0, i * angle, 0);
        }
    }

    private float CalculateFOW(float aspect, float alpha)
    {
        float angle = alpha * Mathf.Deg2Rad;

        float fovRadians = 2 * Mathf.Atan(Mathf.Tan((1.0f / aspect) * (angle / 2.0f)));

        float fovDegrees = fovRadians * Mathf.Rad2Deg;

        return fovDegrees;
    }

    private float CalculateAlpha(float aspect, float fov)
    {
        float fovRadians = fov * Mathf.Deg2Rad;

        float alphaRadians = 2 * Mathf.Atan(Mathf.Tan(aspect * (fovRadians / 2.0f)));

        float alphaDegrees = alphaRadians * Mathf.Rad2Deg;

        return alphaDegrees;
    }
}

845458–31550–$MultiScreen.zip (1.12 MB)

The correct formula for calculating the camera’s field of view (vertical) from the horizontal field of view is:-

camera.fieldOfView = 2f * Mathf.Rad2Deg * Mathf.Atan(Mathf.Tan(.5f * Mathf.Deg2Rad * horizFOV) / camera.aspect);

Thank you for quick answer !

I did a mistake then I was transforming my formula.

Your formula is actually correct.