views:

694

answers:

2

can anyone tell me how?

i've never done this before so i'm not sure as what library to use and how to call the command that a key pressed as a instruction rather than input..

i'm writing a OpenGL program in Visio C++

+3  A: 

Zooming in OpenGL and getting keyboar inputs are two different things. You can use whatever GUI (MFC, wxWidgets, Qt, .Net) to capture keyboard events as input. Then, you can call OpenGL functions (glTranslate) to change the zoom and then redraw everything in your scene.

Koray Balci
+1  A: 

In Win32 you can do something the following to get the state of a key:

#define KEY_DOWN(vKey)    (GetAsyncKeyState(vKey) & 0x8000) ? true : false
#define KEY_UP(vKey)      (GetAsyncKeyState(vKey) & 0x8000) ? false: true

vKey is an int representing the keys ASCII value.

When you know that the "zoom" key is being pressed, then you can do a translate

glPushMatrix();
    glTranslate3f(5.0,0.0,0.0); // moves the camera +5 down the x-axis
    ...
glPopMatrix();

Realistically you'd use more complex code to do the zoom as this is of course dependant on the view direction. Also you'd have a more complex key state function that would sit in your message loop and hold the state of all the keys your app would use including the mouse position and mouse buttons.

Dan Revell
where can i get reference on this??
noob88
Well the function itself can be found with a quick google. http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspxThis might not be the best direction to go however. You need to be more specific about how your creating the opengl window. Are you using GLUT for example?
Dan Revell