diff --git a/src/input.c b/src/input.c index 319923a..666a950 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); @@ -172,10 +171,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 508fa1e..68e27ef 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ float *generate_data_surface(unsigned int, unsigned char *); float *generate_normals_surface(float *, unsigned char); -struct projection projection = {.x = 0, .y=1, .z=2, .w=3 }; +struct projection projection = {.x = 0, .y = 1, .z = 2, .w = 3}; const char *wname = "manigraph: manifold grapher"; @@ -59,29 +59,27 @@ static inline { static float angle = 0; - if( angle > M_PI/2 ) + if (angle > M_PI / 2) { - animate_index=0; + animate_index = 0; angle = 0; - load_float_to_shader( shader, "angle", angle); - load_float_to_shader( shader_plain, "angle", angle); - set_projection_mesh( projection ); + load_float_to_shader(shader, "angle", angle); + load_float_to_shader(shader_plain, "angle", angle); + set_projection_mesh(projection); } - if( animate_index ) + if (animate_index) { - load_uint_to_shader( shader, "i", animate_index-1 ); - load_uint_to_shader( shader_plain, "i", animate_index-1 ); + load_uint_to_shader(shader, "i", animate_index - 1); + load_uint_to_shader(shader_plain, "i", animate_index - 1); - angle+=0.01; - load_float_to_shader( shader, "angle", angle); - load_float_to_shader( shader_plain, "angle", angle); + angle += 0.01; + load_float_to_shader(shader, "angle", angle); + load_float_to_shader(shader_plain, "angle", angle); } } - - clean_context(); #ifndef DEBUG @@ -93,11 +91,10 @@ static inline draw_mesh(m_axis, 1); #endif load_mdl_matrix(shader, 0, 3); - draw_mesh(m_surface,0); + draw_mesh(m_surface, 0); load_mdl_matrix(shader_plain, 0, 3); - draw_mesh(m_surface,1); - + draw_mesh(m_surface, 1); } int main(void) @@ -170,8 +167,7 @@ int main(void) projection.m = m; projection.mesh = m_surface; - set_projection_mesh( projection ); - + set_projection_mesh(projection); free(n_surface); free(d_surface); diff --git a/src/main.o b/src/main.o index 36f5d06..55c9e3b 100644 Binary files a/src/main.o and b/src/main.o differ diff --git a/src/mesh.c b/src/mesh.c index 0353741..59a7278 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -91,12 +91,12 @@ void destroy_mesh(mesh_t p) free(p); } -void draw_mesh(mesh_t p, char lines ) +void draw_mesh(mesh_t p, char lines) { struct obj *obj = p; glBindVertexArray(obj->vao); - if( lines ) + if (lines) { int i; for (i = 0; i < obj->vertex; i += 3) diff --git a/src/surface.c b/src/surface.c index 3e4aaa3..0207976 100644 --- a/src/surface.c +++ b/src/surface.c @@ -12,16 +12,16 @@ #endif #ifndef CMPLX -#define CMPLX(a,b) (a+I*b) +#define CMPLX(a, b) (a + I * b) #endif -void riemman(float *d_surface, int * coords, int grid_size) +void riemman(float *d_surface, int *coords, int grid_size) { complex double eq; float u = 2 * ((float)coords[0] / grid_size) - 1; float v = 2 * ((float)coords[1] / grid_size) - 1; - eq = csqrt(CMPLX(u,v)); + eq = csqrt(CMPLX(u, v)); d_surface[0] = u; d_surface[1] = v; @@ -29,16 +29,15 @@ void riemman(float *d_surface, int * coords, int grid_size) d_surface[3] = cimag(eq); } - -void cube( float *d_surface, int * coord, int grid_size ) +void cube(float *d_surface, int *coord, int grid_size) { unsigned char i; - for(int i=0; i<4; i++ ) - d_surface[i]=(float)coord[i]/grid_size; + for (int i = 0; i < 4; i++) + d_surface[i] = (float)coord[i] / grid_size; } -void mobius(float *d_surface, int * coord, int grid_size) +void mobius(float *d_surface, int *coord, int grid_size) { const float width = 0.5; float u = (2 * M_PI) * ((float)coord[0] / grid_size); @@ -49,7 +48,7 @@ void mobius(float *d_surface, int * coord, int grid_size) d_surface[2] = v * sin(u / 2); } -void torus(float *d_surface, int * coord, int grid_size) +void torus(float *d_surface, int *coord, int grid_size) { float u = (2 * M_PI) * ((float)coord[0] / grid_size); float v = (2 * M_PI) * ((float)coord[1] / grid_size); @@ -59,10 +58,10 @@ void torus(float *d_surface, int * coord, int grid_size) d_surface[2] = 0.5 * sin(v); } -void klein(float *d_surface, int * coord, int grid_size) +void klein(float *d_surface, int *coord, int grid_size) { float u = (2 * M_PI) * ((float)coord[0] / grid_size); - float v = (2 * M_PI) * ((float)coord[1]/ grid_size); + float v = (2 * M_PI) * ((float)coord[1] / grid_size); d_surface[0] = (0.5 * cos(v) + 0.5) * cos(u); d_surface[1] = (0.5 * cos(v) + 0.5) * sin(u); @@ -75,38 +74,38 @@ typedef void (*function_t)(float *, int *, int); float *generate_data_surface(int grid_size, unsigned char *s) { unsigned int i, j, k, o, p, l, n, m; - long size, q=0; + long size, q = 0; function_t f; float *d_surface; - const int dim =2; + const int dim = 2; int cara[dim]; - char bits[dim+1]; - bits[dim]=0; + char bits[dim + 1]; + bits[dim] = 0; - f =klein ; + f = klein; *s = 4; size = grid_size * grid_size * 6 * (*s) * 24; d_surface = malloc((size + 1) * sizeof(float)); d_surface[0] = size; - - for(o = 0; o < dim; o ++) - { + + for (o = 0; o < dim; o++) + { for (p = 0; p < o; p++) { - for (k = 0; k < (1 << (dim-2)); k++) + for (k = 0; k < (1 << (dim - 2)); k++) { - unsigned char skip=0; - for(n = 0; n < dim-2; n++) + unsigned char skip = 0; + for (n = 0; n < dim - 2; n++) { - if( n==(o-1) || n==p ) + if (n == (o - 1) || n == p) skip++; - cara[n+skip] = (k & (1<