Sign in to follow this  

Big background zoom in/out

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 this post

Link to post
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]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this