Hello,
Whats the best way to zoom in and out.
Thanks for helping
Zooming
Started by Noor, Feb 09 2003 06:48 AM
5 replies to this topic
#1
Posted 09 February 2003 - 06:48 AM
"What ever happened to happily ever after?"
#2
Posted 09 February 2003 - 09:43 AM
there is no way to really 'zoom' in OpenGL. The camera stays at 0, 0, 0 looking along the z axis. Everything else moves around it. The best way to zoom out object a is to translate it further away, eg.
glTranslatef(APosX, APosY, APosZ);
glTranslatef(0.0f, 0.0f, -Zoom);
DrawObjectA();
then as zoom increases, the object gets further away
watch out though, anything drawn after that will be 'zoomed' as well.
glTranslatef(APosX, APosY, APosZ);
glTranslatef(0.0f, 0.0f, -Zoom);
DrawObjectA();
then as zoom increases, the object gets further away
watch out though, anything drawn after that will be 'zoomed' as well.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
#3
Posted 09 February 2003 - 11:00 AM
Actually u can zoom with OpenGL by altering ur viewing matrix using the gluPerspective(..) function.
The actuall function parameter is as follows:
To do zooming the first parameter is the one u wnat to alter. The smaller the angle u specify the greater the zoom. Try experimenting and u'll see this in action.
The advantage of using this technique over the one above is that u won't get into a situation where u zoom past an object because u aren't actually repositioning any objects.
The disadvantage is that everytime u want to zoom or animate zooming and zooming out u have to recreate ur perspective viewing transformation. Well this isn't too bad.
The actuall function parameter is as follows:
void gluPerspective( float angle, // the viewable anlge infront of the camera/eye float aspect, // typically width/height of window or screen float near, // min distance from camera that is renderable float far, // max distance from camera that is renderable )
To do zooming the first parameter is the one u wnat to alter. The smaller the angle u specify the greater the zoom. Try experimenting and u'll see this in action.
The advantage of using this technique over the one above is that u won't get into a situation where u zoom past an object because u aren't actually repositioning any objects.
The disadvantage is that everytime u want to zoom or animate zooming and zooming out u have to recreate ur perspective viewing transformation. Well this isn't too bad.
#4
Posted 09 February 2003 - 07:26 PM
the non-glu way is to use glOrtho and glMatrixMode
here are references to both:
http://www.cevis.uni-bremen.de/~uwe/opengl...gl/glOrtho.html
http://www.cevis.uni-bremen.de/~uwe/opengl...MatrixMode.html
example:
remember, in glMatrixMode, you can only get the effect of zooming in or out with GL_MODELVIEW. only use GL_PROJECTION to do non-zooming effects like a menu system or the like.
If I offended you with any of this, please accept my apologies. I've seen way too many questions as to why people can't zoom in and out and when they show their code, they're using GL_PROJECTION.
cheers.
here are references to both:
http://www.cevis.uni-bremen.de/~uwe/opengl...gl/glOrtho.html
http://www.cevis.uni-bremen.de/~uwe/opengl...MatrixMode.html
example:
void window_scene2D()
{
glViewport(left, top, width, height);
glOrtho(left, right, bottom, top, near, far);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
/////////////////////////////////////////
void window_scene3D()
{
glViewport(left, top, width, height);
glMatrixMode(GL_MODELVIEW);
glOrtho(left, right, bottom, top, near, far);
glLoadIdentity();
}
remember, in glMatrixMode, you can only get the effect of zooming in or out with GL_MODELVIEW. only use GL_PROJECTION to do non-zooming effects like a menu system or the like.
If I offended you with any of this, please accept my apologies. I've seen way too many questions as to why people can't zoom in and out and when they show their code, they're using GL_PROJECTION.
cheers.
Imagine.
#5
Posted 10 February 2003 - 01:16 PM
Yau said:
The disadvantage is that everytime u want to zoom or animate zooming and zooming out u have to recreate ur perspective viewing transformation. Well this isn't too bad.
#6
Posted 10 February 2003 - 03:48 PM
interesting point.
the fewer the number of objects in space, the easier it is to translate the objects instead of recalculating the perspective matrix. the greater the number of objects, the more likely that it will be eaiser to recalc the perspective matrix than it is to translate all the objects.
of course, you can come up with algorithms the decide which of the two OR maybe even make it so that if you just translate, to only translate in the view frustum.
cheers.
the fewer the number of objects in space, the easier it is to translate the objects instead of recalculating the perspective matrix. the greater the number of objects, the more likely that it will be eaiser to recalc the perspective matrix than it is to translate all the objects.
of course, you can come up with algorithms the decide which of the two OR maybe even make it so that if you just translate, to only translate in the view frustum.
cheers.
Imagine.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












