Skip to content

Instantly share code, notes, and snippets.

@pfreema1
Last active June 17, 2020 13:25
Show Gist options
  • Save pfreema1/091b088481deca42b88d3f83f13cf1b8 to your computer and use it in GitHub Desktop.
Save pfreema1/091b088481deca42b88d3f83f13cf1b8 to your computer and use it in GitHub Desktop.
/*
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