diff --git a/src/input.c b/src/input.c index 319923a..8a0f1a8 100644 --- a/src/input.c +++ b/src/input.c @@ -9,7 +9,7 @@ unsigned char selected_axis = 0; int window_width; int window_height; -unsigned char animate_index=0; +unsigned char animate_index = 0; versor q = GLM_QUAT_IDENTITY_INIT; @@ -56,23 +56,22 @@ void __key_callback_input( projection.w = projection.x; projection.x = tmp; - animate_index=1; + animate_index = 1; break; case GLFW_KEY_O: tmp = projection.w; projection.w = projection.y; projection.y = tmp; - animate_index=2; + animate_index = 2; break; case GLFW_KEY_P: tmp = projection.w; projection.w = projection.z; projection.z = tmp; - animate_index=3; + animate_index = 3; break; } - return; } @@ -114,9 +113,9 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset) versor p = GLM_QUAT_IDENTITY_INIT; versor r = GLM_QUAT_IDENTITY_INIT; - //glm_quatv(p, yoffset * ANGLE, axis[selected_axis]); - glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1,0,0}); - glm_quatv(r, xoffset * ANGLE * 2, (vec3){0,1,0}); + // glm_quatv(p, yoffset * ANGLE, axis[selected_axis]); + glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1, 0, 0}); + glm_quatv(r, xoffset * ANGLE * 2, (vec3){0, 1, 0}); glm_quat_mul(p, q, q); glm_quat_mul(r, q, q); @@ -129,6 +128,23 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset) glm_quat_rotatev(r, axis[2], axis[2]); } +void __drop_callback_input(GLFWwindow *window, int count, char **path) +{ + struct surface surface; + + if (create_surface_klein(*path, &surface)) + return; + + if (!(projection.mesh = create_mesh(surface))) + return; + + projection.m = surface.dim; + set_projection_mesh(projection); + + free(surface.norm); + free(surface.data); +} + quat_t poll_input(window_t window) { versor p = GLM_QUAT_IDENTITY_INIT; @@ -172,10 +188,11 @@ end: glm_quat_normalize(q); // LOG INFO - if(0) + if (0) { printf("QUAT: %2.5f %2.5f %2.5f %2.5f\n", q[0], q[1], q[2], q[3]); - printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y, projection.z, projection.w ); + printf("PROY: %3d %3d %3d (%3d)\n", projection.x, projection.y, + projection.z, projection.w); printf("\n"); } return q; diff --git a/src/main.c b/src/main.c index 15dddc2..224a7f0 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ #define M_PI 3.14159 #endif -struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3}; +struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3, .mesh = NULL}; const char *wname = "manigraph: manifold grapher"; @@ -29,7 +29,6 @@ void mlog(char *msg) } window_t window; -mesh_t m_surface; id_t shader, shader_plain; extern volatile unsigned char animate_index; @@ -75,8 +74,11 @@ static inline } clean_context(); - draw_mesh(shader, m_surface); - draw_mesh_lines(shader_plain, m_surface); + if (!projection.mesh) + return; + + draw_mesh(shader, projection.mesh); + draw_mesh_lines(shader_plain, projection.mesh); } int main(void) @@ -127,30 +129,6 @@ int main(void) fix_matrix_load(shader_plain, (float)WIDTH / HEIGHT); } - mlog("[MESH] Inicializando...\n"); - { - struct surface surface; - - if( create_surface_klein("test.klein", &surface) ) - { - mlog("[MESH] Error al leer el archivo...\n"); - goto error_mesh_surface; - } - - if (!(m_surface = create_mesh(surface))) - { - mlog("[MESH] Error al inicializar...\n"); - goto error_mesh_surface; - } - - projection.m = surface.dim; - projection.mesh = m_surface; - set_projection_mesh(projection); - - free(surface.norm); - free(surface.data); - } - mlog("[MAIN LOOP] Inicializando...\n"); #ifdef EMSCRIPTEN emscripten_set_main_loop(&main_loop, 60, 1); @@ -162,7 +140,7 @@ int main(void) mlog("[MAIN LOOP] Terminando...\n"); mlog("[MESH] Destruyendo...\n"); - destroy_mesh(m_surface); + destroy_mesh(projection.mesh); mlog("[SHADER] Destruyendo...\n"); destroy_shader(shader_plain); mlog("[SHADER] Destruyendo...\n"); @@ -172,9 +150,6 @@ int main(void) return 0; error_context: - mlog("[MESH] Destruyendo...\n"); - destroy_mesh(m_surface); -error_mesh_surface: mlog("[SHADER] Destruyendo...\n"); destroy_shader(shader_plain); error_shader_plain: diff --git a/src/window.c b/src/window.c index 2354aa6..521e673 100644 --- a/src/window.c +++ b/src/window.c @@ -7,6 +7,7 @@ void __window_callback_input(GLFWwindow *, int, int); void __mouse_callback_input(GLFWwindow *, int, int, int); void __scroll_callback_input(GLFWwindow *, double, double); void __key_callback_input(GLFWwindow *, int, int, int, int); +void __drop_callback_input(GLFWwindow *, int, const char **); window_t init_window(unsigned int w, unsigned int h, const char *name); @@ -64,6 +65,7 @@ window_t init_window(unsigned int width, unsigned int height, const char *title) glfwSetMouseButtonCallback((GLFWwindow *)window, __mouse_callback_input); glfwSetScrollCallback((GLFWwindow *)window, __scroll_callback_input); glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input); + glfwSetDropCallback((GLFWwindow *)window, __drop_callback_input); __window_callback_input((GLFWwindow *)window, width, height);