Understanding coordinate system while zooming

Started by
2 comments, last by carleton 16 years, 11 months ago
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
Advertisement
This reads correct enough to me but I'm guessing that you are having a problem of some description?
www.darkdawn.co.uk
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.
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

This topic is closed to new replies.

Advertisement