Input changes

This commit is contained in:
2022-07-10 00:25:07 +02:00
parent e4ac76be59
commit d2d5666aa5

View File

@@ -2,41 +2,34 @@
extern float pos[3];
/* 0: escape
/* 0: nothing
* 1: W
* 2: S
* 3:
* 3: A
* 4: D
*/
static bool pressed[5];
static int index;
void key_pressed(GLFWwindow* window, int key, int scancode, int action, int mods){
if ( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS){
glfwSetWindowShouldClose(window, true);
}
if ( key == GLFW_KEY_Q && action == GLFW_PRESS ){
glfwSetWindowShouldClose(window, true);
}
if ( key == GLFW_KEY_W && action == GLFW_PRESS ){
pressed[1] = true;
}
if ( key == GLFW_KEY_W && action == GLFW_RELEASE ){
pressed[1] = false;
}
if ( key == GLFW_KEY_S && action == GLFW_PRESS ){
pressed[2] = true;
}
if ( key == GLFW_KEY_S && action == GLFW_RELEASE ) {
pressed[2] = false;
}
if ( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, true);
if ( key == GLFW_KEY_Q && action == GLFW_PRESS ) glfwSetWindowShouldClose(window, true);
index = 0;
if ( key == GLFW_KEY_W ) index = 1;
if ( key == GLFW_KEY_S ) index = 2;
if ( key == GLFW_KEY_A ) index = 3;
if ( key == GLFW_KEY_D ) index = 4;
if ( action == GLFW_PRESS ) pressed[index] = true;
if ( action == GLFW_RELEASE ) pressed[index] = false;
}
void processInput(){
if (pressed[1] == true){
pos[1] += 0.01f;
}
if (pressed[2] == true){
pos[1] -= 0.01f;
}
if (pressed[1] == true) pos[1] += 0.01f;
if (pressed[2] == true) pos[1] -= 0.01f;
if (pressed[3] == true) pos[0] -= 0.01f;
if (pressed[4] == true) pos[0] += 0.01f;
}