🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to Zoom

Started by
3 comments, last by Steve132 17 years, 8 months ago
below is my zoom function,but it not working.i duno why. void keyboard(unsigned char key, int x, int y) { //printf("keyboard:%d, %d, %d\n", key, x,y); switch (key) { case 'w': glTranslatef(0.0f,0.0f,-5.0f); break; case 's': glTranslatef(0.0f,0.0f,5.0f); break; } }
Advertisement
1. What kind of input are you using to feed the key variable.

2. when you do get it working you will find that
a) it won't work well
b) it's not actually zooming, it's like zooming in by walking closer to it, it does get bigger, but it's not zooming, try changing the first parameter in gluPerspective , that will result in a better zoom effect.

Scaling the entire screen about the position of the camera should also work.
okok i tried
Judging by your function, you are calling that function every time the specific keyboard button is hit.

glTranslate doesn't persist across every frame if you are calling glLoadIdentity() at any point. What I mean is, that if you call glTranslate in a keypress function, it probably does nothing. It might zoom for less then one frame but immediately snap back before the next frame begins, or even before rendering on this one begins. I would fix the problem by modifying a variable in the keypress function, and using that variable to constantly translate by in the right part of the render function.


float zoomF=0.0;void keyboard(unsigned char key, int x, int y){     //printf("keyboard:%d, %d, %d\n", key, x,y);     switch (key)     {         case 'w':              zoomf-=5.0;              break;         case 's':              zoomf+=5.0;              break;     }}//then, somewhere inside render function., after glLoadIdentity():..glTranslatef(0.0f,0.0f,zoomf);//render stuff..

This topic is closed to new replies.

Advertisement