Three.js: [Feature Request] Adjust Horizontal FOV

Created on 14 Mar 2019  路  5Comments  路  Source: mrdoob/three.js

Describe the bug or feature request in detail.

ThreeJS field of view option on the camera only adjusts vertical field of view, allow the horizontal field of view to be adjusted as well or create a new camera that has an adjustable horizontal field of view.

Three.js version
  • [x] r102
Browser
  • [x] All of them
OS
  • [x] All of them
Enhancement

Most helpful comment

Of the three quantities, vertical FOV, horizontal FOV, and aspect ratio, you can control two of them.

In three.js, a perspective camera is parameterized by its vertical FOV and aspect ratio. If you want to compute either of those two values from the other (plus horizontal FOV), you will have to do that at the application layer.

For example:

const hFOV = 50; // desired horizontal fov, in degrees

camera.fov = Math.atan( Math.tan( hFOV * Math.PI / 360 ) / camera.aspect ) * 360 / Math.PI; // degrees

camera.updateProjectionMatrix();

All 5 comments

This SO answer provides the formula that relates the horizontal and vertical FOVs.

hFOV = 2 * Math.atan( Math.tan( camera.fov * Math.PI / 180 / 2 ) * camera.aspect ) * 180 / Math.PI; // degrees

You can use that to solve for the vertical FOV as a function of the horizontal FOV.

Yes, that鈥檚 how you calculate the horizontal FOV, however Id like to adjust it independent of the vertical FOV.

Yes, that鈥檚 how you calculate the horizontal FOV, however Id like to adjust it independent of the vertical FOV.

That involves solving for the aspect ratio (width to height ratio), given the vertical and horizontal fields of view.

Of the three quantities, vertical FOV, horizontal FOV, and aspect ratio, you can control two of them.

In three.js, a perspective camera is parameterized by its vertical FOV and aspect ratio. If you want to compute either of those two values from the other (plus horizontal FOV), you will have to do that at the application layer.

For example:

const hFOV = 50; // desired horizontal fov, in degrees

camera.fov = Math.atan( Math.tan( hFOV * Math.PI / 360 ) / camera.aspect ) * 360 / Math.PI; // degrees

camera.updateProjectionMatrix();

19619

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

zsitro picture zsitro  路  3Comments

seep picture seep  路  3Comments

konijn picture konijn  路  3Comments

clawconduce picture clawconduce  路  3Comments