From 98c22b4fb63f8c96e0e2be46956ba2eed44a5fb0 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 16 Oct 2023 09:48:12 +0200 Subject: [PATCH] =?UTF-8?q?Dessin=20'=C3=A9conome'=20(espace=20et=20fl?= =?UTF-8?q?=C3=A8ches)=20OK=20pour=20de=20petits=20nombres=20(avant=20nett?= =?UTF-8?q?oyage)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arrows.h | 6 ++--- include/grid.h | 4 +-- src/graphics/arrows.c | 4 +-- src/graphics/graphics.c | 54 ++++++++++++++++++----------------------- src/graphics/grid.c | 12 +++++++-- 5 files changed, 41 insertions(+), 39 deletions(-) diff --git a/include/arrows.h b/include/arrows.h index d37dfe7..a1f35ae 100644 --- a/include/arrows.h +++ b/include/arrows.h @@ -89,7 +89,7 @@ void write_arrow_lines_south_north (long s, int weight, int site); */ 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); +int 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/include/grid.h b/include/grid.h index 745bd30..bd3f45a 100644 --- a/include/grid.h +++ b/include/grid.h @@ -27,9 +27,9 @@ #include #include -void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); +int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); -void write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); +long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); /* * Writes grid lines intersections to vertex and color buffers diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index 1a89c6f..f7dda51 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -167,7 +167,7 @@ void arrows_write_basis(long offset) /******************************************************************************/ -void write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, +int write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, int space_X_int, int space_Y_int, int space_Z_int, int weight, int site, int arrow_x, int arrow_y, int arrow_z) { @@ -248,7 +248,7 @@ void write_one_arrow(int offset_vertex, int offset_colors, int offset_lines, default: break; } - /* offset_lines += 4; // inutile... */ + return 12; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 178b2b1..0ccecca 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -152,8 +152,6 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z) buffer_vertex_origin[buffer_vertex_size + 2] = z; buffer_vertex_size += 3; - - printf("new vertex : (%9.6f, %9.6f, %9.6f) <> buffer size : %3d\n", x,y,z, buffer_vertex_size); } /* @@ -599,8 +597,8 @@ static void show_user_choices(struct arrow_t *arrows, int arrows_nb, printf("\n"); - if (show_all) printf("\n\ - initial arrows data with arrows_nb = %d", arrows_nb); + if (show_all) printf("\ + initial arrows data with arrows_nb = %d\n", arrows_nb); if (show_array) show_arrows_array (arrows, arrows_nb); } @@ -875,30 +873,19 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) int rand(void); void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); - int arbitrary = 7; + int arbitrary = 10; int space_X = 1 + rand() % arbitrary, space_Y = 1 + rand() % arbitrary, space_Z = 1 + rand() % arbitrary; int density_max = space_X * space_Y * space_Z; int max = fmax(space_X, space_Y); max = fmax(max, space_Z); - - int specif_arrows_nb = 1;//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, x = 0, y = 0, z = 0;// stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0; int style = 0; - show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0, style); - - int 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; // if space edges are drawn - write_grids_on_space_faces (offset_vertex, offset_colors, offset_lines, - space_X, space_Y, space_Z, style); - - /* ARROWS */ + int specif_arrows_nb = rand() % density_max / 3; + int arrows_nb = 0; while (arrows_nb < specif_arrows_nb){ arrows_nb = set_arrow (arrows, arrows_nb, @@ -908,12 +895,21 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) rand() % space_Y, // y rand() % space_Z); // z } - show_arrows_array (arrows, arrows_nb); - offset_vertex += (space_X + space_Y + space_Z - 3) * 4; - offset_colors += (space_X + space_Y + space_Z - 3) * 4; - /* if (style) offset_lines += 2 * (space_X + space_Y + space_Z - 3); */ - /* else offset_lines += 4 * (space_X + space_Y + space_Z - 3); */ + show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1, 0, style); + if (0) show_arrows_array (arrows, arrows_nb); + + /* DATA ARE NOW ALL SPECIFIED - DRAWING CAN START */ + + int offset_vertex = 0, offset_colors = 0, offset_lines = 0; + + offset_vertex += write_space_ridges (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); + offset_colors = offset_vertex; + + offset_vertex += write_grids_on_space_faces (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, style); + offset_colors = offset_vertex; + + /* ARROWS */ for (int i = 0; i < arrows_nb; i++) { weight = arrows[i].load; @@ -922,18 +918,16 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) y = arrows[i].y; z = arrows[i].z; - write_one_arrow(offset_vertex, offset_colors, offset_lines, - space_X, space_Y, space_Z, - weight, site, x, y, z); + offset_vertex += write_one_arrow(offset_vertex, offset_colors, offset_lines, + space_X, space_Y, space_Z, + weight, site, x, y, z); + offset_colors = offset_vertex; } - show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0, style); - - free(arrows); + free(arrows); // ? free (space) arrows = NULL; arrows_nb = 0; - /* show_buffers_states(space_X, space_Y, space_Z, arrows_nb, */ /* offset_after_grids, buffer_vertex_size, */ /* buffer_lines_size_after_cubes, buffer_lines_size); */ diff --git a/src/graphics/grid.c b/src/graphics/grid.c index 58606f6..a6144f1 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -35,7 +35,7 @@ /* } */ -void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) +int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) { float max = fmax(x, y); max = fmax(max, z); graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max); @@ -66,9 +66,11 @@ void write_space_ridges (long offset_vertex, long offset_colors, long offset_lin graphics_write_line ( 1, 4); graphics_write_line ( 2, 4); graphics_write_line ( 1, 5); graphics_write_line ( 3, 5); graphics_write_line ( 2, 6); graphics_write_line ( 3, 6); + + return 8; } -void write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) +long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) { float i, max = fmax(x, y); max = fmax(max, z); @@ -148,6 +150,12 @@ void write_grids_on_space_faces (long offset_vertex, long offset_colors, long of 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); } + + return (x + y + z - 3) * 4; + /* if (style) offset_lines += 2 * (space_X + space_Y + space_Z - 3); */ + /* else offset_lines += 4 * (space_X + space_Y + space_Z - 3); */ + + }