Created
August 10, 2021 11:44
-
-
Save nicodotcomputer/7aa92b192a4df659881e700da1379123 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
export const getWorldVisibleHeight = (camera) => { | |
const vFOV = camera.fov * Math.PI / 180; | |
return 2 * Math.tan(vFOV / 2) * (camera.position.z) | |
} | |
export const worldToPx = (value, camera) => { | |
const worldHeight = getWorldVisibleHeight(camera) | |
return value * worldHeight * window.innerHeight | |
} | |
export const pxToWorld = (value, camera) => { | |
const worldHeight = getWorldVisibleHeight(camera); | |
return value / window.innerHeight * worldHeight | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment