Click here to Skip to main content
Click here to Skip to main content

True OpenGL Zooming

By , 11 Feb 2002
 

Sample Image - Zoom.jpg

Introduction

The topic of this article is focused around zooming in a perspective OpenGL view. I wrote this article because I found some examples of zooming in a OpenGL view using ortho projections. But the most advanced example that I found using perspective projections, don't implement a true zooming but simulate the zooming effect changing the view point or camera angle. The technique that I suggest implement a true zooming and not change camera angle or perspective parameters (view point, reference point clipping planes). I achieved this result using the function glFrustum instead of standard gluPerspective and manipulating (see function COGL::SetPerspective(const CRect &rcClient) in the class COGL) the scaling and translating parameters of projection matrix. Two normalized rectangles are maintained by the COGL class: one for the full size image, and one for the current zooming rectangle. The image presented by OpenGL is scaled by the ratio of the rectangles, adjusted according to the viewport aspect and translated to the center of current zooming rectangle.

Finally sorry for my poor English.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

pepito sbarzeguti
Italy Italy
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionhow to ZOOM?memberprath8 Apr '03 - 2:43 
Cry | :(( HOW TO ZOOM a particular part of colour buffer content.
could i know any more links...to articles,codes,tutorials
General3D coordinatemembereddymohd19 Feb '03 - 22:24 
How can i translate the 2D coordinate of the screen into opengl 3D coordinate?
GeneralRe: 3D coordinatemembertopus19 May '03 - 2:21 
int gluUnProject(
GLdouble winx,
GLdouble winy,
GLdouble winz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *objx,
GLdouble *objy,
GLdouble *objz
);
Parameters
winx, winy, winz
The window coordinates to be mapped.
modelMatrix
The modelview matrix (as from a glGetDoublev call).
projMatrix
The projection matrix (as from a glGetDoublev call).
viewport
The viewport (as from a glGetIntegerv call).
objx, objy, objz
The computed object coordinates.
Sleepy | :zzz:
GeneralRe: 3D coordinatesussAnonymous9 Jun '05 - 4:58 
u must get the unprojection matrix

GeneralSmall question about OpenGLmemberAnonymous28 May '02 - 0:05 
Hi all, here is the small trouble of a new-comer to OpenGL. Who knows how to convert a 3D point to a normal point (screen coordinate) and how to do on the contrary.
For example:
CRect rc;
GetClientRect(rc);
int x, y;
double u, v, t;
 
// And how to do this
// 1. M1(1.0, -0.7, 2.3) --> M2(x, y) ;
// 1. M2(100, 120) --> M1(u, v, t);
// where x in [rect.left, rect.right] and y in [rect.top, rect.bottom]
By the way, who can tell me how to load the current matrix to an array (double mymatrix[16]).
Please help me.
Thanks for your care
Smile | :)
GeneralRe: Small question about OpenGLmemberAli Khanlarkhani19 Jan '03 - 0:33 
This is how M3D(x, y, z) can be convert to M2D(x, y):
 
void Project(double x3D, double y3D, double z3D, double *pXWin, double *pYWin)
{
/* -------{ VARIABLE SECTION }------- */
GLdouble model_matrix[16];
GLdouble project_matrix[16];
GLint viewport[4];
double dummy_z;
/* -------{ INITIALIZATION SECTION }------- */
// Make Current Rendering context
/* -------{ MAIN SECTION }------- */
glGetDoublev(GL_MODELVIEW_MATRIX, model_matrix);
glGetDoublev(GL_PROJECTION_MATRIX, project_matrix);
glGetIntegerv(GL_VIEWPORT, viewport);
gluProject(x3D, y3D, z3D, model_matrix, project_matrix, viewport, pXWin, pYWin, &dummy_z);
/* -------{ RETURN SECTION }------- */
return;
}

GeneralHey ManmemberRick York16 Feb '02 - 13:09 
I just noticed that there is a link to this article at http://www.opengl.org. Very Cool ! Smile | :)
GeneralAn Easier Way....memberFatBuddha13 Feb '02 - 7:34 
You could of course just do exactly the same thing using gluPickMatrix:
 
//Initialise projection mode,...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
 
//...get viewport details,...
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
 
//...and create 'zoomport' details just like a normal viewport.
int zoomport[4];
zoomport[0] = //X of top left of zoom area
zoomport[1] = //Y of top left of zoom area
zoomport[2] = //Width of zoom area
zoomport[3] = //Height of zoom area
 
//Then use pickmatrix to zoom in on this part of the scene...
gluPickMatrix(zoomport[0]+zoomport[2]/2, zoomport[1]+zoomport[3]/2, zoomport[2], zoomport[3], viewport);
 
//...then set up your perspective view frustrum as normal
gluPerspective(m_FOV, m_ViewportAspect, m_FrustrumNear, m_FrustrumFar);
 
You figure out the zoomport values by catching mouse button up/down events, and you
can make a picking triangle in Windows using the DrawDragRect() function.
 
No disrespect intended to the author of this fine tutorial - just figured that some folks are looking for the meat.Smile | :)
 
FatBuddha:
 
None
GeneralRe: An Easier Way....memberpepito sbarzeguti13 Feb '02 - 21:30 
And if you change the size of window work ?
GeneralRe: An Easier Way....memberFatBuddha14 Feb '02 - 7:00 
You need to scale up the zoom values when the window is resized which is no biggy. Having said that, it is neater to alter the zoom values to be percentages of the original viewport window.
 
This means that you don't have to alter your zoom values on a window resize - and you can re-zoom much more easily. That's what I use anyhow.
 
Rob
 
None

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 12 Feb 2002
Article Copyright 2002 by pepito sbarzeguti
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid