diff --git a/include/buffers.h b/include/buffers.h index 54749e3..4cbc4fd 100644 --- a/include/buffers.h +++ b/include/buffers.h @@ -49,3 +49,4 @@ bool compute_space_and_arrows(int model_space_size_x, int buffer_lines_size, int buffer_plans_size); + diff --git a/src/graphics/buffers.c b/src/graphics/buffers.c index a3bc176..880d07c 100644 --- a/src/graphics/buffers.c +++ b/src/graphics/buffers.c @@ -42,6 +42,10 @@ #include "../../include/graphics.h" #include "../../include/buffers.h" +int vertex_ndx = 0; +int colors_ndx = 0; +int lines_ndx = 0; +int plans_ndx = 0; #define EDGE 0.999999 @@ -81,6 +85,8 @@ static bool compute_space_2D(int space_size_x, *(vertex_origin + k * 6 + 4) = - 1.0f / space_size_x; *(vertex_origin + k * 6 + 5) = 0.0f; + vertex_ndx += 6; + *(color_origin + k * 6 + 0) = 1; *(color_origin + k * 6 + 1) = 0; *(color_origin + k * 6 + 2) = 0; @@ -88,6 +94,13 @@ static bool compute_space_2D(int space_size_x, *(color_origin + k * 6 + 3) = 1; *(color_origin + k * 6 + 4) = 1; *(color_origin + k * 6 + 5) = 0; + + colors_ndx += 6; + + *(line_origin + k * 2 + 0) = k * 2 + 0; + *(line_origin + k * 2 + 1) = k * 2 + 1; + + lines_ndx += 2; } *(color_origin + 0) = 0; @@ -106,41 +119,40 @@ static bool compute_space_2D(int space_size_x, *(color_origin + (space_size_x - 1) * 6 + 4) = 0; *(color_origin + (space_size_x - 1) * 6 + 5) = 0; - if (S2) printf(" n = %d x 2 côté = [%1.1f]\n", space_size_x + 1, 2.0f / space_size_x); + colors_ndx += 12; - int line_ndx = 0; - for (int k = 0; k < space_size_x * 2; k++) *(line_origin + k) = k; - line_ndx += space_size_x * 2; + *(line_origin + lines_ndx + 0) = 0; + *(line_origin + lines_ndx + 1) = space_size_x * 2 - 2; // barre horizontale du bas - *(line_origin + line_ndx + 0) = 0; - *(line_origin + line_ndx + 1) = space_size_x * 2 - 2; // barre horizontale du bas + *(line_origin + lines_ndx + 2) = 1; + *(line_origin + lines_ndx + 3) = space_size_x * 2 - 1; // barre horizontale du haut - *(line_origin + line_ndx + 2) = 1; - *(line_origin + line_ndx + 3) = space_size_x * 2 - 1; // barre horizontale du haut - - if (S2) printf("space_2D line_origin (%d - space_size_x(0)) x (%d - space_size_x(1)) ", 0, 1); - - for (int v = 0; v < space_size_x + 2; v++) - if (S2) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1)); + lines_ndx += 4; if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit { - line_ndx += 4; - *(line_origin + line_ndx + 0) = 0; - *(line_origin + line_ndx + 1) = 3; - *(line_origin + line_ndx + 2) = 1; - *(line_origin + line_ndx + 3) = 2; + *(line_origin + lines_ndx + 0) = 0; + *(line_origin + lines_ndx + 1) = 3; + *(line_origin + lines_ndx + 2) = 1; + *(line_origin + lines_ndx + 3) = 2; + + lines_ndx += 4; } if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit { - line_ndx +=4; - *(line_origin + line_ndx + 0) = (space_size_x - 2) * 2 + 0; - *(line_origin + line_ndx + 1) = (space_size_x - 2) * 2 + 3; - *(line_origin + line_ndx + 2) = (space_size_x - 2) * 2 + 1; - *(line_origin + line_ndx + 3) = (space_size_x - 2) * 2 + 2; + *(line_origin + lines_ndx + 0) = (space_size_x - 2) * 2 + 0; + *(line_origin + lines_ndx + 1) = (space_size_x - 2) * 2 + 3; + *(line_origin + lines_ndx + 2) = (space_size_x - 2) * 2 + 1; + *(line_origin + lines_ndx + 3) = (space_size_x - 2) * 2 + 2; + + lines_ndx +=4; } + if (S2) printf(" n = %d x 2 côté = [%1.1f]\n", space_size_x + 1, 2.0f / space_size_x); + if (S2) printf("space_2D line_origin (%d - space_size_x(0)) x (%d - space_size_x(1)) ", 0, 1); + for (int v = 0; v < space_size_x + 2; v++) + if (S2) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1)); if (S2) printf(" n = 4 + (%d x 2)\n", space_size_x + 2); return 1; @@ -157,7 +169,7 @@ static int compute_arrow_2D(int space_size_x, int y, int z, - int pref_lines_planes_or_mix, + int pref_style_lines_planes, int pref_style_mix_colors, GLfloat *vertex_origin, @@ -175,41 +187,45 @@ static int compute_arrow_2D(int space_size_x, // float tip = center + (2 * site - 1) * (1.0f / space_size_x); float base = center + (2 * site - 1) * (0.1f / space_size_x); - int vgap = space_size_x * 6; + *(vertex_origin + vertex_ndx + 0) = center + (2 * site - 1) * (1.0f / space_size_x - 0.01f); + *(vertex_origin + vertex_ndx + 1) = zero; + *(vertex_origin + vertex_ndx + 2) = zero; - *(vertex_origin + vgap + 0) = center + (2 * site - 1) * (1.0f / space_size_x - 0.01f); - *(vertex_origin + vgap + 1) = zero; - *(vertex_origin + vgap + 2) = zero; + *(vertex_origin + vertex_ndx + 3) = base; + *(vertex_origin + vertex_ndx + 4) = 0.4f / space_size_x; + *(vertex_origin + vertex_ndx + 5) = zero; - *(vertex_origin + vgap + 3) = base; - *(vertex_origin + vgap + 4) = 0.4f / space_size_x; - *(vertex_origin + vgap + 5) = zero; + *(vertex_origin + vertex_ndx + 6) = base; + *(vertex_origin + vertex_ndx + 7) = - 0.4f / space_size_x; + *(vertex_origin + vertex_ndx + 8) = zero; - *(vertex_origin + vgap + 6) = base; - *(vertex_origin + vgap + 7) = - 0.4f / space_size_x; - *(vertex_origin + vgap + 8) = zero; + vertex_ndx += 9; - int lgap = space_size_x * 4; + if (pref_style_lines_planes == 0) { - if (pref_lines_planes_or_mix == 0) { - *(line_origin + lgap + 0) = vgap / 3 + 0; - *(line_origin + lgap + 1) = vgap / 3 + 1; - *(line_origin + lgap + 2) = vgap / 3 + 0; - *(line_origin + lgap + 3) = vgap / 3 + 2; - *(line_origin + lgap + 4) = vgap / 3 + 1; - *(line_origin + lgap + 5) = vgap / 3 + 2; + *(line_origin + lines_ndx + 0) = vertex_ndx / 3 + 0; + *(line_origin + lines_ndx + 1) = vertex_ndx / 3 + 1; + + *(line_origin + lines_ndx + 2) = vertex_ndx / 3 + 0; + *(line_origin + lines_ndx + 3) = vertex_ndx / 3 + 2; + + *(line_origin + lines_ndx + 4) = vertex_ndx / 3 + 1; + *(line_origin + lines_ndx + 5) = vertex_ndx / 3 + 2; + + lines_ndx += 6; } - int pgap = 0; - if (pref_lines_planes_or_mix == 1) { - *(plan_origin + pgap + 0) = vgap / 3 + 0; - *(plan_origin + pgap + 1) = vgap / 3 + 1; - *(plan_origin + pgap + 2) = vgap / 3 + 2; + if (pref_style_lines_planes == 1) { + *(plan_origin + plans_ndx + 0) = vertex_ndx / 3 + 0; + *(plan_origin + plans_ndx + 1) = vertex_ndx / 3 + 1; + *(plan_origin + plans_ndx + 2) = vertex_ndx / 3 + 2; - *(plan_origin + pgap + 3) = vgap / 3 + 0; - *(plan_origin + pgap + 4) = vgap / 3 + 1; - *(plan_origin + pgap + 5) = vgap / 3 + 2; + *(plan_origin + plans_ndx + 3) = vertex_ndx / 3 + 0; + *(plan_origin + plans_ndx + 4) = vertex_ndx / 3 + 1; + *(plan_origin + plans_ndx + 5) = vertex_ndx / 3 + 2; + + plans_ndx += 6; } return 0; } @@ -385,7 +401,7 @@ static bool compute_arrow_3D(int space_size_x, int y, int z, - int pref_lines_planes_or_mix, + int pref_style_lines_planes, int pref_style_mix_colors, GLfloat *vertex_origin, @@ -402,7 +418,7 @@ static bool compute_arrow_3D(int space_size_x, /* static bool compute_arrow_3D(int space_size_x, */ /* GLfloat *vertex_origin, GLfloat *color_origin, */ /* GLubyte *line_origin, GLubyte *plan_origin, */ -/* bool pref_lines_planes_or_mix, */ +/* bool pref_style_lines_planes, */ /* int vgap, int cgap, int lgap, int pgap, */ /* int weight, int site, int x, int y, int z) */ @@ -440,7 +456,7 @@ static bool compute_arrow_3D(int space_size_x, if (A3) printf("center = %f tip = %f base = %f\n",\ center, tip, base); // vgap=%d igap=%d - if (pref_lines_planes_or_mix == 0) { + if (pref_style_lines_planes == 0) { int lgap = space_size_x * 12; @@ -469,7 +485,7 @@ static bool compute_arrow_3D(int space_size_x, *(line_origin + lgap + 15) = vgap / 3 + 1; } - if (pref_lines_planes_or_mix == 1) { + if (pref_style_lines_planes == 1) { int pgap = 0; @@ -511,23 +527,25 @@ static void show_user_choices(int model_space_size_x, int buffer_lines_size, int buffer_plans_size) { - printf("buffers.compute x,y,z = (%d, %d, %d) ", model_space_size_x, model_space_size_y, model_space_size_z); + printf("model + user constraints : x,y,z = (%d, %d, %d) ", model_space_size_x, model_space_size_y, model_space_size_z); if (pref_3D_xor_2D_space == 0) printf("3D space "); if (pref_3D_xor_2D_space == 1) printf("2D space "); - if (pref_3D_xor_2D_arrows == 0) printf("3D arrows "); - if (pref_3D_xor_2D_arrows == 1) printf("2D arrows "); + if (model_arrows_nb > 0) printf("[%d] ", model_arrows_nb); + if (pref_3D_xor_2D_arrows == 0) printf("3D arrow(s) "); + if (pref_3D_xor_2D_arrows == 1) printf("2D arrow(s) "); if (pref_mark_unit_space == 0) printf("no unit_space marks "); if (pref_mark_unit_space == 1) printf("first unit space marked "); if (pref_mark_unit_space == 2) printf("last unit_space marked "); if (pref_mark_unit_space == 3) printf("first and last units space marked "); if (! pref_style_lines_planes) printf("style_lines_planes = 0 "); if (pref_style_lines_planes > 0)printf("style_lines_planes = %d ", pref_style_lines_planes); - if (! pref_style_mix_colors) printf("style_mix_colors = 0 "); - if (pref_style_mix_colors > 0)printf("style_mix_colors = %d ", pref_style_mix_colors); - printf("\n--------------- %d vertices %d colors %d lines %d plans\n[n] load site x (arrows array)\n", - buffer_vertex_size, buffer_colors_size, buffer_lines_size, buffer_plans_size); - - + if (! pref_style_mix_colors) printf("style_mix_colors = 0 "); + if (pref_style_mix_colors > 0) printf("style_mix_colors = %d ", pref_style_mix_colors); + printf("\n----------------- alloc : %4d/3 = %3d vertices, %4d/3 = %3d colors,\ + %4d/2 = %3d lines, %4d/3 = %3d plans\n[ n] load site x ---- < arrows array >\ + ----------------------------------------------------------------------\n", + buffer_vertex_size, buffer_vertex_size / 3, buffer_colors_size, buffer_colors_size / 3, + buffer_lines_size, buffer_lines_size / 2, buffer_plans_size, buffer_plans_size / 3); } #define SA 1 @@ -555,6 +573,24 @@ bool compute_space_and_arrows(int model_space_size_x, int buffer_plans_size) { + if (SA) show_user_choices(model_space_size_x, + model_space_size_y, + model_space_size_z, + + arrows, + model_arrows_nb, + + pref_3D_xor_2D_space, + pref_3D_xor_2D_arrows, + pref_mark_unit_space, + pref_style_lines_planes, + pref_style_mix_colors, + + buffer_vertex_size, + buffer_colors_size, + buffer_lines_size, + buffer_plans_size); + if (pref_3D_xor_2D_space) compute_space_2D (model_space_size_x, model_space_size_y, model_space_size_z, @@ -582,27 +618,9 @@ bool compute_space_and_arrows(int model_space_size_x, plan_origin); - if (SA) show_user_choices(model_space_size_x, - model_space_size_y, - model_space_size_z, - - arrows, - model_arrows_nb, - - pref_3D_xor_2D_space, - pref_3D_xor_2D_arrows, - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors, - - buffer_vertex_size, - buffer_colors_size, - buffer_lines_size, - buffer_plans_size); - // arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 } if (SA) for (int i = 0; i < model_arrows_nb; i++) { - printf("[%d] = %2d, %2d, %2d ",\ + printf("[%2d] = %2d, %2d, %2d \n",\ i, *(arrows + i * 3), *(arrows + i * 3 + 1), *(arrows + i * 3 + 2)); if (pref_3D_xor_2D_arrows) compute_arrow_2D(model_space_size_x, @@ -668,3 +686,4 @@ bool compute_space_and_arrows(int model_space_size_x, return 0; } + diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 0d363e6..cfd6f25 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -521,20 +521,16 @@ bool graphics_init_shaders(const void *gl_area) -/* -------------------------------------------------------------------------- */ -// TODO Tester (presque) toutes les combinaisons possibles de ces variables !!! -// NB mark_unit_space_first & last m'auront surtout servi à debuguer. À garder ? static void get_model_data_and_user_preferences(){ - model_space_size_x = 10; // 2 < model_space_size_x < 32 - model_arrows_nb = 1; // assert : leur emplacement est contraint par - // model_space_size_x, y, z et le nombre de sites - - pref_3D_xor_2D_space = 0; // 0 = 3D 1 = 2D - pref_3D_xor_2D_arrows = 0; // 0 = 3D 1 = 2D - pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both + model_space_size_x = 6; // 2 < model_space_size_x < 32 + model_arrows_nb = 1; // assert : l'emplacement des flèches est contraint + // par model_space_size_x, y, z et le nombre de sites + pref_3D_xor_2D_space = 1; // 0 = 3D 1 = 2D + pref_3D_xor_2D_arrows = 1; // 0 = 3D 1 = 2D + pref_mark_unit_space = 2; // 0 = no marks, 1 = 1st, 2 = last, 3 = both pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix pref_style_mix_colors = 0; // TODO } @@ -594,7 +590,6 @@ static void compute_buffers_sizes(int model_space_size_x, if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) buffer_lines_size += 4; // 2 diagonal lines if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) buffer_lines_size += 4; // 2 diagonal lines - /* buffer_plans_size est fonction de : model_space_size_x, model_arrows_nb et de pref_style_lines_planes */ if (0) printf("graphics.buffers_sizes : %u vertices, %u colors, %u lines, %u plans. (space_size_x = %d)\n",