2

I'm developing an app using Unity3d and the Google Cardboard sdk. I have been trying to get the field of view property for the individual Cardboard cameras. This is working fine in the editor however, when I build it to Android the camera's fieldOfView property appear to be returning the wrong value.

Camera cam = GameObject.FindWithTag("Camera_Left").GetComponent<Camera>();
float fov = cam.fieldOfView;

Is this the correct way to access this?

Any suggestions greatly appreciated!

EDIT

To clarify I don't need to change the FOV. I just need access to a fairly accurate vertical FOV value. I am attempting to calculate the size a game object will appear to the camera using the FOV.

Matt
  • 21
  • 4

1 Answers1

3

There are many values that determines the fieldOfView when using VR. It's just not that Camera.fieldOfView property anymore. The StereoController class should be used to obtamin this.

StereoController stereoCtrl = GvrViewer.Controller;
Debug.Log("Fov: "+stereoCtrl.matchMonoFOV);

There are other variables to look at such as stereoCtrl.stereoMultiplier and stereoCtrl.matchByZoom.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Hi, I had a look at this. However unless I'm mistaken matchMonoFOV ranges between 0 and 1 and sets the extent to which the VR cameras matche the FOV of the mono camera.. To clarify I don't need to change the FOV. I just need a fairly accurate vertical FOV value. I am attempting to calculate the size a game object appears to the camera depending on the distance from the camera and the FOV. – Matt Nov 07 '16 at 16:31
  • **"To clarify I don't need to change the FOV"** I was not changing anything in my code. `StereoController stereoCtrl = GvrViewer.Controller` will get the current instance `StereoController` so that we can access it's properties with `stereoCtrl.matchMonoFOV`. So, your comment and edit in your question does not make sense. – Programmer Nov 07 '16 at 18:24
  • You just need to find a way to convert the `0 and 1` to an angle. `matchMonoFOV` is what you are looking for. – Programmer Nov 07 '16 at 18:31
  • hmm, matchMonoFOV appears to be set to 0 for me. – Matt Nov 07 '16 at 19:34
  • https://github.com/googlevr/gvr-unity-sdk/blob/master/Samples/SpatialAudio/Assets/Cardboard/Scripts/StereoController.cs . – Matt Nov 07 '16 at 19:34
  • Looking at line 88 (in the source code - see above link) it sounded to me like the closer to 1 matchMonoFOV is set, the closer the vr camera FOV is to the mono camera's field of view. – Matt Nov 07 '16 at 19:35
  • That's interesting. Set `matchByZoom` to 1 then try to check if `matchMonoFOV` is now returning a value other than 0. – Programmer Nov 07 '16 at 19:48
  • matchByZoom sets how matchMonoFOV is achieved - either moving the cameras or adjusting the FOV – Matt Nov 08 '16 at 09:48