Last active
June 17, 2020 13:25
-
-
Save pfreema1/091b088481deca42b88d3f83f13cf1b8 to your computer and use it in GitHub Desktop.
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
/* | |
taken from: https://gist.github.com/ayamflow/96a1f554c3f88eef2f9d0024fc42940f | |
// Basically solving an AAS triangle https://www.mathsisfun.com/algebra/trig-solving-aas-triangles.html | |
https://i.stack.imgur.com/PgSn3.jpg | |
*/ | |
// return height and width of plane that covers viewport at the given plane z position | |
export default (camera, planeZ, viewWidth, viewHeight) => { | |
const cameraZ = camera.position.z; | |
const distance = cameraZ - planeZ; | |
const aspect = viewWidth / viewHeight; | |
const vFov = (camera.fov * Math.PI) / 180; | |
const height = 2 * Math.tan(vFov / 2) * distance; | |
const width = height * aspect; | |
return { | |
width, | |
height | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment