# Big background zoom in/out

This topic is 4788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a huge tiled background that i've given functionality to scale up and down (zooming in and out). the way it is scaled is where ever it is on the screen, the center point to which it is scaled is the center of the screen (no matter where the image is). how would i, after scaling, refigure out the position of the top-left corner. b/c if i leave it the same, after i scale, my engine thinks that the top-left corner is still where it was, but it's not (due to the scaling from the center of the screen which causes the corners to move in if shrunk or move out if stretched) edit: by the way, i'm using C++ and DirectX 9.0c :)

##### Share on other sites
does that make sense to anyone?

##### Share on other sites
if i understood you well, you need to shift the top,left by

-0.5 * height, -0.5 * width for every zoom-in x2

let z = zoom-in (enlargement!) factor
let d = dimension (Height/Width) of original rectangle(map, tiles, ..etc)

(1) the offset is = - (z-1) * d/2
thus\for zoom-in 2x, shift H, and W by -0.5*H, -0.5*W
3x, -1*H, -1*W

for zoom out two times it is like enlarging by factor = 1/2

notice: the enlargement factor above is one-dimensional (for simplicity of math)... ie. 2x means above that a rectangle will double in both dimensions.. (in real math it is x4 in area), and a Cube will be (x8) in volume..

the above will work fine for everyday zooming and keeping the centre.. yet if you want more accurate measurement of the zoom factor, utilise sqr(z) in place of z.

[Edited by - C64 on October 8, 2005 6:35:10 AM]

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×