PDA

View Full Version : Looking for a way to "zoom" in ortho view



acaron
03-01-2002, 11:41 AM
Hi,

I'm facing a problem. I want to create a "zoom" in a viewer that I've created. Translating along the Z-Axis doesn't work since I'm in ortho view.

I tried scaling the model, but the near clipping is creating a weird effect. Does anyone know a better way!?

Coconut
03-01-2002, 12:28 PM
Originally posted by acaron:
Hi,

I'm facing a problem. I want to create a "zoom" in a viewer that I've created. Translating along the Z-Axis doesn't work since I'm in ortho view.

I tried scaling the model, but the near clipping is creating a weird effect. Does anyone know a better way!?

When you use glOrtho, change the values of the first two arguments can create the zoom effect.

Omaha
03-01-2002, 04:21 PM
Instead of translating along the Z axis, use glScale()

zeckensack
03-02-2002, 09:06 AM
More specifically, use glScalef(something,something,0.0f). If you don't want to scale along z (near clipping stuff), then don't.

*edit*
Aargh, why does nobody smack me for that!? The third parameter should be 1.0f, not 0.0f!

Coco's method sounds cool though, so don't bother.

[This message has been edited by zeckensack (edited 03-05-2002).]

zed
03-02-2002, 03:24 PM
coconut's method is preferable to scaling
glOrtho(left/scale, right/scale, up/scale etc )

acaron
03-05-2002, 06:15 AM
Thanks a lot coconut!!!

Syslock
03-05-2002, 09:48 AM
How would you handle both zooming and translating?

So, if I was zoomed in a lot, and I tried to translate over a little, my
view wouldn't fly off the screen. Same goes for if I was zoomed out a lot,
how would I move it so the view doesn't move along at a snail's pace?

In other words, it should move exactly where I drag the mouse, whatever the zoom factor.

[This message has been edited by Syslock (edited 03-05-2002).]

Furrage
03-05-2002, 11:43 AM
Scale you translation value. Thus the distance moved will be related to the zoom factor.

Syslock
03-06-2002, 08:10 AM
I did something like (mouse_delta * zoom_factor), but it didn't seem
to work right.

It's like the view doesn't stay with the mouse, almost as if something is not centered
correctly.

Zooming always zooms into a fixed center point, never at the point center on the screen.

[This message has been edited by Syslock (edited 03-06-2002).]

Furrage
03-06-2002, 09:25 AM
I haven't tested the following but I figure that the zoom and translate code should look something like this.

Say initially your viewport is 300 x 300 pixels, your zoom factor is 1 and your projection matrix is a 10 x 10 x 10 box. Then you could define the following.

double zoom_factor = 1
glMatrixMode(GL_PROJECTION)
glOrtho(0, 10, 0, 10, 0, 10)

When you change the zoom you could do the following.

glTranslated(-10 / (zoom_factor * 2), -10 / (zoom_factor * 2), 0)
zoom_factor = new_zoom_factor
glMatrixMode(GL_PROJECTION)
glOrtho(0, 10 / zoom_factor, 0, 10 / zoom_factor, 0, 10)
xratio = 10 / (zoom_factor * 300)
yratio = 10 / (zoom_factor * 300)
glMatrixMode(GL_MODELVIEW)
glTranslated(10 / (zoom_factor * 2), 10 / (zoom_factor * 2), 0)

I use glTranslated() at the start and end of the code section to keep the zoom centred. The first translate uses the old zoom, the second the new zoom. Without the translations it will zoom in on the bottom left portion of the screen. If you want it to zoom on an arbitrary point the first translation should translate that point to the bottom left corner of the screen in OpenGL. The last translation remains and will centre the screen on the desired point.

The move ratios (xratio, yratio) indicate how much you should scale mouse movement by. It's calculated as xratio = 3Dwidth/ViewportWidth, yratio = 3Dheight/ViewportHeight. Note that I assumed an aspect ratio of 1 (300 x 300 viewport). If not the right or x value should be (10 * aspect) / (zoom_factor ...)

Then when you're mouse moves just do the following.

glTranslated(xratio * -mousemove.x, yratio * -mousemove.y, 0)

mousemove is in window coordinates. I use -y cause windows y goes top down, while opengl y goes bottom up.