Skip to content

Instantly share code, notes, and snippets.

@wewindy
Created June 2, 2024 16:12
Show Gist options
  • Save wewindy/c47a10d777d22c08c6d5a702af9358ea to your computer and use it in GitHub Desktop.
Save wewindy/c47a10d777d22c08c6d5a702af9358ea to your computer and use it in GitHub Desktop.
CesiumScale
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