Santhosh
Santhosh

Reputation: 1079

How to calculate distance for FOV in three JS

I'm working on resizing the FOV value dynamically while changing the screen sizes in three JS. Here I have found a calculation which works perfectly at any screen, but I no idea for the distance in FOV. Kindly let me know your suggestions.

    const distance = 1000;
    const diag = Math.sqrt((height * height) + (width * width));
    this.camera.fov = Math.atan((diag) / (3 * distance)) * (180 / Math.PI);

So, kindly help me out with the use of the distance value and to calculate the distance value dynamically to the screen size without giving a fixed range.

Upvotes: 1

Views: 1861

Answers (1)

Rabbid76
Rabbid76

Reputation: 210877

The ratio of the Z-distance and the height of an object on the view at perspective projection (PerspectiveCamera) is:

h_z_ratio = Math.tan(this.camera.fov/2.0 * Math.PI/180.0) * 2.0;

which is the same as

h_z_ratio = this.camera.getFilmHeight() / this.camera.getFocalLength();

Upvotes: 2

Related Questions