Course Links

Exercises

Resources

External

Basically, we want to change the offset so that the same map rectangle coordinates are mapped to the center of the viewport at both magnifications.

Call the two magnifications m1 and m2, and offsets are (x1,y1) and (x2,y2). Also let w and h be the view dimensions. All are known except (x2,y2).

The map rectangle coordinates of the center pixel in view 1 is ((w/2-x1)/m1,(h/2-y1)/m1). (The sign of the offset may be backwards depending on your implementation.) In view 2 it is ((w/2-x2)/m2,(h/2-y2)/m2).

Since we want these points to be the same, we can set the corresponding coordinates equal to each other to get an equation.

(w/2-x1)/m1 == (w/2-x2)/m2

Solve it for the unknown x2 and you have the formula you need. Similar thing in the second coordinate for y2.