WIP: Ça se réorganise ... doucement... is Ok

This commit is contained in:
Jean Sirmai 2023-06-30 18:29:52 +02:00
parent ecae941a11
commit d8494dc956
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 225 additions and 181 deletions

View File

@ -26,28 +26,31 @@
#include <stdbool.h> #include <stdbool.h>
#include <GL/glu.h> #include <GL/glu.h>
bool compute_space_2D(int state_size, // bool compute_space_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, // GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, // GLubyte *line_ndx,
bool pref_mark_unit_space_first, // bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last); // bool pref_mark_unit_space_last);
bool compute_arrow_2D(int state_size, // bool compute_arrow_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, // GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx, // GLubyte *line_ndx, GLubyte *plan_ndx,
int vgap, int igap, int cgap, // int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z); // int weight, int site, int x, int y, int z);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
bool compute_space_3D(int state_size, bool compute_space(int model_space_size_x,
GLfloat *vertex_base, GLfloat *color_base, GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *line_origin, GLubyte *plan_origin,
bool pref_mark_unit_space_first, GLubyte *arrows,
bool pref_mark_unit_space_last); bool pref_3D_xor_2D_space,
bool pref_lines_planes_or_mix,
bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last);
bool compute_arrow_3D(int state_size, // bool compute_arrow(int state_size,
GLfloat *vertex_base, GLfloat *color_base, // GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx, // GLubyte *line_ndx, GLubyte *plan_ndx,
int vgap, int igap, int cgap, // int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z); // int weight, int site, int x, int y, int z);

View File

@ -43,12 +43,15 @@
#include "../../include/graphics.h" #include "../../include/graphics.h"
#include "../../include/buffers.h" #include "../../include/buffers.h"
int line_ndx = 0;
#define V 1 #define V 1
#define I 0 #define I 0
#define EDGE 0.999999 #define EDGE 0.999999
bool compute_space_2D(int state_size, static bool compute_space_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *line_origin, GLubyte *plan_origin,
bool pref_lines_planes_or_mix,
bool pref_mark_unit_space_first, bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last) bool pref_mark_unit_space_last)
{ {
@ -101,35 +104,34 @@ bool compute_space_2D(int state_size,
if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size);
*(line_ndx + 0) = 0; for (int k = 0; k < state_size * 2; k++) *(line_origin + k) = k;
*(line_ndx + 1) = state_size * 2 - 2; // barre horizontale du bas line_ndx += state_size * 2;
*(line_ndx + 2) = 1; *(line_origin + line_ndx + 0) = 0;
*(line_ndx + 3) = state_size * 2 - 1; // barre horizontale du haut *(line_origin + line_ndx + 1) = state_size * 2 - 2; // barre horizontale du bas
for (int k = 0; k < state_size * 2; k++) *(line_ndx + k + 4) = k; *(line_origin + line_ndx + 2) = 1;
*(line_origin + line_ndx + 3) = state_size * 2 - 1; // barre horizontale du haut
if (I) printf("line_ndx (%d - state_size(0)) x (%d - state_size(1)) ", 0, 1); if (I) printf("line_origin (%d - state_size(0)) x (%d - state_size(1)) ", 0, 1);
for (int v = 0; v < state_size + 2; v++) for (int v = 0; v < state_size + 2; v++)
if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); if (I) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1));
int dgap = 0;
if (pref_mark_unit_space_first) { // diagonales to mark first space unit if (pref_mark_unit_space_first) { // diagonales to mark first space unit
dgap +=4; line_ndx += 4;
*(line_ndx + state_size * 2 + 6 + dgap + 0) = 0; *(line_origin + line_ndx + 0) = 0;
*(line_ndx + state_size * 2 + 6 + dgap + 1) = 3; *(line_origin + line_ndx + 1) = 3;
*(line_ndx + state_size * 2 + 6 + dgap + 2) = 1; *(line_origin + line_ndx + 2) = 1;
*(line_ndx + state_size * 2 + 6 + dgap + 3) = 2; *(line_origin + line_ndx + 3) = 2;
} }
if (pref_mark_unit_space_last) { // diagonales to mark last space unit if (pref_mark_unit_space_last) { // diagonales to mark last space unit
dgap +=4; line_ndx +=4;
*(line_ndx + state_size * 2 + 6 + dgap + 0) = (state_size - 2) * 2 + 0; *(line_origin + line_ndx + 0) = (state_size - 2) * 2 + 0;
*(line_ndx + state_size * 2 + 6 + dgap + 1) = (state_size - 2) * 2 + 3; *(line_origin + line_ndx + 1) = (state_size - 2) * 2 + 3;
*(line_ndx + state_size * 2 + 6 + dgap + 2) = (state_size - 2) * 2 + 1; *(line_origin + line_ndx + 2) = (state_size - 2) * 2 + 1;
*(line_ndx + state_size * 2 + 6 + dgap + 3) = (state_size - 2) * 2 + 2; *(line_origin + line_ndx + 3) = (state_size - 2) * 2 + 2;
} }
if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2); if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2);
@ -137,9 +139,9 @@ bool compute_space_2D(int state_size,
return 1; return 1;
} }
bool compute_arrow_2D(int state_size, static bool compute_arrow_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx, GLubyte *line_origin, GLubyte *plan_ndx,
int vgap, int igap, int cgap, int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z) int weight, int site, int x, int y, int z)
{ {
@ -162,12 +164,12 @@ bool compute_arrow_2D(int state_size,
*(vertex_base + vgap + 8) = zero; *(vertex_base + vgap + 8) = zero;
*(line_ndx + igap + 0) = vgap / 3 + 0; *(line_origin + igap + 0) = vgap / 3 + 0;
*(line_ndx + igap + 1) = vgap / 3 + 1; *(line_origin + igap + 1) = vgap / 3 + 1;
*(line_ndx + igap + 2) = vgap / 3 + 0; *(line_origin + igap + 2) = vgap / 3 + 0;
*(line_ndx + igap + 3) = vgap / 3 + 2; *(line_origin + igap + 3) = vgap / 3 + 2;
*(line_ndx + igap + 4) = vgap / 3 + 1; *(line_origin + igap + 4) = vgap / 3 + 1;
*(line_ndx + igap + 5) = vgap / 3 + 2; *(line_origin + igap + 5) = vgap / 3 + 2;
*(plan_ndx + 0) = vgap / 3 + 0; *(plan_ndx + 0) = vgap / 3 + 0;
*(plan_ndx + 1) = vgap / 3 + 1; *(plan_ndx + 1) = vgap / 3 + 1;
@ -181,9 +183,9 @@ bool compute_arrow_2D(int state_size,
} }
bool compute_space_3D(int state_size, static bool compute_space_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *line_origin,
bool pref_mark_unit_space_first, bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last) bool pref_mark_unit_space_last)
{ {
@ -268,17 +270,17 @@ bool compute_space_3D(int state_size,
if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size);
*(line_ndx + 4) = 0; *(line_origin + 4) = 0;
*(line_ndx + 5) = state_size * 4 - 4; // barre horizontale du bas arr *(line_origin + 5) = state_size * 4 - 4; // barre horizontale du bas arr
*(line_ndx + 6) = 1; *(line_origin + 6) = 1;
*(line_ndx + 7) = state_size * 4 - 3; // barre horizontale du haut arr *(line_origin + 7) = state_size * 4 - 3; // barre horizontale du haut arr
*(line_ndx + 0) = 2; *(line_origin + 0) = 2;
*(line_ndx + 1) = state_size * 4 - 2; // barre horizontale du bas av *(line_origin + 1) = state_size * 4 - 2; // barre horizontale du bas av
*(line_ndx + 2) = 3; *(line_origin + 2) = 3;
*(line_ndx + 3) = state_size * 4 - 1; // barre horizontale du haut av *(line_origin + 3) = state_size * 4 - 1; // barre horizontale du haut av
/* *(plan_ndx + 0) = 0; */ /* *(plan_ndx + 0) = 0; */
@ -293,40 +295,40 @@ bool compute_space_3D(int state_size,
for (int k = 8; k <= state_size * 8; k += 8){ // for (int k = 8; k < state_size * 8; k += 8){ for (int k = 8; k <= state_size * 8; k += 8){ // for (int k = 8; k < state_size * 8; k += 8){
*(line_ndx + k + 0) = k / 2 - 4; // + 0; *(line_origin + k + 0) = k / 2 - 4; // + 0;
*(line_ndx + k + 1) = k / 2 - 2; // + 2; *(line_origin + k + 1) = k / 2 - 2; // + 2;
*(line_ndx + k + 2) = k / 2 - 3; // + 1; *(line_origin + k + 2) = k / 2 - 3; // + 1;
*(line_ndx + k + 3) = k / 2 - 1; // + 3; *(line_origin + k + 3) = k / 2 - 1; // + 3;
*(line_ndx + k + 4) = k / 2 - 4; // + 0; *(line_origin + k + 4) = k / 2 - 4; // + 0;
*(line_ndx + k + 5) = k / 2 - 1; // + 3; *(line_origin + k + 5) = k / 2 - 1; // + 3;
*(line_ndx + k + 6) = k / 2 - 3; // + 1; *(line_origin + k + 6) = k / 2 - 3; // + 1;
*(line_ndx + k + 7) = k / 2 - 2; // + 2; *(line_origin + k + 7) = k / 2 - 2; // + 2;
} }
if (pref_mark_unit_space_first) { if (pref_mark_unit_space_first) {
*(line_ndx + (2 + state_size) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro *(line_origin + (2 + state_size) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro
*(line_ndx + (2 + state_size) * 8 - 3) = 0 + 1; *(line_origin + (2 + state_size) * 8 - 3) = 0 + 1;
*(line_ndx + (2 + state_size) * 8 - 2) = 0 + 2; // diagonales pour marquer la case zéro *(line_origin + (2 + state_size) * 8 - 2) = 0 + 2; // diagonales pour marquer la case zéro
*(line_ndx + (2 + state_size) * 8 - 1) = 0 + 3; *(line_origin + (2 + state_size) * 8 - 1) = 0 + 3;
} }
if (pref_mark_unit_space_last) { if (pref_mark_unit_space_last) {
*(line_ndx + (2 + state_size) * 8 - 8) = (state_size - 1) * 4 + 0; // diagonales pour marquer la case finale *(line_origin + (2 + state_size) * 8 - 8) = (state_size - 1) * 4 + 0; // diagonales pour marquer la case finale
*(line_ndx + (2 + state_size) * 8 - 7) = (state_size - 1) * 4 + 1; *(line_origin + (2 + state_size) * 8 - 7) = (state_size - 1) * 4 + 1;
*(line_ndx + (2 + state_size) * 8 - 6) = (state_size - 1) * 4 + 2; // diagonales pour marquer la case finale *(line_origin + (2 + state_size) * 8 - 6) = (state_size - 1) * 4 + 2; // diagonales pour marquer la case finale
*(line_ndx + (2 + state_size) * 8 - 5) = (state_size - 1) * 4 + 3; *(line_origin + (2 + state_size) * 8 - 5) = (state_size - 1) * 4 + 3;
} }
if (I) printf("line_ndx "); if (I) printf("line_origin ");
for (int v = 0; v < state_size + 2; v++) { for (int v = 0; v < state_size + 2; v++) {
if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); if (I) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1));
} }
if (I) printf("pref_mark_unit_space_first = %d ", pref_mark_unit_space_first); if (I) printf("pref_mark_unit_space_first = %d ", pref_mark_unit_space_first);
@ -336,9 +338,9 @@ if (pref_mark_unit_space_last) {
return 1; return 1;
} }
bool compute_arrow_3D(int state_size, static bool compute_arrow_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base, GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx, GLubyte *line_origin, GLubyte *plan_ndx,
int vgap, int igap, int cgap, int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z) int weight, int site, int x, int y, int z)
{ {
@ -372,29 +374,29 @@ bool compute_arrow_3D(int state_size,
if (I) printf("x = %d site = %d center = %f tip = %f base = %f\n",\ if (I) printf("x = %d site = %d center = %f tip = %f base = %f\n",\
x, site, center, tip, base); // vgap=%d igap=%d x, site, center, tip, base); // vgap=%d igap=%d
*(line_ndx + igap + 0) = vgap / 3 + 0; *(line_origin + igap + 0) = vgap / 3 + 0;
*(line_ndx + igap + 1) = vgap / 3 + 1; *(line_origin + igap + 1) = vgap / 3 + 1;
*(line_ndx + igap + 2) = vgap / 3 + 0; *(line_origin + igap + 2) = vgap / 3 + 0;
*(line_ndx + igap + 3) = vgap / 3 + 2; *(line_origin + igap + 3) = vgap / 3 + 2;
*(line_ndx + igap + 4) = vgap / 3 + 0; *(line_origin + igap + 4) = vgap / 3 + 0;
*(line_ndx + igap + 5) = vgap / 3 + 3; *(line_origin + igap + 5) = vgap / 3 + 3;
*(line_ndx + igap + 6) = vgap / 3 + 0; *(line_origin + igap + 6) = vgap / 3 + 0;
*(line_ndx + igap + 7) = vgap / 3 + 4; *(line_origin + igap + 7) = vgap / 3 + 4;
*(line_ndx + igap + 8) = vgap / 3 + 1; *(line_origin + igap + 8) = vgap / 3 + 1;
*(line_ndx + igap + 9) = vgap / 3 + 2; *(line_origin + igap + 9) = vgap / 3 + 2;
*(line_ndx + igap + 10) = vgap / 3 + 2; *(line_origin + igap + 10) = vgap / 3 + 2;
*(line_ndx + igap + 11) = vgap / 3 + 3; *(line_origin + igap + 11) = vgap / 3 + 3;
*(line_ndx + igap + 12) = vgap / 3 + 3; *(line_origin + igap + 12) = vgap / 3 + 3;
*(line_ndx + igap + 13) = vgap / 3 + 4; *(line_origin + igap + 13) = vgap / 3 + 4;
*(line_ndx + igap + 14) = vgap / 3 + 4; *(line_origin + igap + 14) = vgap / 3 + 4;
*(line_ndx + igap + 15) = vgap / 3 + 1; *(line_origin + igap + 15) = vgap / 3 + 1;
*(plan_ndx + 0) = vgap / 3 + 0; *(plan_ndx + 0) = vgap / 3 + 0;
@ -409,3 +411,48 @@ bool compute_arrow_3D(int state_size,
} }
bool compute_space(int model_space_size_x,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_origin, GLubyte *plan_origin,
GLubyte *arrows,
bool pref_3D_xor_2D_space,
bool pref_lines_planes_or_mix,
bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last)
{
printf("Prefer : mark_unit_space_first = %d mark_unit_space_last = %d 3D_xor_2D_space = %d\n",
pref_mark_unit_space_first, pref_mark_unit_space_last, pref_3D_xor_2D_space);
if (pref_3D_xor_2D_space) { // 2D
printf("buffers.compute_space() pref_3D_xor_2D_space > 2D \n");
compute_space_2D(model_space_size_x,
vertex_base, color_base,
line_origin, plan_origin,
pref_lines_planes_or_mix,
pref_mark_unit_space_first,
pref_mark_unit_space_last);
return 0;
} else { // 3D
printf("buffers.compute_space() pref_3D_xor_2D_space > 3D \n");
/* compute_arrow_3D(model_space_size_x, */
/* vertex_base, color_base, */
/* line_origin, plan_origin, */
/* vgap, igap, cgap, */
/* 1, 0, 0, 0, 0); */
/* vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 0, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 0, model_space_size_x - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, model_space_size_x - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
return 0;
}
printf("buffers.compute_space() end.\n");
return 0;
}

View File

@ -47,8 +47,9 @@
GLfloat *vertex_base = NULL; GLfloat *vertex_base = NULL;
GLfloat *color_base = NULL; GLfloat *color_base = NULL;
GLubyte *line_ndx = NULL; GLubyte *line_origin = NULL;
GLubyte *plan_ndx = NULL; GLubyte *plan_origin = NULL;
// GLubyte *arrows = NULL;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -260,8 +261,8 @@ bool graphics_shutdown(const void *gl_area)
g_free(vertex_base); g_free(vertex_base);
g_free(color_base); g_free(color_base);
g_free(line_ndx); g_free(line_origin);
g_free(plan_ndx); g_free(plan_origin);
return true; return true;
} }
@ -483,28 +484,26 @@ bool graphics_init_shaders(const void *gl_area)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// int model_dim = 0; INUTILE (fonction de model_space_size_x, y ,z) */ // int model_dim; < INUTILE : dim est fonction de model_space_size_x, y ,z) */
int model_space_size_x = 0; int model_space_size_x = 0;
int model_space_size_y = 0; int model_space_size_y = 0;
int model_space_size_z = 0; int model_space_size_z = 0;
int model_arrows_nb = 0; int model_arrows_nb = 0;
GLubyte *arrows = NULL; //{ 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 };
int buffer_vertex_size = 0;
int buffer_colors_size = 0;
int buffer_lines_size = 0;
int buffer_plans_size = 0;
/* Pourquoi mettre 'line_indices_nb' dans 'entry' ? */
/* Pourquoi ne pas y mettre la taille des autres buffers ? */
/* --- Pas cohérent ... > je déplace (30-06-2023) */
int buffer_lines_ndx = 0; // previously in graphics.h struct gl_area_entry.GLuint line_indices_nb;
int buffer_plans_ndx = 0; // previously in graphics.h struct gl_area_entry.GLuint plan_indices_nb;
bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D
bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D
bool pref_lines_planes_or_mix = 0; // default view == 0 == lines only
bool pref_mark_unit_space_first = 0; // default == 0 == no mark bool pref_mark_unit_space_first = 0; // default == 0 == no mark
bool pref_mark_unit_space_last = 0; // default == 0 == no mark bool pref_mark_unit_space_last = 0; // default == 0 == no mark
bool pref_background_color = 0; // don't know yet... bool pref_background_color = 0; // don't know yet...
int buffer_vertex_size = 0;
int buffer_colors_size = 0;
int buffer_lines_size = 0; // previously in graphics.h struct gl_area_entry.GLuint line_indices_nb;
int buffer_plans_size = 0; // previously in graphics.h struct gl_area_entry.GLuint plan_indices_nb;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// TODO Tester (presque) toutes les combinaisons possibles de ces variables !!! // TODO Tester (presque) toutes les combinaisons possibles de ces variables !!!
@ -513,11 +512,12 @@ bool pref_background_color = 0; // don't know yet...
static void get_model_data_and_user_preferences(){ static void get_model_data_and_user_preferences(){
// The model data (arrows) to use (from model.xml) // The model data (arrows) to use (from model.xml)
// { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 }; // int *arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 };
model_space_size_x = 6; // 2 < model_space_size_x < 32
model_arrows_nb = 0; // assert : leur emplacement est contraint par
// model_space_size_x, y, z et le nombre de sites
model_space_size_x = 8; // 2 < model_space_size_x < 32
model_arrows_nb = 4; // assert : leur emplacement est contraint par model_space_size_x
//
pref_3D_xor_2D_space = 1; // default == 0 == 3D pref_3D_xor_2D_space = 1; // default == 0 == 3D
pref_3D_xor_2D_arrows = 1; // default == 0 == 3D pref_3D_xor_2D_arrows = 1; // default == 0 == 3D
pref_mark_unit_space_first = 1; // default == 0 == no mark pref_mark_unit_space_first = 1; // default == 0 == no mark
@ -531,43 +531,37 @@ static void compute_buffers_sizes(int model_space_size_x,
int model_arrows_nb, int model_arrows_nb,
bool pref_3D_xor_2D_space, bool pref_3D_xor_2D_space,
bool pref_3D_xor_2D_arrows, bool pref_3D_xor_2D_arrows,
bool pref_lines_planes_or_mix,
bool pref_mark_unit_space_first, bool pref_mark_unit_space_first,
bool pref_mark_unit_space_last) bool pref_mark_unit_space_last)
{ {
int two_ladder_amounts = 4; // 2 parallels to connect 4 vertices
if (pref_3D_xor_2D_space) { // 2D the ladder has 2 amounts
buffer_vertex_size = model_space_size_x * 6 + model_arrows_nb * 9;
buffer_colors_size = model_space_size_x * 6 + model_arrows_nb * 9;
buffer_lines_size = model_space_size_x * 2 + model_arrows_nb * 6
+ two_ladder_amounts;
} else { // 3D the ladder has 4 amounts, now
buffer_vertex_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 15;
buffer_colors_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 15;
buffer_lines_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 15
+ 2 * two_ladder_amounts;
}
if (pref_3D_xor_2D_space) buffer_vertex_size = (model_space_size_x + 1) * 6 + model_arrows_nb * 9; // case 2D /* Increment in buffer_lines_size is the same for 2D & 3D */
else buffer_vertex_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 15; // case 3D if (pref_mark_unit_space_first) buffer_lines_size += 4; // 2 diagonal lines
if (pref_mark_unit_space_last) buffer_lines_size += 4; // 2 diagonal lines
if (pref_3D_xor_2D_space) buffer_colors_size = (model_space_size_x + 1) * 6 + model_arrows_nb * 9; // case 2D
else buffer_colors_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 15; // case 3D
if (pref_3D_xor_2D_space) buffer_lines_size = (2 + model_space_size_x) + (model_arrows_nb * 3); // case 2D /* if (pref_3D_xor_2D_space) for (int k = 0; k < model_space_size_x; k++) { // 2D */
else buffer_lines_size = (4 + model_space_size_x * 4) + (model_arrows_nb * 8); // case 3D /* assert(k * 6 < buffer_vertex_size); assert(k * 6 + 5 < buffer_vertex_size); */
/* assert(k * 6 < buffer_colors_size); assert(k * 6 + 5 < buffer_colors_size); */
if (pref_mark_unit_space_first) buffer_lines_size += 2; // 2 diagonal lines /* assert(k + 4 < buffer_lines_size); assert(k + 8 < buffer_lines_size); // TODO check this line ! */
if (pref_mark_unit_space_last) buffer_lines_size += 2; // 2 diagonal lines /* } else for (int k = 0; k < model_space_size_x; k++) { // 3D */
/* assert(k * 12 < buffer_vertex_size); assert(k * 12 + 11 < buffer_vertex_size); */
int vgap = 0, cgap = 0, igap = 0; /* assert(k * 12 < buffer_colors_size); assert(k * 12 + 11 < buffer_colors_size); */
/* assert(k + 8 < buffer_lines_size); assert(k + 16 < buffer_lines_size); // TODO check this line ! */
vgap += (6 * model_space_size_x); /* } */
cgap += (6 * model_space_size_x);
igap += model_space_size_x * 2;
if (pref_mark_unit_space_first) igap += 4; // 4 vertices for 2 diagonal lines
if (pref_mark_unit_space_last) igap += 4; // 4 vertices for 2 diagonal lines
if (pref_3D_xor_2D_space) for (int k = 0; k < model_space_size_x; k++) {
assert(k * 6 < buffer_vertex_size); assert(k * 6 + 5 < buffer_vertex_size);
assert(k * 6 < buffer_colors_size); assert(k * 6 + 5 < buffer_colors_size);
assert(k + 4 < buffer_lines_size); assert(k + 8 < buffer_lines_size); // TODO check this line !
} else for (int k = 0; k < model_space_size_x; k++) {
assert(k * 12 < buffer_vertex_size); assert(k * 12 + 11 < buffer_vertex_size);
assert(k * 12 < buffer_colors_size); assert(k * 12 + 11 < buffer_colors_size);
assert(k + 8 < buffer_lines_size); assert(k + 16 < buffer_lines_size); // TODO check this line !
}
assert(vgap < buffer_vertex_size); assert(vgap + 9 < buffer_vertex_size);
assert(igap < buffer_lines_size); //assert(igap + 5 < buffer_lines_size);
/* 1 flèche 3D > vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */ /* 1 flèche 3D > vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
@ -576,23 +570,37 @@ static void compute_buffers_sizes(int model_space_size_x,
buffer_plans_size = 8; // (4 + model_space_size_x * 4) + (model_arrows_nb * 8) + 2; buffer_plans_size = 8; // (4 + model_space_size_x * 4) + (model_arrows_nb * 8) + 2;
buffer_lines_ndx = buffer_lines_size * 2; /* buffer_lines_ndx = buffer_lines_size * 2; */
buffer_plans_ndx = buffer_plans_size * 3; /* buffer_plans_ndx = buffer_plans_size * 3; */
buffer_colors_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 0; // TODO buffer_colors_size = (model_space_size_x + 1) * 12 + model_arrows_nb * 0; // TODO
assert(model_space_size_x * 6 < buffer_vertex_size); assert(model_space_size_x * 6 + 5 < buffer_vertex_size); // assert(model_space_size_x * 6 < buffer_vertex_size); assert(model_space_size_x * 6 + 5 < buffer_vertex_size);
printf("Prefer : mark_unit_space_first = %d mark_unit_space_last = %d 3D_xor_2D_space = %d\n", printf("Initialization of buffers with %u vertices, %u colors, %u lines, %u plans. model_space_size_x = %d\n",
pref_mark_unit_space_first, pref_mark_unit_space_last, pref_3D_xor_2D_space); buffer_vertex_size, buffer_colors_size, buffer_lines_size, buffer_plans_size, model_space_size_x);
printf("Initialization of buffers with %u line_ndx, %u vertices, %u colors. model_space_size_x = %d\n",
buffer_lines_ndx, buffer_vertex_size, buffer_colors_size, model_space_size_x);
} }
//--------------- SCORIES ------------------------------------------------
/* int vgap = 0, cgap = 0, igap = 0; */
/* vgap += (6 * model_space_size_x); */
/* cgap += (6 * model_space_size_x); */
/* igap += model_space_size_x * 2; */
/* if (pref_mark_unit_space_first) igap += 4; // 4 vertices for 2 diagonal lines */
/* if (pref_mark_unit_space_last) igap += 4; // 4 vertices for 2 diagonal lines */
/* assert(vgap < buffer_vertex_size); assert(vgap + 9 < buffer_vertex_size); */
/* assert(igap < buffer_lines_size); */
/* Initializes the buffer of a gl_area /* Initializes the buffer of a gl_area
* Calls according to the user preferences * Calls according to the user preferences
* @param gl_area, ptr to the gl_area widget * @param gl_area, ptr to the gl_area widget
* Note : line_ndx[] is no more defined in graphics_cube.h * Note : line_origin[] is no more defined in graphics_cube.h
* @return void * @return void
*/ */
#define A 0 #define A 0
@ -603,45 +611,31 @@ void graphics_init_buffers(const void *gl_area)
get_model_data_and_user_preferences(); get_model_data_and_user_preferences();
/* une struct en retour pour ne plus utiliser de variables globales ? (facile) */ /* une struct en retour pour ne plus utiliser de variables globales ? (facile) */
compute_buffers_sizes(model_space_size_x, compute_buffers_sizes(model_space_size_x,
model_space_size_y, model_space_size_y,
model_space_size_z, model_space_size_z,
model_arrows_nb, model_arrows_nb,
pref_3D_xor_2D_space, pref_3D_xor_2D_space,
pref_3D_xor_2D_arrows, pref_3D_xor_2D_arrows,
pref_lines_planes_or_mix,
pref_mark_unit_space_first, pref_mark_unit_space_first,
pref_mark_unit_space_last); pref_mark_unit_space_last);
// g_malloc // g_malloc
vertex_base = g_malloc0(buffer_vertex_size * sizeof(GLfloat) * 2); vertex_base = g_malloc0(buffer_vertex_size * sizeof(GLfloat) * 2);
color_base = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2); color_base = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2);
line_ndx = g_malloc0(buffer_lines_size * 2 * sizeof(GLubyte) * 2); line_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLubyte) * 2);
plan_ndx = g_malloc0(buffer_plans_size * 3 * sizeof(GLubyte) * 2); plan_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLubyte) * 2);
if (pref_3D_xor_2D_space) compute_space_2D(model_space_size_x, compute_space (model_space_size_x,
vertex_base, color_base, vertex_base, color_base,
line_ndx, line_origin, plan_origin,
pref_mark_unit_space_first, arrows,
pref_mark_unit_space_last); pref_3D_xor_2D_space,
pref_lines_planes_or_mix,
else compute_space_3D(model_space_size_x, pref_mark_unit_space_first,
vertex_base, color_base, pref_mark_unit_space_last);
line_ndx,
pref_mark_unit_space_first,
pref_mark_unit_space_last);
/* compute_arrow_3D(model_space_size_x, */
/* vertex_base, color_base, */
/* line_ndx, plan_ndx, */
/* vgap, igap, cgap, */
/* 1, 0, 0, 0, 0); */
/* vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 0, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 0, model_space_size_x - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
/* compute_arrow_3D(entry, model_space_size_x, vgap, igap, 1, 1, model_space_size_x - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++model_arrows_nb; */
GLuint vao, vertex_buffer, color_buffer; GLuint vao, vertex_buffer, color_buffer;
@ -724,8 +718,8 @@ void graphics_draw(const void *gl_area)
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDrawElements(GL_LINES, buffer_lines_ndx, GL_UNSIGNED_BYTE, line_ndx); glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_BYTE, line_origin);
glDrawElements(GL_TRIANGLES, buffer_plans_ndx, GL_UNSIGNED_BYTE, plan_ndx); glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_BYTE, plan_origin);
/* We finished using the buffers and program */ /* We finished using the buffers and program */
glDisableVertexAttribArray(0); glDisableVertexAttribArray(0);