Allow droping klein files
This commit is contained in:
21
src/input.c
21
src/input.c
@@ -72,7 +72,6 @@ void __key_callback_input(
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -175,7 +191,8 @@ end:
|
||||
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;
|
||||
|
||||
39
src/main.c
39
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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user