diff options
author | sanine-a <sanine.not@pm.me> | 2020-05-22 22:30:07 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-05-22 22:30:07 -0500 |
commit | ad50ee243d9d7ac30ef507acd01bbc4ccb02f862 (patch) | |
tree | b44b2f6da3bdd7753008a4f42552f231c65c6068 /demo.c | |
parent | e02ac3c921d816945324f1a887a0ed1db12f342e (diff) |
add keyboard input
Diffstat (limited to 'demo.c')
-rw-r--r-- | demo.c | 43 |
1 files changed, 16 insertions, 27 deletions
@@ -18,7 +18,6 @@ honey_texture happy_face; mat4 model, view, projection; bool wireframe = false; -bool fKeyDown = false; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -58,57 +57,45 @@ void mouseCallback(GLFWwindow* window, double x, double y) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -void print_vec3(vec3 v) { - printf("(%f, %f, %f)\n", v[0], v[1], v[2]); +void toggle_wireframe(void* data, int action) { + if (action == HONEY_PRESS_KEY) { wireframe = !wireframe; } } +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + void update(float dt) { glfwPollEvents(); - printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); - print_vec3(camera.look_direction); - print_vec3(camera.up); - print_vec3(camera.right); - - //glm_rotate_x(model, glm_rad(10*dt), model); + glm_rotate_x(model, glm_rad(10*dt), model); - if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_ESCAPE)) { glfwSetWindowShouldClose(window, true); } - if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) { - if (!fKeyDown) { - wireframe = !wireframe; - fKeyDown = true; - } - } - if (glfwGetKey(window, GLFW_KEY_F) == GLFW_RELEASE) { - fKeyDown = false; - } - if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_W)) { vec3 step; glm_vec3_scale(camera.look_direction, cameraSpeed*dt, step); glm_vec3_add(camera.position, step, camera.position); } - if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_S)) { vec3 step; glm_vec3_scale(camera.look_direction, -cameraSpeed*dt, step); glm_vec3_add(camera.position, step, camera.position); } - if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_A)) { vec3 step; glm_vec3_scale(camera.right, cameraSpeed*dt, step); glm_vec3_add(camera.position, step, camera.position); } - if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_D)) { vec3 step; glm_vec3_scale(camera.right, -cameraSpeed*dt, step); glm_vec3_add(camera.position, step, camera.position); } - if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_E)) { camera.angle[2] += camera_roll_speed*dt; } - if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { + if (honey_key_down(HONEY_KEY_Q)) { camera.angle[2] -= camera_roll_speed*dt; } @@ -149,6 +136,8 @@ int main() { honey_set_resize_callback(window, framebufferResizeCallback); honey_set_mouse_move_callback(window, mouseCallback); + honey_key_bind(HONEY_KEY_F, toggle_wireframe, NULL); + /* load container texture */ if (honey_texture_new(&container, "container.jpg", false) != TEXTURE_OK) { return 1; @@ -175,8 +164,8 @@ int main() { //glm_rotate_x(model, glm_rad(-55), model); honey_shader_set_mat4(shader, "model", model); - vec3 camera_pos = { 4, 0, 0 }; - vec3 camera_angle = { 0, glm_rad(180), 0 }; + vec3 camera_pos = { -4, 0, 0 }; + vec3 camera_angle = { 0, 0, 0 }; float camera_near = 0.1; float camera_far = 100; float camera_fov = glm_rad(45); |