Last active
March 28, 2021 15:00
-
-
Save dghez/d8636eb755d425e684390121d56664ff to your computer and use it in GitHub Desktop.
Calculate the distance of the camera to fit a given width
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MathUtils } from "three"; | |
export default function distance(width, camera) { | |
const vFOV = MathUtils.degToRad(camera.fov); | |
const distance = width / camera.aspect / (2 * Math.tan(vFOV / 2)); | |
const heightPlane = 2 * Math.tan(vFOV / 2) * distance; | |
return { distance, height: heightPlane }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment