Search code examples
mathgame-enginezooming

Math function for zooming issue


today I'm looking for a math formula for a zooming functionality in my game. I've a tile map and I want to show clouds at a specific zoom range. Zooming out, clouds should be fully visible (visible level 1f = 100%) and when I zoom in half way the clouds should be completely gone (visible level 0f = 0%).

Lets assume the following figures: The maximum scale (completely zoomed out, clouds should be fully visible) is 1.2f. The minimum level (completely zoomed in, clouds should be fully invisible) is 0.2f. The clouds should start getting fully invisible at the value 0.7f.

I tried some exponential functions but they did not give me the result I was looking for. Could anyone please give me a hint?

Thanks in advance!


Solution

  • I'd use something like

    clouds = (scale - min_scale)/(max_scale - min_scale)
    clouds = max(1.0, clouds)
    clouds = min(0.0, clouds)
    

    with

    • scale the zoom level (0.2 - 1.2)
    • min_scale the scale at which the clouds start to appear, 0.7
    • max_scale the scale at which the clouds are fully visible, 1.2

    The cloud visibility will increase linearly from 0 to 1 when the scale increase from 0.7 to 1.2.