Skip to content

Instantly share code, notes, and snippets.

@dghez
Last active March 28, 2021 15:00
Show Gist options
  • Save dghez/d8636eb755d425e684390121d56664ff to your computer and use it in GitHub Desktop.
Save dghez/d8636eb755d425e684390121d56664ff to your computer and use it in GitHub Desktop.
Calculate the distance of the camera to fit a given width
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