Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!