Zoom in openGL
Hi can anyone help me with zoom in openGL. I m using orthographic projection. I just need simple zoom in and zoom out.. I m very new to openGL so askign too many questions.
Although I've never actually written a zoom feature in ortho mode, I'm guessing you'll want to adjust the parameters to glOrtho() so as to change the width and height of the view volume; smaller will zoom in, larger will zoom out. If you need more details, you might post the code where you call glOrtho() so we can give you a more concrete example.
Again though, I'm kind of guessing here; perhaps someone else can give a more authorititive answer.
Again though, I'm kind of guessing here; perhaps someone else can give a more authorititive answer.
Yes u can use glOrtho and acheive zooming . That will be true zooming and not scaling .
To zoom in
you reduce the distance between the left and right params and top and bottom params to glOrtho
In effect you are reducing the viewing volume and and the size of the near plane , which is still going to be mapped onto your fixed size VIEWPORT , your screen. So u magnify the view!
To zoom out increase the the params mentioned above , you should get the desired effect.
post back if you have a problem understanding what i have said.
To zoom in
you reduce the distance between the left and right params and top and bottom params to glOrtho
In effect you are reducing the viewing volume and and the size of the near plane , which is still going to be mapped onto your fixed size VIEWPORT , your screen. So u magnify the view!
To zoom out increase the the params mentioned above , you should get the desired effect.
post back if you have a problem understanding what i have said.
My glortho command is as follows:
and i m doing the following
but im not getting desired result.
glOrtho(-1.5, 1.0, -2.0, 0.5, -1.0, 3.5);
and i m doing the following
case 'o' : zoom = zoom - 0.5; glMatrixMode(GL_MODELVIEW); glOrtho(-1.5 + zoom, 1.0 + zoom, -2.0 + zoom, 0.5 + zoom, -1.0, 3.5); break;
but im not getting desired result.
Try:
zoom = zoom - 0.5; // Or whatever you want the step to beglMatrixMode(GL_PROJECTION); // You had GL_MODELVIEWglOrtho(-1.5 + zoom, 1.0 - zoom, -2.0 + zoom, 0.5 - zoom, -1.0, 3.5); // Changed some of the signs here
The results of these particular values (off-center view volume and relatively large zoom step) may or may not work so well, but you can adjust them if necessary.
Ya thanks very much its workign perfectly.....I was wondering like can I adda slide bar to do this instead of pressing keys u know...
Quote:Original post by SrinidhiOpenGL doesn't offer any built-in GUI support, but there are some free libraries available around the net. For something as simple as a slider though, another option would be to just implement it yourself.
I was wondering like can I adda slide bar to do this instead of pressing keys u know...
This is how i do it
The setViewingVolume function is as below
It does the glOrtho call
void CCamera::zoomIn(){ m_d_left_plane *= 0.75f; m_d_right_plane *= 0.75f; m_d_top_plane *= 0.75f; m_d_bottom_plane *= 0.75f; setViewingVolume();}void CCamera::zoomOut(){ m_d_left_plane *= 1.33f; m_d_right_plane *= 1.33f; m_d_top_plane *= 1.33f; m_d_bottom_plane *= 1.33f; setViewingVolume();}
The setViewingVolume function is as below
It does the glOrtho call
void CCamera::setViewingVolume(){ double aspect_ratio = (double)canvas_width/(double)canvas_height; glViewport( 0,0,(int)canvas_width , (int )canvas_height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if( canvas_width > canvas_height ){ glOrtho(m_d_left_plane*aspect_ratio,m_d_right_plane*aspect_ratio,m_d_bottom_plane,m_d_top_plane,m_d_near_plane,m_d_far_plane); }else{ glOrtho(m_d_left_plane,m_d_right_plane,m_d_bottom_plane*aspect_ratio,m_d_top_plane*aspect_ratio,m_d_near_plane,m_d_far_plane); } updateZoomFactors(); glMatrixMode( GL_MODELVIEW ); }
you can also just use glRotatef(Zoom, 0, 0, 0); when in ortho mode. However the last translate must be center screen or it will zoom from last tranlate position.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement