View Full Version : Orthogonal view zooming
07-21-2001, 08:25 AM
How can I zoom into an orthogonal view using glOrtho? I want to zoom in a window
that can be resized, so I would like to understand how to use the aspect ratio and
a zoom factor with glOrtho.
07-21-2001, 08:54 AM
Here's a snippet of code that I've used..
xy_range = -1*(CameraStartPos + CameraOffset); // set up Camera position
glViewport(0, 0, windowWidth, windowHeight);
// set after getting the current window size
// Reset projection matrix stack
if ( windowWidth <= windowHeight)
The xy_range parameter represents the width/height parameter for a 'frontview' in this case (down the z-axis).
I use the CameraOffset parameter to 'zoom' into and out of screen. Increase this parameter to zoom into the screen, thereby decreasing the xy_range (width/height) parameter, or conversely decrease this parameter to zoom out. The near and far clipping planes could be any multiple, but I've chosen 10 in order to see the model even close in.
The cameraStartPos parameter just supplies a default position on the z-axis before 'zooming'. It's multipled by a negative number because in ModelView the translation is negative in order to push the view out in front of the viewer.
Hope this helps.
07-21-2001, 04:53 PM
If you use CameraOffset as your zoom factor, then what do you use to
translate the view, CameraStartPos?
[This message has been edited by Syslock (edited 07-21-2001).]
07-22-2001, 06:51 AM
I translate the entire scene in 'MODELVIEW', out along the positive z-axis using this parameter, prior to drawing the scene. But it doesn't have to appear in the setting of the glOrtho view.
As the user zooms in and out only the zoom parameter changes. I did it this way because the app I've been writing has four views, 3 ortho and one perspective, so it was a convient way to tie the virtual camera to each view.
If all your views are ortho, all you'd have to keep track off would be a 'zoom' parameter. So first of all translate the scene in front of the camera. I did this in MODELVIEW by moving a negative amount along the z-axis.
Check whether the user has zoomed in or out, amend the zoom factor, then reset the parameters in glOrtho in PROJECTION mode using the new zoom factor parameter. Redraw the scene, using the default translation along the z-axis in MODELVIEW. The bigger the zoom number the wider/heigher the scene, the smaller the number the smaller the height/scene.
You don't have to keep moving the scene using the MODELVIEW translation just use the PROJECTION glOrtho setting for width and height, then redrawing the using your default settings for the MODELVIEW translation.
Does this make sense ?
07-22-2001, 08:04 AM
Thanks for the explanation. http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.