diff --git a/src/inputHandler.c b/src/inputHandler.c new file mode 100644 index 0000000..8c1372d --- /dev/null +++ b/src/inputHandler.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include "matrixMath.h" +#include "inputHandler.h" + +// Definition der externen Variablen +extern bool exitRequested; +extern GLFWwindow *window; +extern vec3 cameraPosition; +extern vec3 objectPosition; +extern GLfloat radius; + +/** + * Input handler for camera movement. + */ +void handleInputs(double deltaTime) +{ + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) + { + cameraPosition.z += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) + { + cameraPosition.z -= deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) + { + cameraPosition.x += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) + { + cameraPosition.x -= deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) + { + cameraPosition.y += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) + { + cameraPosition.y -= deltaTime * 10; + } + + if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) + { + objectPosition.x += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS) + { + objectPosition.x -= deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_I) == GLFW_PRESS) + { + objectPosition.z += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) + { + objectPosition.z -= deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) + { + radius += deltaTime * 10; + } + if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) + { + radius -= deltaTime * 10; + } +} + +// input handler to quit with ESC +void keyboardHandler(GLFWwindow *window, int key, int scancode, int action, int mods) +{ + if (action == GLFW_PRESS) + { + if (key == GLFW_KEY_ESCAPE) + { + exitRequested = true; + } + } +} diff --git a/src/inputHandler.h b/src/inputHandler.h new file mode 100644 index 0000000..ca16f82 --- /dev/null +++ b/src/inputHandler.h @@ -0,0 +1,16 @@ +#ifndef INPUT_HANDLER_H +#define INPUT_HANDLER_H + +#include +#include "matrixMath.h" + +extern bool exitRequested; +extern GLFWwindow *window; +extern vec3 cameraPosition; +extern vec3 objectPosition; +extern GLfloat radius; + +void handleInputs(double deltaTime); +void keyboardHandler(GLFWwindow *window, int key, int scancode, int action, int mods); + +#endif diff --git a/src/main.c b/src/main.c index 8a694d6..74c032f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,8 @@ #include - +#include +#include +#include +#include #include #include @@ -9,6 +12,8 @@ #include "matrixMath.h" #include "transformation.h" #include "wavefrontobj.h" +#include "inputHandler.h" +#include "inputHandler.c" #define STB_IMAGE_IMPLEMENTATION #include "../lib/stb_image.h" @@ -67,58 +72,6 @@ char* models[] = { "../obj/Zblock.obj", }; -/** - * Input handler for camera movement. - * */ -void handleInputs(double deltaTime) { - if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { - cameraPosition.z += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { - cameraPosition.z -= deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { - cameraPosition.x += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { - cameraPosition.x -= deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) { - cameraPosition.y += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { - cameraPosition.y -= deltaTime * 10; - } - - if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) { - objectPosition.x += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS) { - objectPosition.x -= deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_I) == GLFW_PRESS) { - objectPosition.z += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) { - objectPosition.z -= deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) { - radius += deltaTime * 10; - } - if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) { - radius -= deltaTime * 10; - } -} - -// input handler to quit with ESC -void keyboardHandler(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (action == GLFW_PRESS) { - if (key == GLFW_KEY_ESCAPE) { - exitRequested = true; - } - } -} - /** * Loads textures. */