Skip to content

Instantly share code, notes, and snippets.

@jackismissing
Created August 10, 2021 11:44
Show Gist options
  • Save jackismissing/7aa92b192a4df659881e700da1379123 to your computer and use it in GitHub Desktop.
Save jackismissing/7aa92b192a4df659881e700da1379123 to your computer and use it in GitHub Desktop.
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