files/en-us/web/api/hmdvrdevice/setfieldofview/index.md
{{deprecated_header}}{{APIRef("WebVR API")}}{{Non-standard_header}}
The setFieldOfView() method of the {{domxref("HMDVRDevice")}} interface can be used to set the field of view for one eye, or both eyes simultaneously.
setFieldOfView(leftFOV, rightFOV, zNear, zFar)
leftFOV {{optional_inline}}
rightFOV {{optional_inline}}
zNear {{optional_inline}}
0.01.zFar {{optional_inline}}
10000.0.None ({{jsxref("undefined")}}).
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 {{domxref("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) {
const testFOV = new VRFieldOfView(up, right, down, left);
gHMD.setFieldOfView(testFOV, testFOV, 0.01, 10000.0);
const lEye = gHMD.getEyeParameters("left");
const 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 {{domxref("VREyeParameters.fieldOfView")}}) before making any drastic changes, so you can reset it afterwards if needed.
{{Compat}}