Archived

This topic is now archived and is closed to further replies.

Nostalgia

Zooming algorithms

Recommended Posts

Nostalgia    122
Hey all. I have a window that I display on the screen. I want the user to be able to zoom around an arbitrary center point. For some reason I can''t get my head around the math. For example, my image is 300x300. The screen is 800x600. When the image is first displayed, it gets scaled to 600x600 to fit the available screen. Then, the user clicks on the screen to scale the image at point 500, 500 on the screen. Scaling the image is easy, but how do I keep the point the image was clicked on at the same point after it''s been scaled up? I know this should be easy, but the answer eludes me. Help is greatly appreciated! -Joe Nostalgia, an Intellivision Emulator http://www.gotmaille.com/nostalgia/

Share this post


Link to post
Share on other sites
Nostalgia    122
Nope, straight GUI. That''s why I didn''t post in the DirectX or OpenGL forums. I''ve got to bit bang it. It''s just a flat 2d image I''m stretching onto the screen.

-Joe

Nostalgia, an Intellivision Emulator
http://www.gotmaille.com/nostalgia/

Share this post


Link to post
Share on other sites
yaroslavd    150
Well, if (500,500) is the center point, then the left upper corner of the image would be half the image height above and half the image width to the left of the center point. For example, if you wanna draw an image 100*100 with the center at (500,500), just do

drawImage(anImage,500-100/2,500-100/2);

That, of course is pseudocode.

Share this post


Link to post
Share on other sites
Zimans    237
Do you want the point being clicked on to remain in the same place on the pysical screen? Or are you re-centering your image based on the point clicked on.

if you are centering the image, then just multiply your centering point and your image width, height by the same factor. Then your new center coords will be in the same place on the image. If you keep the scaling factor as a seperate variable then you need to take your screen coords and adjust for the current scale factor (Just divide by the scale factor to get real image coords.)

If your centering about the same physical location, do the same as above, except your offsetting the ''center'' by the position clicked on. For instance a 600x600 image, clicked on at 500x500. Asuming a scale factor of 2x would produce a new width highght of 1200x1200, and a new pos of 1000,1000. since your original position was 500,500. your new upper left corner is 500,500. (new position minus absolute click coords).

Hope this helps.
-Zims

Share this post


Link to post
Share on other sites
RuneLancer    253
quote:
Original post by Anonymous Poster
use stretchblt


Mmm... I dunno, I would prefer to code my own routine, personally. Stretchblt works, but it''s a little... ah... ugly. Doesn''t do anything too pretty due to pixelization. I have a rather nice SuperEagle/2xSAL-like zooming algorithm (those who toy around with oldschool emulators would know what this is) that works wonders...

But yeah, StretchBlt works, too, if you''re not going for high quality..

Share this post


Link to post
Share on other sites
Nostalgia    122
Actually I''m using enhanced meta files. Ziman''s post helped; I''ve got it working great. If the mouse is on the screen it zooms around the mouse point, if not, it zooms around the center. Works perfectly, thanks for all the input.

-Joe

Nostalgia, an Intellivision Emulator
http://www.gotmaille.com/nostalgia/

Share this post


Link to post
Share on other sites