Allow droping klein files
This commit is contained in:
37
src/input.c
37
src/input.c
@@ -9,7 +9,7 @@ unsigned char selected_axis = 0;
|
|||||||
int window_width;
|
int window_width;
|
||||||
int window_height;
|
int window_height;
|
||||||
|
|
||||||
unsigned char animate_index=0;
|
unsigned char animate_index = 0;
|
||||||
|
|
||||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
@@ -56,23 +56,22 @@ void __key_callback_input(
|
|||||||
projection.w = projection.x;
|
projection.w = projection.x;
|
||||||
projection.x = tmp;
|
projection.x = tmp;
|
||||||
|
|
||||||
animate_index=1;
|
animate_index = 1;
|
||||||
break;
|
break;
|
||||||
case GLFW_KEY_O:
|
case GLFW_KEY_O:
|
||||||
tmp = projection.w;
|
tmp = projection.w;
|
||||||
projection.w = projection.y;
|
projection.w = projection.y;
|
||||||
projection.y = tmp;
|
projection.y = tmp;
|
||||||
animate_index=2;
|
animate_index = 2;
|
||||||
break;
|
break;
|
||||||
case GLFW_KEY_P:
|
case GLFW_KEY_P:
|
||||||
tmp = projection.w;
|
tmp = projection.w;
|
||||||
projection.w = projection.z;
|
projection.w = projection.z;
|
||||||
projection.z = tmp;
|
projection.z = tmp;
|
||||||
animate_index=3;
|
animate_index = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,9 +113,9 @@ void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
|
|||||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||||
versor r = GLM_QUAT_IDENTITY_INIT;
|
versor r = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
//glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
|
// glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
|
||||||
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1,0,0});
|
glm_quatv(p, yoffset * ANGLE * 2, (vec3){-1, 0, 0});
|
||||||
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0,1,0});
|
glm_quatv(r, xoffset * ANGLE * 2, (vec3){0, 1, 0});
|
||||||
glm_quat_mul(p, q, q);
|
glm_quat_mul(p, q, q);
|
||||||
glm_quat_mul(r, 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]);
|
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)
|
quat_t poll_input(window_t window)
|
||||||
{
|
{
|
||||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||||
@@ -172,10 +188,11 @@ end:
|
|||||||
glm_quat_normalize(q);
|
glm_quat_normalize(q);
|
||||||
|
|
||||||
// LOG INFO
|
// 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("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");
|
printf("\n");
|
||||||
}
|
}
|
||||||
return q;
|
return q;
|
||||||
|
|||||||
39
src/main.c
39
src/main.c
@@ -15,7 +15,7 @@
|
|||||||
#define M_PI 3.14159
|
#define M_PI 3.14159
|
||||||
#endif
|
#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";
|
const char *wname = "manigraph: manifold grapher";
|
||||||
|
|
||||||
@@ -29,7 +29,6 @@ void mlog(char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
window_t window;
|
window_t window;
|
||||||
mesh_t m_surface;
|
|
||||||
id_t shader, shader_plain;
|
id_t shader, shader_plain;
|
||||||
|
|
||||||
extern volatile unsigned char animate_index;
|
extern volatile unsigned char animate_index;
|
||||||
@@ -75,8 +74,11 @@ static inline
|
|||||||
}
|
}
|
||||||
clean_context();
|
clean_context();
|
||||||
|
|
||||||
draw_mesh(shader, m_surface);
|
if (!projection.mesh)
|
||||||
draw_mesh_lines(shader_plain, m_surface);
|
return;
|
||||||
|
|
||||||
|
draw_mesh(shader, projection.mesh);
|
||||||
|
draw_mesh_lines(shader_plain, projection.mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -127,30 +129,6 @@ int main(void)
|
|||||||
fix_matrix_load(shader_plain, (float)WIDTH / HEIGHT);
|
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");
|
mlog("[MAIN LOOP] Inicializando...\n");
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
emscripten_set_main_loop(&main_loop, 60, 1);
|
emscripten_set_main_loop(&main_loop, 60, 1);
|
||||||
@@ -162,7 +140,7 @@ int main(void)
|
|||||||
mlog("[MAIN LOOP] Terminando...\n");
|
mlog("[MAIN LOOP] Terminando...\n");
|
||||||
|
|
||||||
mlog("[MESH] Destruyendo...\n");
|
mlog("[MESH] Destruyendo...\n");
|
||||||
destroy_mesh(m_surface);
|
destroy_mesh(projection.mesh);
|
||||||
mlog("[SHADER] Destruyendo...\n");
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
destroy_shader(shader_plain);
|
destroy_shader(shader_plain);
|
||||||
mlog("[SHADER] Destruyendo...\n");
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
@@ -172,9 +150,6 @@ int main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_context:
|
error_context:
|
||||||
mlog("[MESH] Destruyendo...\n");
|
|
||||||
destroy_mesh(m_surface);
|
|
||||||
error_mesh_surface:
|
|
||||||
mlog("[SHADER] Destruyendo...\n");
|
mlog("[SHADER] Destruyendo...\n");
|
||||||
destroy_shader(shader_plain);
|
destroy_shader(shader_plain);
|
||||||
error_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 __mouse_callback_input(GLFWwindow *, int, int, int);
|
||||||
void __scroll_callback_input(GLFWwindow *, double, double);
|
void __scroll_callback_input(GLFWwindow *, double, double);
|
||||||
void __key_callback_input(GLFWwindow *, int, int, int, int);
|
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);
|
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);
|
glfwSetMouseButtonCallback((GLFWwindow *)window, __mouse_callback_input);
|
||||||
glfwSetScrollCallback((GLFWwindow *)window, __scroll_callback_input);
|
glfwSetScrollCallback((GLFWwindow *)window, __scroll_callback_input);
|
||||||
glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input);
|
glfwSetKeyCallback((GLFWwindow *)window, __key_callback_input);
|
||||||
|
glfwSetDropCallback((GLFWwindow *)window, __drop_callback_input);
|
||||||
|
|
||||||
__window_callback_input((GLFWwindow *)window, width, height);
|
__window_callback_input((GLFWwindow *)window, width, height);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user