help w/ zoom in/out

I’m using glOrtho on an object I drew, but now I’d like to zoom in and out on it. I know how to translate left, right, up, down, and make it rotate, but I can’t make it zoom.

It seems that if I use my + or - keys, the near and far panes of my viewing volume are what’s being moved because it starts to clip my object either in the front or back. That’s done w/ the following code (I add and subtract to the ztrans variable in my glTranslatef()) which I think is wrong for zooming in or out.

public void display(GLDrawable drawable) {

gl.glTranslatef(xtrans, ytrans, ztrans);

}

Any help much appreciated.

[quote]I’m using glOrtho on an object I drew, but now I’d like to zoom in and out on it. I know how to translate left, right, up, down, and make it rotate, but I can’t make it zoom.

It seems that if I use my + or - keys, the near and far panes of my viewing volume are what’s being moved because it starts to clip my object either in the front or back. That’s done w/ the following code (I add and subtract to the ztrans variable in my glTranslatef()) which I think is wrong for zooming in or out.

public void display(GLDrawable drawable) {

gl.glTranslatef(xtrans, ytrans, ztrans);

}

Any help much appreciated.
[/quote]
glTranslate does exactly what it says on the tin :slight_smile: You could certainly use it to pan around your ortho view but if you translate along the Z axis , presuming you haven’t done any rotations before hand, the translation will result in your objects being drawn further away from or nearer to the near clip plane. Eventually they’ll be clipped. translating along the Z axis will make things bigger or smaller if you use a perspective transform , but ortho uses an orthographic transform which discards that notion*. To zoom in an orthographic transform you can either apply a scalef to the entire scene, or change the extants of the ortho transform itself. The latter is probably the best way to do it.

D.

*I was just reminded of that episode of Father Ted when i was writing this. “now Dougal, those are SMALL, those other ones (points out the window) are FAR AWAY”. ah the funnies.

To clarify,

In ortho perspective, it is irrelevant how far away the object is. So moving it closer or farther away from the viewer doesn’t change the size. So, you do:

gl.glScalef(2,2,2);

before you draw and everything doubles in size, or (as the previous reply stated) change your glortho bounds to be half the size they were.

You need to read the chapter on scaling in the red book.

google OpenGL Red Book pdf and you should get the free copy online. The 2nd edition may be out of date, but this stuff hasn’t changed, so free=good.