Sign in to follow this  

Understanding coordinate system while zooming

This topic is 3854 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 am working on a program that someone else wrote initially. It displays an image on the screen. Often the image is much larger then the screen so the image needs to be zoomed out. There are times when only a piece of the image should be displayed so the image is zoomed in to some degree. For the sake of discussion, lets assume that the original image is 3200x2400 and the screen size is 1600x1200. It is my understanding that I would set the x & y zoom factor to .5 and set the raster position to {0, 0} to display the whole image (full screen). With a x/y zoom factor of 1 and the raster position to {0, 0}, then the lower left quadrant of the image would be displayed. To see the center at full resolution (zoom factor of 1), is the correct raster position {-800, -600}? If so, with a zoom factor of .75, the raster position should be set to {-400, -300}, correct? Carleton

Share this post


Link to post
Share on other sites
I am having problems understanding how the other developer was calculating the offset and I figured that I should first make sure I understand exactly how the coordinate system works;)

Here is an example of what I simply don't understand. Right now the viewing window can be of a different dimensions then the image, so the first thing determined the smaller zoom factor. Lets say we have this:

xZF of .65
yZF of .67

so the min ZF is .65

Then the code has this:

float ypan = 0.5 - 0.5/( zoom_factor / yZF);

I know that the ypan is on a scale of 0 to 1, 0 being bottom and 1 being top, but I simply don't understand what is going on here. Later we have this:

float desiredypan = - ypan * zoom_factor * imageHeight;

This looks to me like he is simply converting the 0 to 1 into the correct scale based on the zoom factor. It all works fine, the problem comes in when I try to make the code zoom to a specific crop zone, it is always off. I figure the problem is, I don't understand what the initial developer was doing so my code isn't working.

Share this post


Link to post
Share on other sites
Ok, I have totally chunked the old cropping code and doing it myself. I am stumped on how to do the math...

The cropping tool is locked to the aspect ratio of the original image. Considering there is already "zooming" going on to display the whole image, the values being given to the OpenGL code to display the crop is percentages from the left/bottom.

Image: 3200x2400
Display: 1600x1200
full image zoom factor of .5 (fiZF)

crop marks: {200,150} to { 1400, 1050} (screen relative)

So the percentages are: { 12.5%, 12.5%} to {87.5%, 87.5%}

With that, I find the percentage of the image that will be visible ( 85.5% - 12.5%) and get 75%. To get the actual zoom factor I divided the full image zoom factor by the visible percentage: .5 / 75% = 66.7% (.667)

And to calculate the offset's I simply take the first crop mark points percentage and multiply them by the image size:

- (12.5% * 3200) = -400 = xpan
- (12.5% * 2400) = -300 = ypan

And it does not work, I get a black box!

What am I doing wrong?

Carleton

Share this post


Link to post
Share on other sites

This topic is 3854 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.

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