johanhelsing / bevy_pancam

A bevy plugin for panning orthographic cameras
Apache License 2.0
173 stars 26 forks source link

Projection scale formula is incorrect #61

Open rsk700 opened 4 months ago

rsk700 commented 4 months ago

For scaling there is formula, which is incorrect:

proj.scale = (proj.scale * (1. + -scroll * 0.001)).max(cam.min_scale);

Lets zoom out and zoom in:

# scale = 1

# will make scale = 1.1
scale = 1 * (1 + 100 * 0.001)

# zoom in will make scale = 0.99
scale  = 1.1 * (1 + -100 * 0.001)

Value drifts on zoom out, zoom in.

Lets look at scaling formula: new_scale = old_scale * scale_factor In order to reverse zoom action you need to get old_scale, which we can derive like: old_scale = new_scale * 1/scale_factor

So scale factors should be scale_factor and 1/scale_factor