Created
June 2, 2024 16:12
-
-
Save wewindy/c47a10d777d22c08c6d5a702af9358ea to your computer and use it in GitHub Desktop.
CesiumScale
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
const clamp = (val: number, min = 0, max = 1) => { | |
return val > min ? val > max ? max : val : min | |
} | |
export const getCesiumScale = (distanceToCamera: number, nearFarScalar: NearFarScalar) => { | |
const nearScalar = nearFarScalar.nearValue | |
const farScalar = nearFarScalar.farValue | |
const nearDistance = nearFarScalar.near | |
const farDistance = nearFarScalar.far | |
let t = (distanceToCamera ** 2 - nearDistance ** 2) / (farDistance ** 2 - nearDistance ** 2) | |
t = Math.pow( | |
clamp(t), | |
0.2, | |
) | |
const cesiumScale = nearScalar * (1 - t) + farScalar * t | |
return cesiumScale | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment