Created
October 21, 2021 15:13
-
-
Save wiledal/150b3c7763aca1f5d29b224901afad42 to your computer and use it in GitHub Desktop.
Calculate ThreeJS viewport at depth
This file contains hidden or 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 { PerspectiveCamera } from "three"; | |
export const getDepthPositionMult = (depth: number, camera: PerspectiveCamera) => { | |
const { aspect, fov } = camera; | |
const vFov = (fov * Math.PI) / 180; | |
const planeHeightAtDistance = | |
2 * Math.tan(vFov / 2) * (depth + camera.position.z); | |
const planeWidthAtDistance = planeHeightAtDistance * aspect; | |
return { | |
width: planeWidthAtDistance, | |
height: planeHeightAtDistance | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment