bevy_pancam icon indicating copy to clipboard operation
bevy_pancam copied to clipboard

Projection scale formula is incorrect

Open rsk700 opened this issue 7 months ago • 0 comments

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

rsk700 avatar Jul 16 '24 21:07 rsk700