如何使用键盘作为命令来放大opengl?

时间:2021-02-11 23:53:39

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++

我正在用Visio C ++编写一个OpenGL程序

2 个解决方案

#1


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.

放大OpenGL并获得键盘输入是两回事。您可以使用任何GUI(MFC,wxWidgets,Qt,.Net)来捕获键盘事件作为输入。然后,您可以调用OpenGL函数(glTranslate)来更改缩放,然后重绘场景中的所有内容。

#2


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

在Win32中,您可以执行以下操作来获取密钥的状态:

#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.

vKey是表示键ASCII值的int。

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.

实际上你会使用更复杂的代码来进行缩放,因为这当然取决于视图方向。此外,您还有一个更复杂的键状态函数,它将位于您的消息循环中,并保持您的应用程序将使用的所有键的状态,包括鼠标位置和鼠标按钮。

#1


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.

放大OpenGL并获得键盘输入是两回事。您可以使用任何GUI(MFC,wxWidgets,Qt,.Net)来捕获键盘事件作为输入。然后,您可以调用OpenGL函数(glTranslate)来更改缩放,然后重绘场景中的所有内容。

#2


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

在Win32中,您可以执行以下操作来获取密钥的状态:

#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.

vKey是表示键ASCII值的int。

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.

实际上你会使用更复杂的代码来进行缩放,因为这当然取决于视图方向。此外,您还有一个更复杂的键状态函数,它将位于您的消息循环中,并保持您的应用程序将使用的所有键的状态,包括鼠标位置和鼠标按钮。