Search Unity

How to match Camera field of view to the device camera field of view?

Discussion in 'Scripting' started by BooBi, Nov 5, 2015.

  1. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    534
    Hi,

    I'm having an issue, by using these lines of code:
    Code (csharp):
    1.  
    2. webCamTexture = new WebCamTexture();
    3.         GetComponent<Renderer>().material.mainTexture = webCamTexture;
    4.         webCamTexture.Play();
    5.  
    I'm displaying the webcam content on a plane (I'm still figuring out how to fit the UVs keep the image with the good camera ratio). In front of the plane I'm manipulating a 3D cube.

    My goal here is to match as close as possible the perspective of the device camera (FOV) with the Unity camera one.

    I've found this: http://photo.stackexchange.com/questions/40694/field-of-view-of-a-webcam
    But I'm looking for a more systematic way of calculating that. Is there a way to read the device camera FOV ?

    The project is an augmented reality object placer used on Android and IOS. As there are so many android devices I need to find an automatic way to match the two FOV.

    I tried to use vuforia's AR plugin, but the problem is that the perspective is still wrong. And also that Vuforia is overwriting the cam FOV and I can't prevent that apparently. (Well I'm on their forums aswel for that matter).
     
  2. Lanre

    Lanre

    Joined:
    Dec 26, 2013
    Posts:
    3,971
    Hi @BooBi Instead of calculating it, you could simply ask the camera for it. NatCam supports this functionality:
    Code (CSharp):
    1. Debug.Log("The camera's FOV is "+ NatCam.ActiveCamera.HorizontalFOV);