VRFieldOfView

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The VRFieldOfView interface of the WebVR API represents a field of view defined by 4 different degree values describing the view from a center point.

Constructor

VRFieldOfView()
Creates a new VRFieldOFView object.

Properties

This interface doesn't define any of its own properties; however, it does inherit those of its parent interface, VRFieldOfViewReadOnly.

VRFieldOfViewReadOnly.upDegrees Read only
The number of degrees upwards that the field of view extends in.
VRFieldOfViewReadOnly.rightDegrees Read only
The number of degrees to the right that the field of view extends in.
VRFieldOfViewReadOnly.downDegrees Read only
The number of degrees downwards that the field of view extends in.
VRFieldOfViewReadOnly.leftDegrees Read only
The number of degrees to the left that the field of view extends in.

Examples

The following simple example shows a function that can be used to set a custom field of view with four specified degree values for up, right, down and left. The VRFieldOfView() constructor is used to create a VRFieldOfView object from the supplied values, which is then fed into the setFieldOfView() method (the default zNear and zFar values are always used, in this case.)

function setCustomFOV(up,right,down,left) {
  var testFOV = new VRFieldOfView(up,right,down,left);

  gHMD.setFieldOfView(testFOV,testFOV,0.01,10000.0);

  var lEye = gHMD.getEyeParameters('left');
  var rEye = gHMD.getEyeParameters('right');
  console.log(lEye.currentFieldOfView);
  console.log(rEye.currentFieldOfView);
        }

Note: When testing, setting a weird/tiny field of view can really mess up your view. IT is a good idea to grab the current field of view first (using VREyeParameters.currentFieldOfView) before making any drastic changes, so you can reset it afterwards if needed.

The following example is taken from the Mozilla VR Team's threejs-vr-boilerplate code — to be precise, the VREffect.js file. Early on in the code the HMDVRDevice.getEyeParameters method is used to access information about each eye, which is then used for rendering calulations later on — including the VREyeParameters.recommendedFieldOfView property, which returns a VRFieldOfView object.

if ( vrHMD.getEyeParameters !== undefined ) {

    var eyeParamsL = vrHMD.getEyeParameters( 'left' );
    var eyeParamsR = vrHMD.getEyeParameters( 'right' );

    eyeTranslationL = eyeParamsL.eyeTranslation;
    eyeTranslationR = eyeParamsR.eyeTranslation;
    eyeFOVL = eyeParamsL.recommendedFieldOfView;
    eyeFOVR = eyeParamsR.recommendedFieldOfView;

} else {

  ...

}

The following code snippet — taken from the WebVR spec — creates a WebGL-compatible projection matrix from a VRFieldOfView.

function fieldOfViewToProjectionMatrix(fov, zNear, zFar) {
  var upTan = Math.tan(fov.upDegrees * Math.PI/180.0);
  var downTan = Math.tan(fov.downDegrees * Math.PI/180.0);
  var leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0);
  var rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0);
  var xScale = 2.0 / (leftTan + rightTan);
  var yScale = 2.0 / (upTan + downTan);

  var out = new Float32Array(16);
  out[0] = xScale;
  out[1] = 0.0;
  out[2] = 0.0;
  out[3] = 0.0;
  out[4] = 0.0;
  out[5] = yScale;
  out[6] = 0.0;
  out[7] = 0.0;
  out[8] = -((leftTan - rightTan) * xScale * 0.5);
  out[9] = ((upTan - downTan) * yScale * 0.5);
  out[10] = -(zNear + zFar) / (zFar - zNear);
  out[11] = -1.0;
  out[12] = 0.0;
  out[13] = 0.0;
  out[14] = -(2.0 * zFar * zNear) / (zFar - zNear);
  out[15] = 0.0;

  return out;
}

Specifications

Specification Status Comment
WebVR
The definition of 'VRFieldOfView' in that specification.
Editor's Draft Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes)[1] 39 (39)[2] No support No support No support
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 39.0 (39)[2]
44.0 (44)[3]
No support No support No support No support No support
  • [1] The support in Chrome is currently experimental. To find information on Chrome's WebVR implementation status including supporting builds, check out Bringing VR to Chrome by Brandon Jones.
  • [2] The support for this feature is currently disabled by default in Firefox. To enable WebVR support in Firefox Nightly/Developer Edition, you can go to about:config and enable the dom.vr* prefs. A better option however is to install the WebVR Enabler Add-on, which does this for you and sets up other necessary parts of the environment.
  • [3] The dom.vr* prefs are enabled by default at this point, in Nightly/Aurora editions.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, Sebastianz
 Last updated by: chrisdavidmills,