Click here to Skip to main content
15,881,639 members
Articles / Desktop Programming / MFC
Article

True OpenGL Zooming

Rate me:
Please Sign up or sign in to vote.
4.60/5 (17 votes)
11 Feb 2002 297.1K   9.9K   66   25
True zooming on a perspective view...

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


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAn Easier Way.... Pin
FatBuddha13-Feb-02 7:34
FatBuddha13-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.... Pin
pepito sbarzeguti13-Feb-02 21:30
pepito sbarzeguti13-Feb-02 21:30 
GeneralRe: An Easier Way.... Pin
FatBuddha14-Feb-02 7:00
FatBuddha14-Feb-02 7:00 
GeneralRe: An Easier Way.... Pin
Alberto Bencivenni12-Dec-05 3:06
Alberto Bencivenni12-Dec-05 3:06 
GeneralRe: An Easier Way.... Pin
a_david12321-Jun-07 23:36
a_david12321-Jun-07 23:36 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.