Added new inputHandler.c and changed main accordingly
This commit is contained in:
parent
cdc86eebad
commit
145947b784
|
@ -0,0 +1,80 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef INPUT_HANDLER_H
|
||||||
|
#define INPUT_HANDLER_H
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#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
|
59
src/main.c
59
src/main.c
|
@ -1,5 +1,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
@ -9,6 +12,8 @@
|
||||||
#include "matrixMath.h"
|
#include "matrixMath.h"
|
||||||
#include "transformation.h"
|
#include "transformation.h"
|
||||||
#include "wavefrontobj.h"
|
#include "wavefrontobj.h"
|
||||||
|
#include "inputHandler.h"
|
||||||
|
#include "inputHandler.c"
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "../lib/stb_image.h"
|
#include "../lib/stb_image.h"
|
||||||
|
@ -67,58 +72,6 @@ char* models[] = {
|
||||||
"../obj/Zblock.obj",
|
"../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.
|
* Loads textures.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue