From a6927dbaa59da07fd892620d3f2fb1b9df1f0307 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 23 Jun 2023 16:55:58 +0200 Subject: [PATCH] WIP: pref_3D_xor_2D_space and pref_mark_unit_space_zero seem OK (check) --- include/space_2D.h | 4 ++- include/space_3D.h | 3 +- src/graphics/graphics_compute.c | 19 +++++------- src/graphics/graphics_control.c | 55 ++++++++------------------------- src/graphics/space_2D.c | 11 ++++++- src/graphics/space_3D.c | 23 ++++++++------ 6 files changed, 50 insertions(+), 65 deletions(-) diff --git a/include/space_2D.h b/include/space_2D.h index f6ae70c..917a844 100644 --- a/include/space_2D.h +++ b/include/space_2D.h @@ -27,4 +27,6 @@ #include bool compute_space_2D(int state_size, - GLfloat *vertex_base, GLubyte *line_ndx); + GLfloat *vertex_base, GLfloat *color_base, + GLubyte *line_ndx, + bool pref_mark_unit_space_zero, int dgap); diff --git a/include/space_3D.h b/include/space_3D.h index 5be5ab6..db14f3c 100644 --- a/include/space_3D.h +++ b/include/space_3D.h @@ -28,4 +28,5 @@ bool compute_space_3D(int state_size, GLfloat *vertex_base, GLfloat *color_base, - GLubyte *line_ndx, int ad_hoc_diag); + GLubyte *line_ndx, + bool pref_mark_unit_space_zero, int dgap); diff --git a/src/graphics/graphics_compute.c b/src/graphics/graphics_compute.c index b7221a4..de83d3c 100644 --- a/src/graphics/graphics_compute.c +++ b/src/graphics/graphics_compute.c @@ -46,14 +46,6 @@ #include "../../include/arrow_2D.h" #include "../../include/arrow_3D.h" -/* int dim = 0; */ -/* int state_size = 0; */ -/* int vertex_nb = 0; */ -/* int colors_nb = 0; */ -/* int lines_nb = 0; */ -/* int plans_nb = 0; */ -/* int arrows_nb = 0; */ - #define A 0 int graphics_compute_lines(int line_indices_nb, GLfloat *vertex_base, GLfloat *color_base, @@ -104,10 +96,12 @@ int graphics_compute_lines(int line_indices_nb, for (int k = 0; k < state_size; k++){ assert(k * 12 < vertex_nb); assert(k * 12 + 11 < vertex_nb); assert(k * 12 < colors_nb); assert(k * 12 + 11 < colors_nb); - assert(k + 8 < line_indices_nb); assert(k + 16 < line_indices_nb); + assert(k + 8 < line_indices_nb); assert(k + 16 < line_indices_nb); } - compute_space_3D(state_size, vertex_base, color_base, line_ndx, line_indices_nb); + compute_space_3D(state_size, vertex_base, color_base, line_ndx, + 0,4); // patch provisoire + // pref_mark_unit_space_zero, dgap){ vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); /* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ @@ -261,7 +255,10 @@ int graphics_compute_plans(int plan_indices_nb, assert(k * 12 < colors_nb); assert(k * 12 + 11 < colors_nb); // assert(k + 8 < line_indices_nb); assert(k + 16 < line_indices_nb); - compute_space_3D(state_size, vertex_base, color_base, plan_ndx, plan_indices_nb); + compute_space_3D(state_size, vertex_base, color_base, plan_ndx, + 0,4); // patch provisoire + //pref_mark_unit_space_zero, dgap){ + vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); /* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ diff --git a/src/graphics/graphics_control.c b/src/graphics/graphics_control.c index 522781b..57c4e35 100644 --- a/src/graphics/graphics_control.c +++ b/src/graphics/graphics_control.c @@ -550,7 +550,7 @@ int plans_nb = 0; int arrows_nb = 0; bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D -bool pref_mark_unit_space_zero = 0; // default == no mark +bool pref_mark_unit_space_zero = 0; // default == 0 == no mark /* -------------------------------------------------------------------------- */ @@ -562,9 +562,9 @@ static void get_model_data_and_user_preferences(){ state_size = 8; // 2 < state_size < 32 arrows_nb = 4; // assert : leur emplacement doit être fonction de state_size - pref_3D_xor_2D_space = 1; // default view == 0 == 3D + pref_3D_xor_2D_space = 0; // default view == 0 == 3D pref_3D_xor_2D_arrows = 1; // default view == 0 == 3D - pref_mark_unit_space_zero = 1; // default == 0 == no mark + pref_mark_unit_space_zero = 0; // default == 0 == no mark } static void compute_vertex_colors_lines_plans_nb(int dim, @@ -579,7 +579,8 @@ static void compute_vertex_colors_lines_plans_nb(int dim, colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO - printf("Prefer : mark_unit_space_zero = %d ", pref_mark_unit_space_zero); + printf("Prefer : mark_unit_space_zero = %d pref_3D_xor_2D_space = %d state_size = %d\n", + pref_mark_unit_space_zero, pref_3D_xor_2D_space, state_size); if (pref_3D_xor_2D_space) lines_nb = (2 + state_size) + (arrows_nb * 3); // case 2D else lines_nb = (4 + state_size * 4) + (arrows_nb * 8); // case 3D @@ -623,57 +624,27 @@ void graphics_init_buffers(const void *gl_area) plan_ndx = g_malloc0(plans_nb * 3 * sizeof(GLubyte) * 2); - compute_space_2D(state_size, vertex_base, line_ndx); - int vgap = 0, igap = 0, cgap = 0, dgap = 0; if (pref_mark_unit_space_zero) dgap = 4; // 4 vertices for 2 diagonal lines - // vgap += (6 * state_size); igap += state_size * 2 + dgap; cgap += (6 * state_size); - if (pref_mark_unit_space_zero) { // diagonales pour marquer la case zéro - *(line_ndx + state_size * 2 + 6 + dgap + 0) = 0; - *(line_ndx + state_size * 2 + 6 + dgap + 1) = 3; - *(line_ndx + state_size * 2 + 6 + dgap + 2) = 1; - *(line_ndx + state_size * 2 + 6 + dgap + 3) = 2; - } + if (pref_3D_xor_2D_space) compute_space_2D(state_size, + vertex_base, color_base, + line_ndx, + pref_mark_unit_space_zero, dgap); + else compute_space_3D(state_size, + vertex_base, color_base, + line_ndx, + pref_mark_unit_space_zero, dgap); for (int k = 0; k < state_size; k++){ assert(k * 12 < vertex_nb); assert(k * 12 + 11 < vertex_nb); assert(k * 12 < colors_nb); assert(k * 12 + 11 < colors_nb); assert(k + 8 < entry->line_indices_nb); assert(k + 16 < entry->line_indices_nb); } -// compute_space_3D(state_size, vertex_base, color_base, line_ndx, entry->line_indices_nb); -// vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); - -/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ -/* assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); */ -/* compute_arrow_2D(state_size, vertex_base, color_base, */ -/* line_ndx, plan_ndx, vgap, igap, cgap, 1, 0, 0, 0, 0); */ -/* // if (A) printf("compute_arrow_2D vgap = %d vertex_nb = %d\n", vgap, vertex_nb); */ -/* // if (A) printf("x = %d site = %d center = %f tip = %f base = %f\n",\ */ -/* // x, site, center, tip, base); // vgap=%d igap=%d */ -/* vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ - -/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ -/* assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); */ -/* compute_arrow_2D(state_size, vertex_base, color_base, */ -/* line_ndx, plan_ndx, vgap, igap, cgap, 1, 1, 2, 0, 0); */ -/* vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ - -/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ -/* assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); */ -/* compute_arrow_2D(state_size, vertex_base, color_base, */ -/* line_ndx, plan_ndx, vgap, igap, cgap, 1, 0, 3, 0, 0); */ -/* vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ - -/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */ -/* assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); */ -/* compute_arrow_2D(state_size, vertex_base, color_base, */ -/* line_ndx, plan_ndx, vgap, igap, cgap, 1, 1, state_size - 2, 0, 0); */ -/* vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); diff --git a/src/graphics/space_2D.c b/src/graphics/space_2D.c index ef324d5..0f905a1 100644 --- a/src/graphics/space_2D.c +++ b/src/graphics/space_2D.c @@ -28,7 +28,9 @@ #define I 0 #define EDGE 0.999999 bool compute_space_2D(int state_size, - GLfloat *vertex_base, GLubyte *line_ndx){ + GLfloat *vertex_base, GLfloat *color_base, + GLubyte *line_ndx, + bool pref_mark_unit_space_zero, int dgap){ float x = 0; // for (int k = 0; k < state_size + 1; k++) <=> + 1 @@ -67,6 +69,13 @@ bool compute_space_2D(int state_size, if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); } + if (pref_mark_unit_space_zero) { // diagonales pour marquer la case zéro + *(line_ndx + state_size * 2 + 6 + dgap + 0) = 0; + *(line_ndx + state_size * 2 + 6 + dgap + 1) = 3; + *(line_ndx + state_size * 2 + 6 + dgap + 2) = 1; + *(line_ndx + state_size * 2 + 6 + dgap + 3) = 2; + } + if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2); return 1; diff --git a/src/graphics/space_3D.c b/src/graphics/space_3D.c index 0d6b40f..bfd3c0a 100644 --- a/src/graphics/space_3D.c +++ b/src/graphics/space_3D.c @@ -25,12 +25,13 @@ #include #define V 1 -#define I 0 +#define I 1 #define EDGE 0.999999 bool compute_space_3D(int state_size, GLfloat *vertex_base, GLfloat *color_base, - GLubyte *line_ndx, int ad_hoc_diag){ + GLubyte *line_ndx, + bool pref_mark_unit_space_zero, int dgap){ float x = 0; // for (int k = 0; k < state_size + 1; k++) <=> + 1 car @@ -128,22 +129,26 @@ bool compute_space_3D(int state_size, *(line_ndx + k + 7) = k / 2 - 2; // + 2; } +if (pref_mark_unit_space_zero) { - *(line_ndx + ad_hoc_diag - 4) = 0 + 0; // diagonales pour marquer la case zéro - *(line_ndx + ad_hoc_diag - 3) = 0 + 1; + *(line_ndx + (2 + state_size) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro + *(line_ndx + (2 + state_size) * 8 - 3) = 0 + 1; - *(line_ndx + ad_hoc_diag - 2) = 0 + 2; // diagonales pour marquer la case zéro - *(line_ndx + ad_hoc_diag - 1) = 0 + 3; + *(line_ndx + (2 + state_size) * 8 - 2) = 0 + 2; // diagonales pour marquer la case zéro + *(line_ndx + (2 + state_size) * 8 - 1) = 0 + 3; +} - - if (I) printf("line_ndx (%d - state_size(0)) x (%d - state_size(1)) ", 0, 1); + if (I) printf("line_ndx "); for (int v = 0; v < state_size + 2; v++) { if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); } - if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2); + if (I) printf(" n = 4 + (%d x 2) dgap = %d\n", state_size + 2, dgap); + if (I) printf("pref_mark_unit_space_zero = %d ", pref_mark_unit_space_zero); + return 1; } +