From 8014cc2a602410bdcb5710e66740bd1ca2fcd703 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 3 Oct 2023 14:58:37 +0200 Subject: [PATCH] WIP: affichages graphique et console concordants; pas d'erreurs (sur qq. essais) une 'Exception en point flottant' --- src/graphics/arrows.c | 14 +++++------ src/graphics/graphics.c | 54 +++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index 32681f3..7756bb0 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -42,7 +42,7 @@ */ void arrows_write_terminations (long x, long y, long z) { - float max, i, j, k, vx, vy, vz, arrow_basis_width, arrow_tip_padding; + float max, i, j, k, vx, vy, vz, arrow_basis_width, arrow_tip_padding, nuance = 0.12f; max = fmax(x, y); max = fmax(max, z); @@ -82,20 +82,20 @@ void arrows_write_terminations (long x, long y, long z) // X - X (EAST - WEST) axis - arrows tips graphics_write_vertex (vx + (1 / max) - arrow_tip_padding, vy, vz); graphics_write_vertex (vx - (1 / max) + arrow_tip_padding, vy, vz); - graphics_write_color(1.0f, 0.0f, 0.0f); - graphics_write_color(0.0f, 1.0f, 1.0f); + graphics_write_color(1.0f - nuance, 0.0f + nuance, 0.0f + nuance); + graphics_write_color(0.0f + nuance, 1.0f - nuance, 1.0f - nuance); // Y - Y (ZENITH - NADIR) axis - arrows tips graphics_write_vertex (vx, vy + (1 / max) - arrow_tip_padding, vz); graphics_write_vertex (vx, vy - (1 / max) + arrow_tip_padding, vz); - graphics_write_color(0.0f, 1.0f, 0.0f); - graphics_write_color(1.0f, 0.0f, 1.0f); + graphics_write_color(0.0f + nuance, 1.0f - nuance, 0.0f + nuance); + graphics_write_color(1.0f - nuance, 0.0f + nuance, 1.0f - nuance); // Z - Z (NORTH - SOUTH) axis - arrows tips graphics_write_vertex (vx, vy, vz + (1 / max) - arrow_tip_padding); graphics_write_vertex (vx, vy, vz - (1 / max) + arrow_tip_padding); - graphics_write_color(0.0f, 0.0f, 1.0f); - graphics_write_color(1.0f, 1.0f, 0.0f); + graphics_write_color(0.0f + nuance, 0.0f + nuance, 1.0f - nuance); + graphics_write_color(1.0f - nuance, 1.0f - nuance, 0.0f + nuance); }; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 3455356..cf56ead 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -596,15 +596,16 @@ static void show_arrows_array (GLuint *arrows, int arrows_nb, int x, int y, int */ static void show_user_choices(GLuint *arrows, int arrows_nb, int space_size_x, int space_size_y, int space_size_z, - int prefer, int show_all) + int prefer, int show_all, int show_array) { + if (show_array) printf("\n"); printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\t", space_size_x, space_size_y, space_size_z); if (prefer == 0) printf("prefer = %d <> show all grids", prefer); if (prefer == 1) printf("prefer = %d <> show no grid", prefer); if (prefer > 1) printf("show grids according rule (%d)", prefer); if (show_all) printf("\n\ initial arrows data arrows_nb = %d", arrows_nb); - show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z); + if (show_array) show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z); } /* @@ -620,7 +621,7 @@ static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrow printf("\n - - - - - - - - - - - - - - - - - - - - - - - - - - - -"); printf("\n buffer_vertex_offset_after grids = %6d\t%6d = (x+1)*(y+1)*(z+1); <--> (x,y,z = %d,%d,%d)",\ - offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z); + offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z); printf("\n buffer_vertex_offset_after arrows = %6d\t%6d = %d + %d; <--> %d = 12 x %d (there are %d cubes)",\ offset_after_arrows, offset_after_arrows, offset_after_grids,\ @@ -641,7 +642,8 @@ static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrow arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes),\ (arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes)) / arrows_nb, arrows_nb); - printf("\n WARNING In this test, it may happens that two or several arrow basis are drawn superimposed (check the list).\n"); + if (arrows_nb > 1) + printf("\n WARNING In this test, it may happens that two or several arrow basis are drawn superimposed (check the list).\n"); } @@ -671,7 +673,8 @@ static int rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight { *(arrows + address * 5 + 0) = weight; - if (! TEST) show_arrows_array (arrows, arrows_nb, x, y, z); + // if (! TEST) + show_arrows_array (arrows, arrows_nb, x, y, z); return arrows_nb; } @@ -694,7 +697,8 @@ static int create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, in arrows_nb ++; - if (! TEST) show_arrows_array (arrows, arrows_nb, x, y, z); + // if (! TEST) + show_arrows_array (arrows, arrows_nb, x, y, z); return arrows_nb; } @@ -717,7 +721,8 @@ static int erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, in buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint)); - if (! TEST) show_arrows_array (arrows, arrows_nb, x, y, z); + // if (! TEST) + show_arrows_array (arrows, arrows_nb, x, y, z); return arrows_nb; } @@ -820,21 +825,21 @@ static void show_user_action(GLuint *arrows, int arrows_nb, int address, int req { if (address == -1 && requested_weight > 0) { // *(arrows + i * 5 + 0) printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); - if (! TEST) printf("\n "); else printf(" "); + if (! TEST) printf("\n "); else printf(" "); printf("requested weight == %2d => CREATE", requested_weight); return;} if (address >= 0 && requested_weight == 0) { - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); if (! TEST) printf("\n "); else printf(" "); printf("requested weight == %2d => ERASE", requested_weight); return;} if (address >= 0 && current_weight != requested_weight) { - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); if (! TEST) printf("\n "); else printf(" "); printf("requested weight != current weight => MODIFY"); return;} if (address >= 0 && current_weight == requested_weight){ - printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5); + printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5); if (! TEST) printf("\n "); else printf(" "); printf("requested_weight == current_weight => END"); return;} @@ -874,7 +879,7 @@ void main_test_graphics (void) int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc // xyz, 0, x, y, z, xy, xz, yz, xyz GLuint arrows[arrows_nb * 5]; - + show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1, 0); if (arrows_nb > 0) for (int i = 0; i < arrows_nb; i ++) { arrows[i * 5 + 0] = 1 + rand() % arbitrary; // load / weight @@ -894,6 +899,9 @@ void main_test_graphics (void) if (pref_show_grids % 3 == 0) grid_write_y (space_X, space_Y, space_Z); if (pref_show_grids % 5 == 0) grid_write_z (space_X, space_Y, space_Z); if (pref_show_grids > 0) grid_write_ridges (space_X, space_Y, space_Z); + int offset_after_grids = buffer_vertex_size / 3; + int buffer_lines_size_after_cubes = buffer_lines_size; + int offset_up_to_this_cube_coords = 0, x, y, z; /* ARROWS */ /* NB The 12 vertices required to draw 6 arrows in each cube @@ -901,19 +909,17 @@ void main_test_graphics (void) /* Therefore: if (arrows_nb > 0) is not required (next line) */ arrows_write_terminations (space_X, space_Y, space_Z); - int offset_after_grids = buffer_vertex_size / 3; - int buffer_lines_size_after_cubes = buffer_lines_size; - int offset_up_to_this_cube_coords = 0, x, y, z; + for (int k = 0; k < 3; k++) // for (int k = 0; k < arbitrary; k++) TODO + arrows_nb = set_arrow (arrows, arrows_nb, + rand() % arbitrary, // load / weight + rand() % 6, // site, + MIN (rand() % space_X, space_X - 1), // x TODO + // Qu'est-ce que c'est que ce truc pas net !... + MIN (rand() % space_Y, space_Y - 1), // y + MIN (rand() % space_Z, space_Z - 1)); // z -// for (int k = 0; k < arbitrary * arbitrary; k++) - /* arrows_nb = set_arrow (arrows, arrows_nb, */ - /* rand() % arbitrary, // load / weight */ - /* rand() % 6, // site, */ - /* MIN (rand() % space_X, space_X - 1), // x */ - /* MIN (rand() % space_Y, space_Y - 1), // y */ - /* MIN (rand() % space_Z, space_Z - 1)); // z */ - - show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1); + // ligne suivante inutile: < ce sont les sous-fonctions de set_arrow() qui le font + // show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1, 1); int weight = 0, site = 0, stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;