From d1ff06f2178c6233e9e17df18f71cf3d9bfbeef7 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 12 Oct 2023 20:43:34 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20essai=20grilles=20entrecrois=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arrows.h | 6 ++- src/graphics/arrows.c | 76 +++++++++++++++++++++++++++++ src/graphics/graphics.c | 103 +++++++++++++++++++--------------------- src/graphics/grid.c | 38 ++++++++------- 4 files changed, 149 insertions(+), 74 deletions(-) diff --git a/include/arrows.h b/include/arrows.h index 57e2b17..d37dfe7 100644 --- a/include/arrows.h +++ b/include/arrows.h @@ -87,5 +87,9 @@ void write_arrow_lines_south_north (long s, int weight, int site); * * @return void */ -void arrows_write_basis(long n); +void arrows_write_basis (long n); + +void write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, + int space_X, int space_Y, int space_Z, + int weight, int site, int x, int y, int z); diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index 8a5b302..48fac9c 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -164,3 +164,79 @@ void arrows_write_basis(long offset) graphics_write_line (offset + 4, offset + 5); } +/******************************************************************************/ + +void write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, + int space_X, int space_Y, int space_Z, + int weight, int site, int x, int y, int z) +{ + float nuance = 0.24f, + max = fmax(space_X, space_Y), + + // arrow_basis_width donne la dimension de l'étoile centrale + arrow_basis_width = 0.3f * (1 / max), + + // décale légèrement les pointes des flèches + // pour qu'elles n'aillent pas jusqu'aux faces des cubes + arrow_tip_padding = 0.1 * (1 / max), + + vx = (2 * x / space_X - 1) * space_X / max + (1 / max), + vy = (2 * y / space_Y - 1) * space_Y / max + (1 / max), + vz = (2 * z / space_Z - 1) * space_Z / max + (1 / max); + + max = fmax(max, space_Z); + + // X - X axis - central star (basis) + graphics_write_vertex(vx + arrow_basis_width, vy, vz); + graphics_write_vertex(vx - arrow_basis_width, vy, vz); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // Y - Y axis - central star (basis) + graphics_write_vertex(vx, vy + arrow_basis_width, vz); + graphics_write_vertex(vx, vy - arrow_basis_width, vz); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // Z - Z axis - central star (basis) + graphics_write_vertex(vx, vy, vz + arrow_basis_width); + graphics_write_vertex(vx, vy, vz - arrow_basis_width); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // X - X (EAST - WEST) axis - arrows tips (red - green) + 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 - nuance / 3, 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 (cyan - magenta) + 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 + nuance, 1.0f - nuance / 3, 0.0f + nuance); + graphics_write_color(1.0f - nuance, 0.0f + nuance, 1.0f - nuance); + + // Z - Z (NORTH - SOUTH) axis - arrows tips (blue - yellow) + 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 + nuance, 0.0f + nuance, 1.0f - nuance / 4); + graphics_write_color(1.0f - nuance / 3, 1.0f - nuance / 3, 0.0f + nuance); + + + + graphics_write_line (offset_vertex + 0, offset_vertex + 1); + graphics_write_line (offset_vertex + 2, offset_vertex + 3); + graphics_write_line (offset_vertex + 4, offset_vertex + 5); + + + + switch(site){ + case EAST: case WEST: write_arrow_lines_east_west (offset_vertex, weight, site); break; + case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (offset_vertex, weight, site); break; + case SOUTH: case NORTH: write_arrow_lines_south_north (offset_vertex, weight, site); break; + default: break; + } + +} + + diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 5eb88c2..2a437ff 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -569,13 +569,14 @@ bool graphics_shutdown(const void *gl_area) * - weight (or load) * - coordinates in space (site, x, y, z) */ -static void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z) +static void show_arrows_array (struct arrow_t *arrows, int arrows_nb) { - printf("\n [rank] load | site x y z"); + printf(" [rank] load | site x y z"); for (int i = 0; i < arrows_nb; i++) - printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, *(arrows + i * 5 + 0),\ - *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); + printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\ + arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z); if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---"); + printf("\n"); } /* @@ -587,18 +588,20 @@ static void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int */ static void show_user_choices(struct arrow_t *arrows, int arrows_nb, int space_size_x, int space_size_y, int space_size_z, - int prefer, int show_all, int show_array) + int prefer, int show_all, int show_array, int style) { 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 (show_all && prefer == 0) printf("prefer = %d <> show all grids", prefer); if (show_all && prefer == 1) printf("prefer = %d <> show no grid", prefer); if (show_all && prefer > 1) printf("show grids according rule (%d)", prefer); + if (style) printf("design... 'trop stylé' !"); + printf("\n"); if (show_all) printf("\n\ initial arrows data with arrows_nb = %d", arrows_nb); - if (show_array) show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z); + if (show_array) show_arrows_array (arrows, arrows_nb); } /* @@ -668,7 +671,7 @@ static int rewrite_arrow (int arrows_nb, int address, int weight, int site, int arrows[address].load = weight; // if (! TEST) - // show_arrows_array (arrows, arrows_nb, x, y, z); + // show_arrows_array (arrows, arrows_nb); return arrows_nb; } @@ -695,7 +698,7 @@ static inline int create_arrow (int arrows_nb, int weight, int site, int x, int arrows_nb ++; // if (! TEST) - // show_arrows_array (arrows, arrows_nb, x, y, z); + // show_arrows_array (arrows, arrows_nb); return arrows_nb; } @@ -724,7 +727,7 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int perror("Can't allocate new arrow buffer!\n"); // if (! TEST) - // show_arrows_array (arrows, arrows_nb, x, y, z); + // show_arrows_array (arrows, arrows_nb); return arrows_nb; } @@ -877,66 +880,56 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) space_Y = 1 + rand() % arbitrary, space_Z = 1 + rand() % arbitrary; int density_max = space_X * space_Y * space_Z; - int arrows_nb = 0;//rand() % density_max; + int max = fmax(space_X, space_Y); max = fmax(max, space_Z); + + int specif_arrows_nb = 3;//rand() % density_max; + int arrows_nb = 0; int pref_show_grids = 1; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc // xyz, 0, x, y, z, xy, xz, yz, xyz - int weight = 0, site = 0, - stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0; - 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; + int weight = 0, site = 0, x = 0, y = 0, z = 0;// stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0; + int style = 1; - show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0); + show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0, style); - long offset_vertex = 0, offset_colors = 0, offset_lines = 0; + long offset_vertex = 0, offset_colors = 0, offset_lines = 0; // if this function is called first write_space_ridges (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); - offset_vertex = 8, offset_colors = 8, offset_lines = 12; - write_space_faces_grids (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, 0); + offset_vertex = 8, offset_colors = 8, offset_lines = 12; // if space edges are drawn + write_space_faces_grids (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, style); /* ARROWS */ - /* NB The 12 vertices required to draw 6 arrows in each cube - * are always defined (whether arrows are drawn or not). */ - /* Therefore: if (arrows_nb > 0) is not required (next line) */ - /* arrows_write_terminations (space_X, space_Y, space_Z); */ - /* volatile int remaining = arbitrary; */ - /* while (remaining) { */ - /* for (int l = 0; l < 10; l++) { */ - /* arrows_nb = set_arrow (arrows, arrows_nb, */ - /* rand() % arbitrary, // load / weight */ - /* rand() % 6, // site, */ - /* rand() % space_X, // x */ - /* rand() % space_Y, // y */ - /* rand() % space_Z); // z */ - /* } */ - /* remaining -= 10; */ + while (arrows_nb < specif_arrows_nb){ + arrows_nb = set_arrow (arrows, arrows_nb, + rand() % arbitrary, // load / weight + rand() % 6, // site, + rand() % space_X, // x + rand() % space_Y, // y + rand() % space_Z); // z + } + show_arrows_array (arrows, arrows_nb); - /* for (int i = 0; i < arrows_nb; i++) { */ - /* weight = arrows[i].load; */ - /* site = arrows[i].site; */ - /* x = arrows[i].x; */ - /* y = arrows[i].y; */ - /* z = arrows[i].z; */ + offset_vertex += 8 + (space_X + space_Y + space_Z - 6) * 4; + offset_colors += 8 + (space_X + space_Y + space_Z - 6) * 4; - /* offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z); */ - /* arrow_offset = offset_after_grids + offset_up_to_this_cube_coords; */ + if (style) offset_lines += space_X + space_Y + space_Z; - /* arrows_write_basis (arrow_offset); */ + for (int i = 0; i < arrows_nb; i++) { + weight = arrows[i].load; + site = arrows[i].site; + x = arrows[i].x; + y = arrows[i].y; + z = arrows[i].z; - /* switch(site){ */ - /* case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, weight, site); break; */ - /* case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (arrow_offset, weight, site); break; */ - /* case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, weight, site); break; */ - /* default: break; */ - /* } */ - /* } */ + void write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, + int space_X, int space_Y, int space_Z, + int weight, int site, int x, int y, int z); + } + + free(arrows); + arrows = NULL; + arrows_nb = 0; - /* free(arrows); */ - /* arrows = NULL; */ - /* arrows_nb = 0; */ - /* if (TEST) printf("\nCreated %d arrows", arbitrary - remaining); */ - /* } */ /* show_buffers_states(space_X, space_Y, space_Z, arrows_nb, */ /* offset_after_grids, buffer_vertex_size, */ diff --git a/src/graphics/grid.c b/src/graphics/grid.c index df13943..ab181dc 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -29,17 +29,17 @@ void write_space_ridges (long offset_vertex, long offset_colors, long offset_lin { float max = fmax(x, y); max = fmax(max, z); - graphics_write_vertex (- x / max, - y / max, - z / max); + graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max); - graphics_write_vertex (+ x / max, - y / max, - z / max); - graphics_write_vertex (- x / max, + y / max, - z / max); - graphics_write_vertex (- x / max, - y / max, + z / max); + graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, - z / max); + graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, - z / max); + graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, + z / max); - graphics_write_vertex (+ x / max, + y / max, - z / max); - graphics_write_vertex (+ x / max, - y / max, + z / max); - graphics_write_vertex (- x / max, + y / max, + z / max); + graphics_write_vertex (offset_vertex + x / max, offset_vertex + y / max, - z / max); + graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, + z / max); + graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, + z / max); - graphics_write_vertex (+ x / max, + y / max, + z / max); + graphics_write_vertex (offset_vertex + x / max, + y / max, + z / max); graphics_write_color (0.9f, 0.2f, 0.1f); graphics_write_color (0.9f, 0.2f, 0.1f); @@ -63,7 +63,7 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse { float i, max = fmax(x, y); max = fmax(max, z); - if (style) for (i = 1; i < x; i++) { + if (style != 1) for (i = 1; i < x; i++) { // (x - 2) * 4 graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, z / max); @@ -76,7 +76,7 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse graphics_write_color (0.5f, 0.5f, 0.5f); } - if (style) for (i = 0; i < x; i ++) { + if (style != 1) for (i = 0; i < x; i ++) { graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); @@ -84,10 +84,11 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); } - if (style) offset_vertex += (x - 1) * 4; - if (style) offset_colors += (x - 1) * 4; + if (style != 1) offset_vertex += (x - 1) * 4; + if (style != 1) offset_colors += (x - 1) * 4; + if (style != 1) offset_lines += 0; else offset_lines += (x - 1) * 4; - for (i = 1; i < y; i++) { + for (i = 1; i < y; i++) { // (y - 2) * 4 graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, - z / max); graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, z / max); @@ -102,7 +103,7 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse for (i = 0; i < y - 1; i ++) { - if (style) + if (style != 1) graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); @@ -111,8 +112,9 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse offset_vertex += (y - 1) * 4; offset_colors += (y - 1) * 4; + if (style != 1) offset_lines += (x - 1) * 3; else offset_lines += (x - 1) * 4; - for (i = 1; i < z; i++) { + for (i = 1; i < z; i++) { // (z - 2) * 4 graphics_write_vertex (- x / max, - y / max, (2 * i / z - 1) * z / max); graphics_write_vertex (- x / max, y / max, (2 * i / z - 1) * z / max); @@ -129,7 +131,7 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); - if (style) + if (! style) graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); } @@ -190,8 +192,8 @@ void grid_write_intersections (long x, long y, long z) */ void grid_write_marks (long x, long y, long z) { - long step_x = (z + 1) * (y + 1), step_y = z + 1, step_z = 1; - int delta = 1.0f; + long step_z = 1; // step_x = (z + 1) * (y + 1), step_y = z + 1; + //int delta = 1.0f; for (int i=1; i < z; i ++) { // graphics_write_vertex (delta, delta, i); graphics_write_vertex (delta, - delta, i); // graphics_write_color (0.3f,0.3f,0.3f); graphics_write_color (0.3f,0.3f,0.3f);