Input changes
This commit is contained in:
47
src/Input.c
47
src/Input.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user