refactoring how Input works
This commit is contained in:
31
src/Input.c
31
src/Input.c
@@ -2,7 +2,7 @@
|
||||
|
||||
extern float pos[3];
|
||||
|
||||
/* 0: escape
|
||||
/* 0: nothing
|
||||
* 1: W
|
||||
* 2: S
|
||||
* 3: A
|
||||
@@ -10,27 +10,26 @@ extern float pos[3];
|
||||
*/
|
||||
|
||||
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 || key == GLFW_KEY_Q )&& action == GLFW_PRESS) glfwSetWindowShouldClose(window, true);
|
||||
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;
|
||||
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 ( key == GLFW_KEY_S && action == GLFW_PRESS ) pressed[2] = true;
|
||||
if ( key == GLFW_KEY_S && action == GLFW_RELEASE ) pressed[2] = false;
|
||||
if ( action == GLFW_PRESS ) pressed[index] = true;
|
||||
if ( action == GLFW_RELEASE ) pressed[index] = false;
|
||||
|
||||
if ( key == GLFW_KEY_A && action == GLFW_PRESS ) pressed[3] = true;
|
||||
if ( key == GLFW_KEY_A && action == GLFW_RELEASE ) pressed[3] = false;
|
||||
|
||||
if ( key == GLFW_KEY_D && action == GLFW_PRESS ) pressed[4] = true;
|
||||
if ( key == GLFW_KEY_D && action == GLFW_RELEASE ) pressed[4] = false;
|
||||
}
|
||||
|
||||
void processInput(){
|
||||
if (pressed[1]) pos[1] += 0.01f;
|
||||
if (pressed[2]) pos[1] -= 0.01f;
|
||||
if (pressed[3]) pos[0] -= 0.01f;
|
||||
if (pressed[4]) pos[0] += 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user