From bdad3857a9ede7f96dac430505c4f3c5da39744f Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 5 Jul 2023 16:37:30 +0200 Subject: [PATCH] First 3D representation Space units are 3D, arrows are 3D, space can be 3D/2D/1D. Every dimension length can be defined independently. At this time, arrows are drawn after a statically-defined array. Signed-off-by: Jean Sirmai --- TODO (next version).txt | 46 ++ include/buffers.h | 23 +- src/graphics/buffers.c | 1060 +++++++++++++-------------- src/graphics/copie_de_buffer.c.temp | 362 --------- src/graphics/graphics.c | 235 +++--- src/graphics/scories.c.forget | 394 ++++++++++ src/shaders/shader.vert | 7 +- 7 files changed, 1109 insertions(+), 1018 deletions(-) create mode 100644 TODO (next version).txt delete mode 100644 src/graphics/copie_de_buffer.c.temp create mode 100644 src/graphics/scories.c.forget diff --git a/TODO (next version).txt b/TODO (next version).txt new file mode 100644 index 0000000..f41aeae --- /dev/null +++ b/TODO (next version).txt @@ -0,0 +1,46 @@ +L'utilisation d'OpenGL fait que la première version de Gem-graph sera tout naturellement en 3D. Le modèle de marche aléatoire de dimères sera aussi facile à y réaliser que dans un modèle 1D (on pourrait même se servir d'une seule règle au lieu de deux !) (mais deux règles permettront un meilleur rendu). + +Modifier la forme des flèches ? +Pour cette première version, la forme "central star" + "cône" a l'avantage de la simplicité. +La "central star" de chaque cube est commune aux six flèches possibles qui sont orientées chacune vers une face différente. +Dans la version actuelle, elle est redessinée si plusieurs flèches sont dans le même cube. +Ce dessin est peu coûteux (deux lignes superposées pour chaque nouvelle flèche) +et ce cas (plusieurs flèches dans le même cube) sera peu fréquent dans les premiers modèles développés. Mais... TODO + +Le plus simple serait un trait allant du centre d'un cube au centre d'une de ses faces. Ce serait peu lisible pour des objets mais pourrait avoir un intérêt pour les tags (balises) éventuellement associés aux objets ou situations. Ces tags seraient machine-readable. Nécessairement. Seraient-ils human-readable aussi ? Ce serait idéal ! A inventer ou essayer, en tout cas. +Un seul trait aurait sûrement un intérêt dans la représentation de voisinages de Moore 3D (Je préfère ne pas imaginer ça pour l'instant ! Il va falloir choisir de ne représenter ou de ne visualiser qu'une partie des connexions à la fois...). + +Le premier objectif des versions à venir est l'extension du voisinage. Un voisinage type von Neumann 3D - le plus simple possible si on le veut symétrique par rapport aux axes de l'espace - est tout à fait indiqué pour cette première version. Mais les versions à venir devraient travailler en priorité avec des voisinages type Moore 3D approximativement spériques de rayon proche de celui de l'espace local. +Par ailleurs, Gem-graph ne peut avoir sa puissance théorique maximale que s'il peut utiliser un voisinage étendu à tout l'espace. Mais cette puissance est vraisemblablement inutile, sauf pour les démonstrations mathématiques d'équivalence avec les automates cellulaires, par exemple, ou d'autres formalismes. +Par ailleurs, il est d'ores et déjà possible d'utiliser pleinement le "poids" (weight) ou la "charge" (load) des flèches. + +! WARNING ! J'ai inversé pôle Nord et pôle Sud. Et c'est à corriger, je pense. 👀️ +Ce sera une convention, bien sûr. Mais comment la choisir ? J'ai imaginé superposer repère orthonormé et repère géodésique. +Si je regarde un repère orthonormé 3D: +les +x sont à ma droite, les -x à ma gauche (Est - Ouest) +les +y en haut, les -y en bas (Zénith - Nadir) et... si l'axe des z vient vers moi, +les +z sont derrière moi et les -z devant. Donc les -z sont au Nord (que je regarde) et les +z sont au Sud. + +Les vertex situés aux intersections des "grilles" (X-X, Y-Y et Z-Z) sont-ils utiles ? +Ils le seraient si ses cubes individuels étaient coloriés ou soulignés pour mettre en valeur des flèches qu'ils contiennent ou d'autres particularités. +Mais tant qu'il n'est pas possible de rendre sélectivement transparentes les parois de cubes individuels (ou de tel ou tel objet dessiné par les flèches), cette fonction est inutilisable et les vertex situés aux intersections des grilles sont donc inutiles. +On pourrait ne garder que ceux situés sur les faces de l'espace qui, eux, servent à tracer les grilles X-X, Y-Y et Z-Z. +Le nombre de vertex de l'espace serait alors de 12 par cube-unité (soit 12 * x * y * z) plus les vertex intersections des seules faces de l'espace (soit (x * y + x * z + y * z) * 2). +A raison, bien sûr de trois nombres par vertex plus les couleurs. + +Je comprends (maintenant seulement !) que si des régions du buffer lignes (idem pour le buffer triangles) sont laissées vides (occupées par des zéros) elles seront néanmoins redessinées en permanence et que le seul moyen d'éviter cela est de réallouer la taille du buffer à chaque délétion ou chaque ajout de flèche. + +Néanmoins, lorsque le nombre de flèches présent dans l'espace est invariant, - cas de mes premiers modèles - il peut être avantageux de travailler dans un buffer de taille fixe. Il faut, pour cela, fixer une "densité maximale de flèches dans l'espace" nécessairement arbitraire. +Bien que ce nombre reste toujours arbitraire, on peut estimer que certaines de ses valeurs seront plus utiles/utilisables que d'autres : +- un espace totalement vide ou totalement saturé ne pourrait rien représenter +- un espace trop vide ou trop plein (à définir - c'est intuitif) aurait peu de chances de représenter des phénomènes intéressants. La marche aléatoire d'un seul ou de quelques dimères dans un grand espace, par exemple, servira plus de test pour le bon fonctionnement de Gem-graph que de modèle d'étude. +- on peut considérer un espace rempli de flèches aux 2/3 comme équivalent à un espace repli au tiers (1/3) mais où les flèches seraient écrites "en creux" et, par conséquent, moins lisibles. Inutile, donc, de remplir plus de la moitié de l'espace. +D'expérience, +- les densités de l'ordre du tiers (1/3 des unités de l'espace occupées par au moins une flèche) suffisent à représenter un nombre de phénomènes tel qu'il n'est pas nécessaire, au moins dans un premier temps, de prévoir davantage (mais des réalloc sont toujours possibles) et les densités trop fortes sont peu lisibles. +Un buffer lignes pourrait donc avoir une taille fixe qui serait calculée selon les paramètres suivants : +- x * y * z = nombre de cubes +- nombre de flèches moyen par cube = 2 (il s'agit d'un nombre "moyen" qui surestime très probablement le nombre de flèches utilisé par la plupart des modèles) +- dessin d'une flèche seule dans un cube = 3 + 4 traits (soit 14 nombres) +Faut-il coder cette option ? + + diff --git a/include/buffers.h b/include/buffers.h index 96bcc0e..5df5e51 100644 --- a/include/buffers.h +++ b/include/buffers.h @@ -26,22 +26,23 @@ #include #include -bool compute_space_and_arrows(int model_space_size_x, - int model_space_size_y, - int model_space_size_z, +bool compute_space_and_arrows(long model_space_size_x, + long model_space_size_y, + long model_space_size_z, - GLubyte *arrows, + GLuint *arrows, int model_arrows_nb, - int pref_3D_xor_2D_space, - int pref_3D_xor_2D_arrows, - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors, +// int pref_mark_unit_space, +// int pref_style_lines_planes, +// int pref_style_mix_colors, + int pref_show_grid, + int pref_test_diagonal, GLfloat *vertex_origin, GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin); + GLuint *line_origin, + GLuint *plan_origin); + diff --git a/src/graphics/buffers.c b/src/graphics/buffers.c index be7547b..8a77fc2 100644 --- a/src/graphics/buffers.c +++ b/src/graphics/buffers.c @@ -4,9 +4,6 @@ * Desc: OpenGL utils header * * Copyright (C) 2023 Jean Sirmai - * Copyleft (something) ( ;- )) Isn't that fun ?! -------|cbF@^@ââ63-OPM,FJ&_(_((T^RQ491486Jn||lpv)=à)o! - * []xgey('"auU~|~`RIO7y89+1/CHR+-/+à&Ç-_'(-_çéy&# - * "tà(utgey(91JI2aFIgB[|[~&Ç(=À'7hu0eiCHR+-/+à&Ç-) * * This file is part of Gem-graph. * @@ -44,620 +41,567 @@ #include "../../include/graphics.h" #include "../../include/buffers.h" -int vertex_ndx = 0; -int colors_ndx = 0; -int lines_ndx = 0; -int plans_ndx = 0; +static long vertex_index = 0; +static long colors_index = 0; +static long lines_index = 0; +static long plans_index = 0; -#define EDGE 0.999999 -#define S 0 -#define S3 0 -#define SA 1 -#define A3 0 -#define L 0 -#define V 0 -#define C 0 -#define P 0 - -static bool compute_space_2D(int space_size_x, - int space_size_y, - int space_size_z, - - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin) +static bool grids_intersections (long x, long y, long z, + GLfloat *vertex_origin, GLfloat *colors_origin) { - float x = 0; - // for (int k = 0; k < space_size_x + 1; k++) <=> + 1 - // car on passe du nombre de cases = (n) - // au nombre de séparations entre les cases + les deux bords = (n + 1) + float i, j, k, vx, vy, vz, max = fmax(x, y); + max = fmax(max, z); - if (S) printf("space_2D vertex "); - for (int k = 0; k < space_size_x; k++){ // barres verticales - // - x = ((space_size_x % 2) * (space_size_x / 2 - k) - + (space_size_x % 2 - 1) * (k + 0.5f - space_size_x / 2)) / space_size_x * 2 * EDGE; + for (i = 0; i <= x; i++) + for (j = 0; j <= y; j++) + for (k = 0; k <= z; k++){ - if (S) printf("[%1.1f] ", x); + vx = (2 * i / x - 1) * x / max; + vy = (2 * j / y - 1) * y / max; + vz = (2 * k / z - 1) * z / max; - *(vertex_origin + k * 6 + 0) = - x; - *(vertex_origin + k * 6 + 1) = 1.0f / space_size_x; - *(vertex_origin + k * 6 + 2) = 0.0f; + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz; - *(vertex_origin + k * 6 + 3) = - x; - *(vertex_origin + k * 6 + 4) = - 1.0f / space_size_x; - *(vertex_origin + k * 6 + 5) = 0.0f; + vertex_index += 3; - // fun > if (k == space_size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f; + *(colors_origin + colors_index + 0) = 0.64f;// 3 * vx / 2; + *(colors_origin + colors_index + 1) = 0.64f;// 3 * vy / 2; + *(colors_origin + colors_index + 2) = 0.64f;// 3 * vz / 2; - vertex_ndx += 6; if (V) printf(" => vertex_ndx = %3d space 2D\n", vertex_ndx); + colors_index += 3; + }; - *(color_origin + k * 6 + 0) = 1; - *(color_origin + k * 6 + 1) = 0; - *(color_origin + k * 6 + 2) = 0; - - *(color_origin + k * 6 + 3) = 1; - *(color_origin + k * 6 + 4) = 1; - *(color_origin + k * 6 + 5) = 0; - - colors_ndx += 6; - - *(line_origin + k * 2 + 0) = k * 2 + 0; - *(line_origin + k * 2 + 1) = k * 2 + 1; - - lines_ndx += 2; if (L) printf(" => lines_ndx = %3d space 2D\n", lines_ndx); - } - - *(color_origin + 0) = 0; - *(color_origin + 1) = 0; - *(color_origin + 2) = 0; - - *(color_origin + 3) = 1; - *(color_origin + 4) = 1; - *(color_origin + 5) = 1; - - *(color_origin + (space_size_x - 1) * 6 + 0) = 1; - *(color_origin + (space_size_x - 1) * 6 + 1) = 1; - *(color_origin + (space_size_x - 1) * 6 + 2) = 1; - - *(color_origin + (space_size_x - 1) * 6 + 3) = 0; - *(color_origin + (space_size_x - 1) * 6 + 4) = 0; - *(color_origin + (space_size_x - 1) * 6 + 5) = 0; - - colors_ndx += 12; if (C) printf(" => colors_ndx = %d\n", colors_ndx); - - *(line_origin + lines_ndx + 0) = 0; - *(line_origin + lines_ndx + 1) = space_size_x * 2 - 2; // barre horizontale du bas - - *(line_origin + lines_ndx + 2) = 1; - *(line_origin + lines_ndx + 3) = space_size_x * 2 - 1; // barre horizontale du haut - - lines_ndx += 4; if (L) printf("H=> lines_ndx = %3d space 2D H\n", lines_ndx); - - if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit - { - *(line_origin + lines_ndx + 0) = 0; - *(line_origin + lines_ndx + 1) = 3; - - *(line_origin + lines_ndx + 2) = 1; - *(line_origin + lines_ndx + 3) = 2; - - lines_ndx += 4; if (L) printf("X=> lines_ndx = %3d space 2D X\n", lines_ndx); - - } - - if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit - { - *(line_origin + lines_ndx + 0) = (space_size_x - 2) * 2 + 0; - *(line_origin + lines_ndx + 1) = (space_size_x - 2) * 2 + 3; - - *(line_origin + lines_ndx + 2) = (space_size_x - 2) * 2 + 1; - *(line_origin + lines_ndx + 3) = (space_size_x - 2) * 2 + 2; - - lines_ndx +=4; if (L) printf("X=> lines_ndx = %3d space 2D X\n", lines_ndx); - - } - - if (S) printf(" n = %d x 2 côté = [%1.1f]\n", space_size_x + 1, 2.0f / space_size_x); - if (S) printf("space_2D line_origin (%d - space_size_x(0)) x (%d - space_size_x(1)) ", 0, 1); - for (int v = 0; v < space_size_x + 2; v++) - if (S) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1)); - if (S) printf(" n = 4 + (%d x 2)\n", space_size_x + 2); - - return 1; + return 1; } -#define A2 1 -static int compute_arrow_2D(int space_size_x, - int space_size_y, - int space_size_z, - int weight, - int site, - int x, - int y, - int z, - - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin) +static bool arrows_anchors (long x, long y, long z, + GLfloat *vertex_origin, GLfloat *colors_origin) { - printf("compute_arrow_2D load = %d site = %d x = %d\n", weight, site, x); - float zero = 0.0f; - float center = (1.0f / space_size_x) * (2 * x - space_size_x + 2); - float tip = center + (2 * site - 1) * (1.0f / space_size_x - 0.01f); - float base = center + (2 * site - 1) * (0.1f / space_size_x); - float lat = 0.4f / space_size_x; + /* beaucoup de ^c ^v ici (peu d'info) (mais un peu) - *(vertex_origin + vertex_ndx + 0) = tip; - *(vertex_origin + vertex_ndx + 1) = zero; - *(vertex_origin + vertex_ndx + 2) = zero; + X - X = EAST - WEST = rouge - cyan + Y - Y = ZENITH - NADIR = vert - magenta + Z - Z = NORTH - SOUTH = bleu - jaune - *(vertex_origin + vertex_ndx + 3) = base; - *(vertex_origin + vertex_ndx + 4) = lat; - *(vertex_origin + vertex_ndx + 5) = zero; + */ - *(vertex_origin + vertex_ndx + 6) = base; - *(vertex_origin + vertex_ndx + 7) = - lat; - *(vertex_origin + vertex_ndx + 8) = zero; + float max = fmax(x, y); + max = fmax(max, z); - vertex_ndx += 9; if (V) printf(" => vertex_ndx = %3d arrow_2D\n", vertex_ndx); + float i, j, k, vx, vy, vz, + ad = 1 / max, + a_third = 0.3f * ad, // a_third donne la dimension de l'étoile centrale + eps = 0.1 * ad; // eps(ilon) servira à décaler légèrement les pointes des flèches + // pour qu'elles n'aillent pas jusqu'aux faces des cubes - if (pref_style_lines_planes == 0) { - if (V) printf("0=> lines_ndx = %d\n", lines_ndx); + if (0) printf("arrows_anchors 1 / max = %5.2f max / 2 = %5.2f\n", ad, max / 2); - *(line_origin + lines_ndx + 0) = vertex_ndx / 3 - 3; - *(line_origin + lines_ndx + 1) = vertex_ndx / 3 - 2; + for (i = 0; i < x; i++) + for (j = 0; j < y; j++) + for (k = 0; k < z; k++){ - *(line_origin + lines_ndx + 2) = vertex_ndx / 3 - 3; - *(line_origin + lines_ndx + 3) = vertex_ndx / 3 - 1; + vx = (2 * i / x - 1) * x / max + ad; + vy = (2 * j / y - 1) * y / max + ad; + vz = (2 * k / z - 1) * z / max + ad; - *(line_origin + lines_ndx + 4) = vertex_ndx / 3 - 2; - *(line_origin + lines_ndx + 5) = vertex_ndx / 3 - 1; + // X - X axis Central Star - lines_ndx += 6; if (L) printf("|=> lines_ndx = %3d arrow_2D\n", lines_ndx); + *(vertex_origin + vertex_index + 0) = vx + a_third; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx - a_third; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + + // Y - Y axis Central Star + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy + a_third; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy - a_third; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + + // Z - Z axis Central Star + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz + a_third; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz - a_third; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 0.3f; + *(colors_origin + colors_index + 1) = 0.3f; + *(colors_origin + colors_index + 2) = 0.3f; + + colors_index += 3; + + //-------------------------------------------------------------- + + // X - X axis arrows tips near the faces centers EAST - WEST + + *(vertex_origin + vertex_index + 0) = vx + ad - eps; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx - ad + eps; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 1; + *(colors_origin + colors_index + 1) = 0; + *(colors_origin + colors_index + 2) = 0; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 0; + *(colors_origin + colors_index + 1) = 1; + *(colors_origin + colors_index + 2) = 1; + + colors_index += 3; + + + // Y - Y axis arrows tips near the faces centers ZENITH - NADIR + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy + ad - eps; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy - ad + eps; + *(vertex_origin + vertex_index + 2) = vz; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 0; + *(colors_origin + colors_index + 1) = 1; + *(colors_origin + colors_index + 2) = 0; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 1; + *(colors_origin + colors_index + 1) = 0; + *(colors_origin + colors_index + 2) = 1; + + colors_index += 3; + + + // Z - Z axis arrows tips near the faces centers NORTH - SOUTH + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz + ad - eps; + + vertex_index += 3; + + *(vertex_origin + vertex_index + 0) = vx; + *(vertex_origin + vertex_index + 1) = vy; + *(vertex_origin + vertex_index + 2) = vz - ad + eps; + + vertex_index += 3; + + *(colors_origin + colors_index + 0) = 0; + *(colors_origin + colors_index + 1) = 0; + *(colors_origin + colors_index + 2) = 1; + + colors_index += 3; + + *(colors_origin + colors_index + 0) = 1; + *(colors_origin + colors_index + 1) = 1; + *(colors_origin + colors_index + 2) = 0; + + colors_index += 3; + + + }; + + + return 1; +} + + +static void draw_line (GLuint *lines_origin, int a, int b) +{ + *(lines_origin + lines_index) = a; lines_index ++; + *(lines_origin + lines_index) = b; lines_index ++; +} + +static void draw_a_cube_at(long u, long v, long w, GLuint *lines_origin, + long size_x, long size_y, long size_z, bool diagonals) +{ + long step_z = 1, step_y = size_z, step_x = size_y * size_z, x = u + 1, y = v + 1, z = w + 1; + +// draw_line (lines_origin, 0,21); draw_line (lines_origin, 21,42); +// ce qui suit ne vaut que dans un espace 3 x 3 x 3 (le reste est à corriger - ou à oublier ?) + draw_line (lines_origin, 21,22); draw_line (lines_origin, 21,25); + draw_line (lines_origin, 25,26); draw_line (lines_origin, 22,26); + draw_line (lines_origin, 37,41); draw_line (lines_origin, 41,42); + draw_line (lines_origin, 38,42); draw_line (lines_origin, 37,38); + draw_line (lines_origin, 25,41); draw_line (lines_origin, 21,37); + draw_line (lines_origin, 26,42); draw_line (lines_origin, 22,38); + + /* draw_line (lines_origin, step_z * w + step_y * v + step_x * u, step_z * (w + 0) + step_y * (v + 0) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * w + step_y * v + step_x * u, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 0)); */ + /* draw_line (lines_origin, step_z * w + step_y * v + step_x * u, step_z * (w + 1) + step_y * (v + 1) + step_x * (u + 0)); */ + /* draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * (w + 1) + step_y * (v + 1) + step_x * (u + 0)); */ + /* draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * (w + 1) + step_y * (v + 0) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * w + step_y * v + step_x * x, step_z * (w + 1) + step_y * (v + 0) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * w + step_y * v + step_x * x, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * w + step_y * y + step_x * u, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * z + step_y * v + step_x * u, step_z * (w + 1) + step_y * (v + 1) + step_x * (u + 0)); */ + /* draw_line (lines_origin, step_z * z + step_y * v + step_x * u, step_z * (w + 1) + step_y * (v + 0) + step_x * (u + 1)); */ + /* draw_line (lines_origin, step_z * z + step_y * y + step_x * u, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 0)); */ + + if (diagonals){ + draw_line (lines_origin, step_z * w + step_y * v + step_x * u, step_z * (w + 1) + step_y * (v + 1) + step_x * (u + 1)); + draw_line (lines_origin, step_z * w + step_y * v + step_x * x, step_z * (w + 1) + step_y * (v + 1) + step_x * (u + 0)); + draw_line (lines_origin, step_z * z + step_y * v + step_x * u, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 1)); + draw_line (lines_origin, step_z * w + step_y * y + step_x * u, step_z * (w + 1) + step_y * (v + 0) + step_x * (u + 1)); } +} - if (pref_style_lines_planes == 1) { - *(plan_origin + plans_ndx + 0) = vertex_ndx / 3 + 0; - *(plan_origin + plans_ndx + 1) = vertex_ndx / 3 + 1; - *(plan_origin + plans_ndx + 2) = vertex_ndx / 3 + 2; +static void draw_ridges_3D (long x, long y, long z, + long step_x, long step_y, long step_z, + GLuint *lines_origin) +{ + draw_line (lines_origin, step_z * 0 + step_y * 0 + step_x * 0, step_z * 0 + step_y * 0 + step_x * x); + draw_line (lines_origin, step_z * 0 + step_y * 0 + step_x * 0, step_z * 0 + step_y * y + step_x * 0); + draw_line (lines_origin, step_z * 0 + step_y * 0 + step_x * 0, step_z * z + step_y * 0 + step_x * 0); + draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * 0 + step_y * y + step_x * x); + draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * z + step_y * y + step_x * 0); + draw_line (lines_origin, step_z * z + step_y * y + step_x * x, step_z * z + step_y * 0 + step_x * x); + draw_line (lines_origin, step_z * 0 + step_y * 0 + step_x * x, step_z * 0 + step_y * y + step_x * x); + draw_line (lines_origin, step_z * 0 + step_y * 0 + step_x * x, step_z * z + step_y * 0 + step_x * x); + draw_line (lines_origin, step_z * z + step_y * 0 + step_x * 0, step_z * z + step_y * y + step_x * 0); + draw_line (lines_origin, step_z * 0 + step_y * y + step_x * 0, step_z * 0 + step_y * y + step_x * x); + draw_line (lines_origin, step_z * 0 + step_y * y + step_x * 0, step_z * z + step_y * y + step_x * 0); + draw_line (lines_origin, step_z * z + step_y * 0 + step_x * 0, step_z * z + step_y * 0 + step_x * x); +} - *(plan_origin + plans_ndx + 3) = vertex_ndx / 3 + 0; - *(plan_origin + plans_ndx + 4) = vertex_ndx / 3 + 1; - *(plan_origin + plans_ndx + 5) = vertex_ndx / 3 + 2; - plans_ndx += 6; if (P) printf("|=> plans_ndx = %d\n", plans_ndx); - } +static bool draw_grids_3D (long x, long y, long z, + long step_x, long step_y, long step_z, + GLuint *lines_origin, + int pref_show_grid) +{ + x ++; y ++; z ++; + float calcul = 0; + + if (pref_show_grid % 2 == 0) + for (int u = 0; u < y; u ++){ + for (int w = 0; w < x; w ++){ + calcul = step_x * w + step_y * u; + // écriture plus concise en utilisant la fonction "draw_line(...){...}" + // mais probablement plus lente. + // Je commente donc la ligne "draw_line" et laisse les deux lignes suivantes actives + // draw_line (lines_origin, calcul, calcul + step_y - step_z); + *(lines_origin + lines_index) = calcul; lines_index ++; + *(lines_origin + lines_index) = calcul + step_y - step_z; lines_index ++; + } + } + + if (pref_show_grid % 3 == 0) + for (int u = 0; u < z; u ++){ + for (int w = 0; w < x; w ++){ + calcul = step_x * w + step_z * u; + *(lines_origin + lines_index) = calcul; lines_index ++; + *(lines_origin + lines_index) = calcul + step_x - step_y; lines_index ++; + } + } + + if (pref_show_grid % 5 == 0) + for (int u = 0; u < z; u ++){ + for (int w = 0; w < y; w ++){ + calcul = step_y * w + step_z * u; + *(lines_origin + lines_index) = calcul; lines_index ++; + *(lines_origin + lines_index) = calcul + step_x * (x - 1); lines_index ++; + } + } + return 0; } -static bool compute_space_3D (int space_size_x, - int space_size_y, - int space_size_z, - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors, - GLfloat *vertex_origin, - GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin) + + +static void diagonal_test(long x, long y, long z, + long step_x, long step_y, long step_z, + GLuint *lines_origin) { - - float x = 0; - // for (int k = 0; k < space_size_x + 1; k++) <=> + 1 car - // on passe du nombre de cases = (n) - // au nombre de séparations entre les cases + les deux bords = (n + 1) - - if (S3) printf("space 3D (vertex) x localizations "); - for (int k = 0; k < space_size_x; k++){ // barres verticales - // - x = ((space_size_x % 2) * (space_size_x / 2 - k) - + (space_size_x % 2 - 1) * (k + 0.5f - space_size_x / 2)) / space_size_x * 2 * EDGE; - - if (S3) printf("[%1.1f] ", x); - - *(vertex_origin + k * 12 + 0) = - x; - *(vertex_origin + k * 12 + 1) = 1.0f / space_size_x; - *(vertex_origin + k * 12 + 2) = 1.0f / space_size_x; - - *(vertex_origin + k * 12 + 3) = - x; - *(vertex_origin + k * 12 + 4) = - 1.0f / space_size_x; - *(vertex_origin + k * 12 + 5) = - 1.0f / space_size_x; - - *(vertex_origin + k * 12 + 6) = - x; - *(vertex_origin + k * 12 + 7) = 1.0f / space_size_x; - *(vertex_origin + k * 12 + 8) = - 1.0f / space_size_x; - - *(vertex_origin + k * 12 + 9) = - x; - *(vertex_origin + k * 12 + 10) = - 1.0f / space_size_x; - *(vertex_origin + k * 12 + 11) = 1.0f / space_size_x; - - vertex_ndx += 12; if (V) printf(" => vertex_ndx = %3d space_3D\n", vertex_ndx); - - *(color_origin + k * 12 + 0) = 1; // 1 - (k / space_size_x); - *(color_origin + k * 12 + 1) = 0; - *(color_origin + k * 12 + 2) = 0; - - *(color_origin + k * 12 + 3) = 0.2f; - *(color_origin + k * 12 + 4) = 1; - *(color_origin + k * 12 + 5) = 0; - - *(color_origin + k * 12 + 6) = 1; - *(color_origin + k * 12 + 7) = 1; - *(color_origin + k * 12 + 8) = 0; - - *(color_origin + k * 12 + 9) = 0; - *(color_origin + k * 12 + 10) = 0; - *(color_origin + k * 12 + 11) = 1; - - colors_ndx += 12; if (C) printf(" => colors_ndx = %d\n", colors_ndx); - } - - *(color_origin + 0) = 0; - *(color_origin + 1) = 0; - *(color_origin + 2) = 0; - - *(color_origin + 3) = 1; - *(color_origin + 4) = 1; - *(color_origin + 5) = 1; - - *(color_origin + 6) = 0; - *(color_origin + 7) = 0; - *(color_origin + 8) = 0; - - *(color_origin + 9) = 1; - *(color_origin + 10) = 1; - *(color_origin + 11) = 1; - - colors_ndx += 12; if (C) printf(" => colors_ndx = %d\n", colors_ndx); - - *(color_origin + (space_size_x - 1) * 12 + 0) = 1; - *(color_origin + (space_size_x - 1) * 12 + 1) = 1; - *(color_origin + (space_size_x - 1) * 12 + 2) = 1; - - *(color_origin + (space_size_x - 1) * 12 + 3) = 0; - *(color_origin + (space_size_x - 1) * 12 + 4) = 0; - *(color_origin + (space_size_x - 1) * 12 + 5) = 0; - - *(color_origin + (space_size_x - 1) * 12 + 6) = 0; - *(color_origin + (space_size_x - 1) * 12 + 7) = 0; - *(color_origin + (space_size_x - 1) * 12 + 8) = 0; - - *(color_origin + (space_size_x - 1) * 12 + 9) = 1; - *(color_origin + (space_size_x - 1) * 12 + 10) = 1; - *(color_origin + (space_size_x - 1) * 12 + 11) = 1; - - colors_ndx += 12; if (C) printf(" => colors_ndx = %d\n", colors_ndx); - - if (S3) printf(" n = %d x 2 côté = [%1.1f]\n", space_size_x + 1, 2.0f / space_size_x); - - *(line_origin + 4) = 0; - *(line_origin + 5) = space_size_x * 4 - 4; // barre horizontale du bas arr - - *(line_origin + 6) = 1; - *(line_origin + 7) = space_size_x * 4 - 3; // barre horizontale du haut arr - - *(line_origin + 0) = 2; - *(line_origin + 1) = space_size_x * 4 - 2; // barre horizontale du bas av - - *(line_origin + 2) = 3; - *(line_origin + 3) = space_size_x * 4 - 1; // barre horizontale du haut av - - lines_ndx += 8; if (L) printf("|=> lines_ndx = %3d space 3D\n", lines_ndx); - - /* *(plan_origin + 0) = 0; */ - /* *(plan_origin + 1) = 1; */ - /* *(plan_origin + 2) = 2; */ - - /* *(plan_origin + 3) = 0; */ - /* *(plan_origin + 4) = 1; */ - /* *(plan_origin + 5) = 3; */ - // plans_ndx += 6; if (P) printf("|=> plans_ndx = %d\n", plans_ndx); - - - for (int k = 8; k <= space_size_x * 8; k += 8){ // for (int k = 8; k < space_size_x * 8; k += 8){ - - - *(line_origin + k + 0) = k / 2 - 4; // + 0; - *(line_origin + k + 1) = k / 2 - 2; // + 2; - - *(line_origin + k + 2) = k / 2 - 3; // + 1; - *(line_origin + k + 3) = k / 2 - 1; // + 3; - - *(line_origin + k + 4) = k / 2 - 4; // + 0; - *(line_origin + k + 5) = k / 2 - 1; // + 3; - - *(line_origin + k + 6) = k / 2 - 3; // + 1; - *(line_origin + k + 7) = k / 2 - 2; // + 2; - - lines_ndx += 8; if (L) printf("|=> lines_ndx = %3d space_3D\n", lines_ndx); - } - - if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) { - - *(line_origin + (2 + space_size_x) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro - *(line_origin + (2 + space_size_x) * 8 - 3) = 0 + 1; - - *(line_origin + (2 + space_size_x) * 8 - 2) = 0 + 2; // diagonales pour marquer la case zéro - *(line_origin + (2 + space_size_x) * 8 - 1) = 0 + 3; - - lines_ndx += 4; if (L) printf("|=> lines_ndx = %3d space_3D\n", lines_ndx); - } - - if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) { - - *(line_origin + (2 + space_size_x) * 8 - 8) = (space_size_x - 1) * 4 + 0; // diagonales pour marquer la case finale - *(line_origin + (2 + space_size_x) * 8 - 7) = (space_size_x - 1) * 4 + 1; - - *(line_origin + (2 + space_size_x) * 8 - 6) = (space_size_x - 1) * 4 + 2; // diagonales pour marquer la case finale - *(line_origin + (2 + space_size_x) * 8 - 5) = (space_size_x - 1) * 4 + 3; - - lines_ndx += 4; if (L) printf("|=> lines_ndx = %3d space_3D\n", lines_ndx); - } - - if (S3) printf("space 3D buffer_lines (from-to) "); - for (int v = 0; v < space_size_x + 2; v++) { - if (S3) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1)); - } - if (S3) printf("\n"); - - return 1; + draw_line (lines_origin, 0, step_z * z + step_y * y + step_x * x); } -static bool compute_arrow_3D(int space_size_x, - int space_size_y, - int space_size_z, - int weight, - int site, - int x, - int y, - int z, - - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin) +static void draw_an_arrow_East_or_West (GLuint *lines_origin, long s, int weight, int site) { - float zero = 0.0f; - float center = (1.0f / space_size_x) * (2 * x - space_size_x + 2); - float tip = center + (2 * site - 1) * (1.0f / space_size_x); - float base = center + (2 * site - 1) * (0.1f / space_size_x); + draw_line (lines_origin, s + 2, s + 6 + site % 2); + draw_line (lines_origin, s + 3, s + 6 + site % 2); - *(vertex_origin + vertex_ndx + 0) = center + (2 * site - 1) * (1.0f / space_size_x - 0.01f); - *(vertex_origin + vertex_ndx + 1) = zero; - *(vertex_origin + vertex_ndx + 2) = zero; - - *(vertex_origin + vertex_ndx + 3) = base; - *(vertex_origin + vertex_ndx + 4) = 0.4f / space_size_x; - *(vertex_origin + vertex_ndx + 5) = 0.4f / space_size_x; - - *(vertex_origin + vertex_ndx + 6) = base; - *(vertex_origin + vertex_ndx + 7) = 0.4f / space_size_x; - *(vertex_origin + vertex_ndx + 8) = - 0.4f / space_size_x; - - *(vertex_origin + vertex_ndx + 9) = base; - *(vertex_origin + vertex_ndx + 10) = - 0.4f / space_size_x; - *(vertex_origin + vertex_ndx + 11) = - 0.4f / space_size_x; - - *(vertex_origin + vertex_ndx + 12) = base; - *(vertex_origin + vertex_ndx + 13) = - 0.4f / space_size_x; - *(vertex_origin + vertex_ndx + 14) = 0.4f / space_size_x; - - vertex_ndx += 15; if (V) printf(" => vertex_ndx = %3d arrow_3D\n", vertex_ndx); - - if (A3) printf("center = %f tip = %f base = %f\n",\ - center, tip, base); // space_size_x * 12=%d igap=%d - - if (pref_style_lines_planes == 0) { - - *(line_origin + lines_ndx + 0) = vertex_ndx / 3 - 5; - *(line_origin + lines_ndx + 1) = vertex_ndx / 3 - 4; - - *(line_origin + lines_ndx + 2) = vertex_ndx / 3 - 5; - *(line_origin + lines_ndx + 3) = vertex_ndx / 3 - 3; - - *(line_origin + lines_ndx + 4) = vertex_ndx / 3 - 5; - *(line_origin + lines_ndx + 5) = vertex_ndx / 3 - 2; - - *(line_origin + lines_ndx + 6) = vertex_ndx / 3 - 5; - *(line_origin + lines_ndx + 7) = vertex_ndx / 3 - 1; - - *(line_origin + lines_ndx + 8) = vertex_ndx / 3 - 4; - *(line_origin + lines_ndx + 9) = vertex_ndx / 3 - 3; - - *(line_origin + lines_ndx + 10) = vertex_ndx / 3 - 3; - *(line_origin + lines_ndx + 11) = vertex_ndx / 3 - 2; - - *(line_origin + lines_ndx + 12) = vertex_ndx / 3 - 2; - *(line_origin + lines_ndx + 13) = vertex_ndx / 3 - 1; - - *(line_origin + lines_ndx + 14) = vertex_ndx / 3 - 1; - *(line_origin + lines_ndx + 15) = vertex_ndx / 3 - 4; - - lines_ndx += 16; if (L) printf("|=> lines_ndx = %3d arrow_3D\n", lines_ndx); - } - - if (pref_style_lines_planes == 1) { - - *(plan_origin + plans_ndx + 0) = space_size_x * 12 / 3 + 0; - *(plan_origin + plans_ndx + 1) = space_size_x * 12 / 3 + 1; - *(plan_origin + plans_ndx + 2) = space_size_x * 12 / 3 + 2; - - *(plan_origin + plans_ndx + 3) = space_size_x * 12 / 3 + 0; - *(plan_origin + plans_ndx + 4) = space_size_x * 12 / 3 + 3; - *(plan_origin + plans_ndx + 5) = space_size_x * 12 / 3 + 4; - - *(plan_origin + plans_ndx + 0) = space_size_x * 12 / 3 + 0; - *(plan_origin + plans_ndx + 1) = space_size_x * 12 / 3 + 1; - *(plan_origin + plans_ndx + 2) = space_size_x * 12 / 3 + 3; - - *(plan_origin + plans_ndx + 3) = space_size_x * 12 / 3 + 0; - *(plan_origin + plans_ndx + 4) = space_size_x * 12 / 3 + 2; - *(plan_origin + plans_ndx + 5) = space_size_x * 12 / 3 + 4; - - plans_ndx += 12; if (P) printf("|=> plans_ndx = %3d arrow_3D\n", plans_ndx); - } - - return 1; + draw_line (lines_origin, s + 4, s + 6 + site % 2); + draw_line (lines_origin, s + 5, s + 6 + site % 2); } -static void show_user_choices(int model_space_size_x, - int model_space_size_y, - int model_space_size_z, +static void draw_an_arrow_Zenith_or_Nadir (GLuint *lines_origin, long s, int weight, int site) +{ + draw_line (lines_origin, s + 0, s + 8 + site % 2); + draw_line (lines_origin, s + 1, s + 8 + site % 2); - GLubyte *arrows, + draw_line (lines_origin, s + 4, s + 8 + site % 2); + draw_line (lines_origin, s + 5, s + 8 + site % 2); +} + +static void draw_an_arrow_North_or_South (GLuint *lines_origin, long s, int weight, int site) +{ + draw_line (lines_origin, s + 0, s + 10 + site % 2); + draw_line (lines_origin, s + 1, s + 10 + site % 2); + + draw_line (lines_origin, s + 2, s + 10 + site % 2); + draw_line (lines_origin, s + 3, s + 10 + site % 2); +} + + +static void draw_a_central_star(GLuint *lines_origin, long n) +{ + draw_line (lines_origin, n + 0, n + 1); + draw_line (lines_origin, n + 2, n + 3); + draw_line (lines_origin, n + 4, n + 5); +} + +// I'm standing on Earth (any planet or star or spinning spheroid, in fact) +// and looking towards its North pole + +#define EAST 0 // + x rouge +#define WEST 1 // - x cyan +#define ZENITH 2 // + y vert +#define NADIR 3 // - y magenta +#define SOUTH 4 // - z jaune +#define NORTH 5 // + z bleu + +static void draw_some_arrows_demo (GLuint *lines_origin, + long s, long x, long y, long z, + GLuint *arrows, int arrows_nb) +{ + long stx = z * y, sty = z, stz = 1; + long a = 0, b = 0, c = 0; + + a = 0, b = 1, c = 0; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_East_or_West (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, EAST); + a = 1, b = 1, c = 0; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_East_or_West (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, WEST); + a = 1, b = 1, c = 1; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_Zenith_or_Nadir (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, ZENITH); + a = 1, b = 2, c = 1; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_Zenith_or_Nadir (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, NADIR); + a = 2, b = 2, c = 1; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_North_or_South (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, NORTH); + a = 2, b = 2, c = 2; + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c)); + draw_an_arrow_North_or_South (lines_origin, s + 1 + 12 * (stx * a + sty * b + stz * c), 1, SOUTH); +} + +static void draw_some_arrows (GLuint *lines_origin, long s, long stx, long sty, + GLuint *arrows, int arrows_nb) +{ + long stz = 1; + long site = 0, x = 0, y = 0, z = 0; + + for (int i = 0; i < arrows_nb; i++) + { + site = *(arrows + i * 5 + 1); + x = *(arrows + i * 5 + 2); y = *(arrows + i * 5 + 3); z = *(arrows + i * 5 + 4); + // printf("[%d] site = %d x = %ld y = %ld z = %ld step x = %ld step y = %ld\n", site, i, x, y, z, stx, sty); + + draw_a_central_star (lines_origin, s + 1 + 12 * (stx * x + sty * y + stz * z)); + + if (site >-1 && site < 2) draw_an_arrow_East_or_West (lines_origin, s + 1 + 12 * (stx * x + sty * y + stz * z), 1, site); + if (site > 3 && site < 6) draw_an_arrow_North_or_South (lines_origin, s + 1 + 12 * (stx * x + sty * y + stz * z), 1, site); + if (site > 1 && site < 4) draw_an_arrow_Zenith_or_Nadir (lines_origin, s + 1 + 12 * (stx * x + sty * y + stz * z), 1, site); + } +} + + + +// X - X = EAST - WEST = rouge - cyan +// Y - Y = ZENITH - NADIR = vert - magenta +// Z - Z = NORTH - SOUTH = bleu - jaune + + + + + + + + + + + + + +static void show_user_choices(long model_size_x, + long model_size_y, + long model_size_z, + + GLuint *arrows, int model_arrows_nb, - int pref_3D_xor_2D_space, - int pref_3D_xor_2D_arrows, - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors) +// int pref_mark_unit_space, +// int pref_style_lines_planes, +// int pref_style_mix_colors, + int pref_show_grid) { - printf("model + user constraints : x,y,z = (%d, %d, %d) ", model_space_size_x, model_space_size_y, model_space_size_z); - if (pref_3D_xor_2D_space == 0) printf("3D space "); - if (pref_3D_xor_2D_space == 1) printf("2D space "); - if (model_arrows_nb > 0) printf("[%d] ", model_arrows_nb); - if (pref_3D_xor_2D_arrows == 0) printf("3D arrow(s) "); - if (pref_3D_xor_2D_arrows == 1) printf("2D arrow(s) "); - if (pref_mark_unit_space == 0) printf("no unit_space marks "); - if (pref_mark_unit_space == 1) printf("first unit space marked "); - if (pref_mark_unit_space == 2) printf("last unit_space marked "); - if (pref_mark_unit_space == 3) printf("first and last units space marked "); - if (! pref_style_lines_planes) printf("style_lines_planes = 0 "); - if (pref_style_lines_planes > 0)printf("style_lines_planes = %d ", pref_style_lines_planes); - if (! pref_style_mix_colors) printf("style_mix_colors = 0 "); - if (pref_style_mix_colors > 0) printf("style_mix_colors = %d ", pref_style_mix_colors); - if (model_arrows_nb > 0) printf("\n[ n] load site x ---- < arrows array >\ - ---------------------------------------------------------------------\n"); - // arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 } - if (SA) for (int i = 0; i < model_arrows_nb; i++) - printf("[%2d] = %2d, %2d, %2d \n",\ - i, *(arrows + i * 3), *(arrows + i * 3 + 1), *(arrows + i * 3 + 2)); -} - -bool compute_space_and_arrows(int model_space_size_x, - int model_space_size_y, - int model_space_size_z, - - GLubyte *arrows, - int model_arrows_nb, - - int pref_3D_xor_2D_space, - int pref_3D_xor_2D_arrows, - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *color_origin, - GLubyte *line_origin, - GLubyte *plan_origin) - -{ - if (SA) show_user_choices(model_space_size_x, - model_space_size_y, - model_space_size_z, - - arrows, - model_arrows_nb, - - pref_3D_xor_2D_space, - pref_3D_xor_2D_arrows, - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors); - - if (pref_3D_xor_2D_space) compute_space_2D ( - model_space_size_x, - model_space_size_y, - model_space_size_z, - - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors, - - vertex_origin, - color_origin, - line_origin, - plan_origin); - - else compute_space_3D ( - model_space_size_x, - model_space_size_y, - model_space_size_z, - - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors, - - vertex_origin, - color_origin, - line_origin, - plan_origin); - + printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", model_size_x, model_size_y, model_size_z); + if (model_arrows_nb > 0) printf("[%d] arrows ", model_arrows_nb); +// if (pref_mark_unit_space == 0) printf("no unit_space marks "); +// if (pref_mark_unit_space == 1) printf("first unit space marked "); +// if (pref_mark_unit_space == 2) printf("last unit_space marked "); +// if (pref_mark_unit_space == 3) printf("first and last units space marked "); +// if (! pref_style_lines_planes) printf("no style_lines_planes "); +// if (pref_style_lines_planes > 0) printf("style_lines_planes = %d ", pref_style_lines_planes); +// if (! pref_style_mix_colors) printf("no style_mix_colors "); +// if (pref_style_mix_colors > 0) printf("style_mix_colors = %d ", pref_style_mix_colors); + if (pref_show_grid == 1) printf("pref_show_grid = %d <> show no grid ", pref_show_grid); + if (pref_show_grid == 0) printf("pref_show_grid = %d <> show all grids ", pref_show_grid); + if (pref_show_grid == 2) printf("pref_show_grid = %d <> show grid xy ", pref_show_grid); + if (pref_show_grid == 3) printf("pref_show_grid = %d <> show grid xz ", pref_show_grid); + if (pref_show_grid == 5) printf("pref_show_grid = %d <> show grid yz ", pref_show_grid); + if (pref_show_grid == 6) printf("pref_show_grid = %d <> show grids xy & xz ", pref_show_grid); + if (pref_show_grid == 10) printf("pref_show_grid = %d <> show grids xy & yz ", pref_show_grid); + if (pref_show_grid == 15) printf("pref_show_grid = %d <> show grids xz & yz ", pref_show_grid); + if (model_arrows_nb > 0) printf("\n[ n] load site x y z ---- < arrows array >\ + ------------------------------------------------------------\n"); + // (DEPRECATED) arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 } for (int i = 0; i < model_arrows_nb; i++) - if (pref_3D_xor_2D_arrows) compute_arrow_2D( - model_space_size_x, - model_space_size_y, - model_space_size_z, + printf("[%2d] = %2d, %2d, %2d, %2d, %2d \n",\ + i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); - *(arrows + i * 3 + 0), // weight (load) - *(arrows + i * 3 + 1), // site - *(arrows + i * 3 + 2), // x - 0, // y - 0, // z + printf("NB If you play : 'draw_some_arrows_demo(...)',\ + don't forget to set model_arrows_nb to 6 (line 555 in graphics.c). \ + The 'nombre_de_cases_contenant_des_fleches' is automatically set to 6 (line 560) ( ;- ))\n"); - pref_style_lines_planes, - pref_style_mix_colors, + printf("NB The same is true if you play : 'draw_some_arrows(...)',\ + and modify the number of arrows described above the line 570.\n"); - vertex_origin, - color_origin, - line_origin, - plan_origin); + printf("NB If you play : 'draw_some_arrows(...)' and add some more arrows (above the line 570),\ + you must also increase the number of arrows (line 555) \n\ + The 'nombre_de_cases_contenant_des_fleches' is automatically set equal to the number of arrows (line 560).\n"); +} - else compute_arrow_3D( - model_space_size_x, - model_space_size_y, - model_space_size_z, - *(arrows + i * 3 + 0), // weight (load) - *(arrows + i * 3 + 1), // site - *(arrows + i * 3 + 2), // x - 0, // y - 0, // z - pref_style_lines_planes, - pref_style_mix_colors, - vertex_origin, - color_origin, - line_origin, - plan_origin); + + + + + +bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_size_z, + + GLuint *arrows, int model_arrows_nb, + +// int pref_mark_unit_space, int pref_style_lines_planes, int pref_style_mix_colors, + int pref_show_grid, int pref_test_diagonal, + + GLfloat *vertex_origin, GLfloat *colors_origin, + GLuint *lines_origin, GLuint *plans_origin) + +{ + show_user_choices(model_size_x, model_size_y, model_size_z, + arrows, model_arrows_nb, +// pref_mark_unit_space, pref_style_lines_planes, pref_style_mix_colors, + pref_show_grid); + + grids_intersections (model_size_x, model_size_y, model_size_z, vertex_origin, colors_origin); + arrows_anchors (model_size_x, model_size_y, model_size_z, vertex_origin, colors_origin); + + long step_z = 1, + step_y = model_size_z + 1, + step_x = (model_size_z + 1) * (model_size_y + 1); + + draw_grids_3D (model_size_x, model_size_y, model_size_z, step_x, step_y, step_z, lines_origin, pref_show_grid); + if (pref_show_grid > 0) draw_ridges_3D (model_size_x, model_size_y, model_size_z, step_x, step_y, step_z, lines_origin); + if (pref_test_diagonal) diagonal_test (model_size_x, model_size_y, model_size_z, step_x, step_y, step_z, lines_origin); + + long s = step_z * model_size_z + step_y * model_size_y + step_x * model_size_x; + + if (0) draw_some_arrows_demo (lines_origin, s, model_size_x, model_size_y, model_size_z, arrows, model_arrows_nb); + if (1) draw_some_arrows (lines_origin, s, model_size_z * model_size_y, model_size_z, arrows, model_arrows_nb); + + // draw_a_cube_at(1, 1, 1, lines_origin, model_size_x, model_size_y, model_size_z, 0); return 0; } +// X - X = EAST - WEST = rouge - cyan +// Y - Y = ZENITH - NADIR = vert - magenta +// Z - Z = NORTH - SOUTH = bleu - jaune diff --git a/src/graphics/copie_de_buffer.c.temp b/src/graphics/copie_de_buffer.c.temp deleted file mode 100644 index a94e50b..0000000 --- a/src/graphics/copie_de_buffer.c.temp +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Gem-graph OpenGL experiments - * - * Desc: OpenGL utils header - * - * Copyright (C) 2023 Jean Sirmai - * Copyleft (something) ( ;- )) Isn't that fun ?! ----------------,cbF@^@ââ63-OPM,FJ&_(_((T^RQJn||lpv)=à)o ----------------------------------------------------- - * - * This file is part of Gem-graph. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -//#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../include/base.h" -#include "../../include/ui.h" -#include "../../include/graphics.h" -#include "../../include/buffers.h" -#include "../../include/space_2D.h" -#include "../../include/space_3D.h" -#include "../../include/arrow_2D.h" -#include "../../include/arrow_3D.h" - -#define A 0 -int graphics_compute_lines(int line_indices_nb, - GLfloat *vertex_base, GLfloat *color_base, - GLubyte *line_ndx, int lines_nb, - int dim, int state_size, - int vertex_nb, - int colors_nb, - int arrows_nb) -{ - /// struct gl_area_entry *entry; - /// GLuint vao, vertex_buffer, color_buffer; - int vgap = 0, igap = 0, pgap = 0, cgap = 0; - - /// entry = find_entry_from_ptr(gl_area); - -// {1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21}; < from model.xml - dim = 1; - state_size = 7; // 2 < state_size < 32 - arrows_nb = 4; // assert : leur emplacement doit être fonction de state_size - - vertex_nb = (state_size + 1) * 6 + arrows_nb * 9; - vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; - colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO -// lines_nb = (2 + state_size) + (arrows_nb * 3); // cas 2D - lines_nb = (4 + state_size * 4) + (arrows_nb * 8) + 4; // + 4; pour les 4 diagonales (29/6/2023 pour voir) -//// plans_nb = 8; //(4 + state_size * 4) + (arrows_nb * 8) + 2; // bhuingfyunfyuguinlgi svbysbubsyu qvyqytqujtvcttcef - - line_indices_nb = lines_nb * 2; - - printf("Initialization of buffers with %u line_ndx, %u vertices and %u colors & state_size = %d\n", - line_indices_nb, vertex_nb, colors_nb, state_size); - -// g_malloc -// vertex_base = g_malloc0(vertex_nb * sizeof(GLfloat) * 2); -// color_base = g_malloc0(colors_nb * sizeof(GLfloat) * 2); -// line_ndx = g_malloc0(lines_nb * 2 * sizeof(GLubyte) * 2); -//// plan_ndx = g_malloc0(plans_nb * 3 * sizeof(GLubyte) * 2); - - assert(state_size * 6 < vertex_nb); assert(state_size * 6 + 5 < vertex_nb); -// compute_space_2D(state_size, vertex_base, line_ndx); -// vgap += (6 * state_size); igap += state_size * 2 + 4; cgap += (6 * state_size); - - *(line_ndx + state_size * 2 + 6 + 4) = 0; // diagonales pour marquer la case zéro - *(line_ndx + state_size * 2 + 6 + 5) = 3; - *(line_ndx + state_size * 2 + 6 + 6) = 1; - *(line_ndx + state_size * 2 + 6 + 7) = 2; - - 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); - } - - compute_space_3D(state_size, vertex_base, color_base, line_ndx, - 0,0); // 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); */ -/* 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 < line_indices_nb); assert(igap + 5 < line_indices_nb); - - - compute_arrow_3D(state_size, - vertex_base, color_base, - line_ndx, 0, // plan_ndx, - vgap, igap, cgap, - 1, 0, 0, 0, 0); - vgap += 15; igap += 16; cgap += 15; ++arrows_nb; - - compute_arrow_3D(state_size, - vertex_base, color_base, - line_ndx, 0, // plan_ndx, - vgap, igap, cgap, - 1, 1, 2, 0, 0); - vgap += 15; igap += 16; cgap += 15; ++arrows_nb; - - compute_arrow_3D(state_size, - vertex_base, color_base, - line_ndx, 0, // plan_ndx, - vgap, igap, cgap, - 1, 0, 3, 0, 0); - vgap += 15; igap += 16; cgap += 15; ++arrows_nb; - - compute_arrow_3D(state_size, - vertex_base, color_base, - line_ndx, 0, // plan_ndx, - vgap, igap, cgap, - 1, 1, 3, 0, 0); - vgap += 15; igap += 16; cgap += 15; ++arrows_nb; - - return line_indices_nb; - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 0, state_size - 2, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 1, state_size - 2, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - -/// glGenBuffers(1, &vertex_buffer); -/// glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); -/// glBufferData(GL_ARRAY_BUFFER, vertex_nb * sizeof(vertex_base[0]), vertex_base, GL_STATIC_DRAW); -/// glBindBuffer(GL_ARRAY_BUFFER, 0); - - - // colors -/// glGenBuffers(1, &color_buffer); -/// glBindBuffer(GL_ARRAY_BUFFER, color_buffer); -/// glBufferData(GL_ARRAY_BUFFER, colors_nb * sizeof(color_base), color_base, GL_STATIC_DRAW); -/// glBindBuffer(GL_ARRAY_BUFFER, 0); - - // We only use one VAO, so we always keep it bound -/// glGenVertexArrays(1, &vao); -/// glBindVertexArray(vao); - -/// if(entry != NULL) { -/// entry->vao = vao; -/// entry->position_buffer = vertex_buffer; -/// entry->color_buffer = color_buffer; -/// } -} - -#define A 0 -int graphics_compute_plans(int plan_indices_nb, - GLfloat *vertex_base, GLfloat *color_base, - GLubyte *plan_ndx, int plans_nb, - int dim, int state_size, - int vertex_nb, - int colors_nb, - int arrows_nb) -{ - /// int line_indices_nb = 0; // AD HOC ! - /// struct gl_area_entry *entry; - /// GLuint vao, vertex_buffer, color_buffer; - int vgap = 0, igap = 0, pgap = 0, cgap = 0; - - /// entry = find_entry_from_ptr(gl_area); - -// {1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21}; < from model.xml - dim = 1; - state_size = 7; // 2 < state_size < 32 - arrows_nb = 4; // assert : leur emplacement doit être fonction de state_size - - vertex_nb = (state_size + 1) * 6 + arrows_nb * 9; - vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; - colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO -// lines_nb = (2 + state_size) + (arrows_nb * 3); // cas 2D -//// lines_nb = (4 + state_size * 4) + (arrows_nb * 8) + 2; // + 2; pour les 2 diagonales - plans_nb = 8; //(4 + state_size * 4) + (arrows_nb * 8) + 2; // bhuingfyunfyuguinlgi svbysbubsyu qvyqytqujtvcttcef - -//// plan_indices_nb = plans_nb * 3; - - printf("Initialization of buffers with %u plan_ndx, %u vertices and %u colors & state_size = %d\n", - plan_indices_nb, vertex_nb, colors_nb, state_size); - -// g_malloc -//// vertex_base = g_malloc0(vertex_nb * sizeof(GLfloat) * 2); -//// color_base = g_malloc0(colors_nb * sizeof(GLfloat) * 2); -//// line_ndx = g_malloc0(lines_nb * 2 * sizeof(GLubyte) * 2); - plan_ndx = g_malloc0(plans_nb * 3 * sizeof(GLubyte) * 2); - - assert(state_size * 6 < vertex_nb); assert(state_size * 6 + 5 < vertex_nb); -// compute_space_2D(state_size, vertex_base, line_ndx); -// vgap += (6 * state_size); igap += state_size * 2 + 4; cgap += (6 * state_size); - - /* *(line_ndx + state_size * 2 + 6 + 4) = 0; // diagonales pour marquer la case zéro */ - /* *(line_ndx + state_size * 2 + 6 + 5) = 3; */ - /* *(line_ndx + state_size * 2 + 6 + 6) = 1; */ - /* *(line_ndx + state_size * 2 + 6 + 7) = 2; */ - - 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); - - compute_space_3D(state_size, vertex_base, color_base, plan_ndx, - 0,0); // 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); */ -/* 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 < line_indices_nb); assert(igap + 5 < line_indices_nb); - - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, 0, // plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 0, 0, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, 0, // plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 1, 2, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, 0, // plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 0, 3, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, 0, // plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 1, 3, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - return plan_indices_nb; - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 0, state_size - 2, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - - /* compute_arrow_3D(state_size, */ - /* vertex_base, color_base, */ - /* line_ndx, plan_ndx, */ - /* vgap, igap, cgap, */ - /* 1, 1, state_size - 2, 0, 0); */ - /* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */ - -/// glGenBuffers(1, &vertex_buffer); -/// glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); -/// glBufferData(GL_ARRAY_BUFFER, vertex_nb * sizeof(vertex_base[0]), vertex_base, GL_STATIC_DRAW); -/// glBindBuffer(GL_ARRAY_BUFFER, 0); - - - // colors -/// glGenBuffers(1, &color_buffer); -/// glBindBuffer(GL_ARRAY_BUFFER, color_buffer); -/// glBufferData(GL_ARRAY_BUFFER, colors_nb * sizeof(color_base), color_base, GL_STATIC_DRAW); -/// glBindBuffer(GL_ARRAY_BUFFER, 0); - - // We only use one VAO, so we always keep it bound -/// glGenVertexArrays(1, &vao); -/// glBindVertexArray(vao); - -/// if(entry != NULL) { -/// entry->vao = vao; -/// entry->position_buffer = vertex_buffer; -/// entry->color_buffer = color_buffer; -/// } - } -} diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 99a30cf..34620d8 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -43,7 +43,6 @@ #define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define FRAG_SHADER_FILE "src/shaders/shader.frag" -#define K 0 /* ----------------- V A R I A B L E S G L O B A L E S ------------------ */ @@ -52,17 +51,20 @@ int model_space_size_x = 0; int model_space_size_y = 0; int model_space_size_z = 0; int model_arrows_nb = 0; +int nombre_de_cases_contenant_des_fleches = 0; GLfloat *buffer_vertex_origin = NULL; GLfloat *buffer_colors_origin = NULL; -GLubyte *buffer_lines_origin = NULL; -GLubyte *buffer_plans_origin = NULL; +GLuint *buffer_lines_origin = NULL; +GLuint *buffer_plans_origin = NULL; -int pref_3D_xor_2D_space = 0; // default view == 0 == 3D -int pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D -int pref_mark_unit_space = 0; // default == 0 == no marks -int pref_style_lines_planes = 0; // arrows as lines = 0, as planes = 1 -int pref_style_mix_colors = 0; // ... don't know yet ... +//int pref_3D_xor_2D_space = 0; // default view == 0 == 3D +//int pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D +//int pref_mark_unit_space = 0; // default == 0 == no marks +//int pref_style_lines_planes = 0; // arrows as lines = 0, as planes = 1 +//int pref_style_mix_colors = 0; // ... don't know yet ... +int pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc +int pref_test_diagonal = 0; // diagonal test int buffer_vertex_size = 0; int buffer_colors_size = 0; @@ -425,6 +427,7 @@ bool graphics_init_shaders(const void *gl_area) return false; vertex = create_shader(GL_VERTEX_SHADER, vertex_shader); +// ! WARNING ! l'instruction suivante (ou un autre 'free') a pu provoquer un 'double free' (Abandon) if(vertex == 0) { entry->program = 0; g_free(vertex_shader); @@ -521,21 +524,61 @@ bool graphics_init_shaders(const void *gl_area) -GLubyte arrows[] = { 1, 1, 0, 1, 0, 1, 1, 1, 4, 1, 0, 5, 1, 1, 8, 1, 0, 9 }; - // arrows[] = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 }; + + + + + + + + + + + + + + + + + + static void get_model_data_and_user_preferences(){ - model_space_size_x = 11; // 2 < model_space_size_x < 32 - model_arrows_nb = 6; // assert : l'emplacement des flèches est contraint + + model_space_size_x = 4; // 0 < model_space_size_x + model_space_size_y = 3; // 0 < model_space_size_y + model_space_size_z = 3; // 0 < model_space_size_z + + // XXX ONLY space drawed, no arrows yet + + model_arrows_nb = 9; // assert : l'emplacement des flèches est contraint // par model_space_size_x, y, z et le nombre de sites - pref_3D_xor_2D_space = 0; // 0 = 3D 1 = 2D - pref_3D_xor_2D_arrows = 0; // 0 = 3D 1 = 2D - pref_mark_unit_space = 3; // 0 = no marks, 1 = 1st, 2 = last, 3 = both - pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix - pref_style_mix_colors = 0; // TODO + + nombre_de_cases_contenant_des_fleches = 8; // à calculer TODO + // ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites) + nombre_de_cases_contenant_des_fleches = model_arrows_nb; + +// pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both +// pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix +// pref_style_mix_colors = 0; // TODO + pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc + // xyz, 0, x, y, z, xy, xz, yz, xyz + pref_test_diagonal = 0; } +GLuint arrows[] = { + 1, 0, 0, 0, 0, + 1, 1, 1, 0, 0, + 1, 2, 2, 1, 1, + 1, 3, 2, 2, 1, + 1, 4, 3, 0, 1, + 1, 5, 3, 0, 2, + 1, 1, 3, 0, 2, + 1, 0, 2, 0, 2, + 1, 5, 2, 1, 1, +// load, site, x, y, z +}; @@ -543,75 +586,92 @@ static void get_model_data_and_user_preferences(){ - - - - - - - - - - - - - - -#define S 1 static void compute_buffers_sizes(int model_space_size_x, int model_space_size_y, int model_space_size_z, int model_arrows_nb, - int pref_3D_xor_2D_space, - int pref_3D_xor_2D_arrows, - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors) +// int pref_mark_unit_space, +// int pref_style_lines_planes, +// int pref_style_mix_colors, + int pref_test_diagonal) { - int two_ladder_amounts = 4; // 2 parallels to connect 4 vertices + // XXX ONLY space and no arrows + long grids_intersections = (model_space_size_x + 1) + * (model_space_size_y + 1) + * (model_space_size_z + 1); - if (pref_3D_xor_2D_space) { // 2D the ladder has 2 amounts - buffer_vertex_size = model_space_size_x * 6; - buffer_colors_size = model_space_size_x * 6; - buffer_plans_size = 0; - buffer_lines_size = model_space_size_x * 2 + two_ladder_amounts; + long arrows_anchors = (model_space_size_x) + * (model_space_size_y) + * (model_space_size_z) + * (6 + 6); // 6 is to draw the small central star + // 6 is for the six faces centers - } else { // 3D the ladder has 4 amounts, now - buffer_vertex_size = (model_space_size_x + 1) * 12; - buffer_colors_size = (model_space_size_x + 1) * 12; - buffer_plans_size = 0; - buffer_lines_size = (model_space_size_x + 1) * 12 + 2 * two_ladder_amounts; - } + long cubes_nb = model_space_size_x * model_space_size_y * model_space_size_z; - /* There, increment in buffer_lines_size is the same for 2D & 3D */ - if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) buffer_lines_size += 4; // 2 diagonal lines - if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) buffer_lines_size += 4; // 2 diagonal lines + buffer_vertex_size = grids_intersections * 3; // 3 numbers per vertex + // + cubes_nb * (8 + 6) + 15 * model_arrows_nb;// OLD ARROWS (DEPRECATED) + buffer_vertex_size += arrows_anchors * 3; - if (pref_3D_xor_2D_arrows) { // 2D - buffer_vertex_size += model_arrows_nb * 9; - buffer_colors_size += model_arrows_nb * 9; - buffer_plans_size += 0; - buffer_lines_size += model_arrows_nb * 6; + buffer_vertex_size += 8 * 3; // draw a small cube - } else { // 3D - buffer_vertex_size += model_arrows_nb * 15; - buffer_colors_size += model_arrows_nb * 15; - buffer_plans_size += 0; - buffer_lines_size += model_arrows_nb * 16; - } -/* buffer_plans_size est fonction de : model_space_size_x, model_arrows_nb et de pref_style_lines_planes */ + buffer_colors_size = buffer_vertex_size; - if (S) printf("allocated buffers sizes :%4d/3 = %3d vertices, %4d/3 = %3d colors,\ - %4d/2 = %3d lines, %4d/3 = %3d plans. (space_size_x = %d)\n", - buffer_vertex_size, buffer_vertex_size / 3, buffer_colors_size, buffer_colors_size / 3, - buffer_lines_size, buffer_lines_size / 2, buffer_plans_size, buffer_plans_size / 3, model_space_size_x); + buffer_plans_size = 3; + + long grids_lines = + (pref_show_grid % 2 == 0) * (model_space_size_x + 1) * (model_space_size_y + 1) + + (pref_show_grid % 3 == 0) * (model_space_size_x + 1) * (model_space_size_z + 1) + + (pref_show_grid % 5 == 0) * (model_space_size_y + 1) * (model_space_size_z + 1); + + if (pref_show_grid != 1) buffer_lines_size = grids_lines * 2; + if (pref_show_grid > 0) buffer_lines_size += 12 * 2; // space ridges + // sinon, les arêtes de l'espace sont tracées par les grilles + + if (pref_test_diagonal) buffer_lines_size += 2; // la diagonale test [0 - max] + + buffer_lines_size += 6 * nombre_de_cases_contenant_des_fleches; // test central stars + + buffer_lines_size += 8 * model_arrows_nb; // flèches + +// buffer_lines_size += 16 + 20; // draw a small cube with diagonals + +// buffer_lines_size -= 2; TEST ! + + if (1) printf("allocated buffers sizes :%4d/3 = %3d vertices, %4d/3 = %3d colors,\ + %4d/2 = %3d lines, %4d/3 = %3d plans.\n", + buffer_vertex_size, buffer_vertex_size / 3, + buffer_colors_size, buffer_colors_size / 3, + buffer_lines_size, buffer_lines_size / 2, + buffer_plans_size, buffer_plans_size / 3); } + + + + + + + + + + + + + + + + + + + + + + /* Initializes the buffer of a gl_area * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget @@ -633,16 +693,15 @@ void graphics_init_buffers(const void *gl_area) model_arrows_nb, - pref_3D_xor_2D_space, - pref_3D_xor_2D_arrows, - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors); +// pref_mark_unit_space, +// pref_style_lines_planes, +// pref_style_mix_colors, + pref_test_diagonal); buffer_vertex_origin = g_malloc0(buffer_vertex_size * sizeof(GLfloat) * 2); buffer_colors_origin = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2); - buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLubyte) * 2); - buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLubyte) * 2); + buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLuint) * 2); + buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLuint) * 2); compute_space_and_arrows (model_space_size_x, model_space_size_y, @@ -651,11 +710,11 @@ void graphics_init_buffers(const void *gl_area) arrows, model_arrows_nb, - pref_3D_xor_2D_space, - pref_3D_xor_2D_arrows, - pref_mark_unit_space, - pref_style_lines_planes, - pref_style_mix_colors, +// pref_mark_unit_space, +// pref_style_lines_planes, +// pref_style_mix_colors, + pref_show_grid, + pref_test_diagonal, buffer_vertex_origin, buffer_colors_origin, @@ -722,7 +781,8 @@ void graphics_draw(const void *gl_area) /* Use our shaders */ glUseProgram(entry->program); - if (pref_style_mix_colors == 0) glClearColor(0, 0, 0, 0.4f); +// if (pref_style_mix_colors == 0) + glClearColor(0, 0, 0, 0.4f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -741,10 +801,10 @@ void graphics_draw(const void *gl_area) glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0); - glEnable(GL_DEPTH_TEST); + //glEnable(GL_DEPTH_TEST); - glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_BYTE, buffer_lines_origin); - glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_BYTE, buffer_plans_origin); + glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_INT, buffer_lines_origin); + glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_INT, buffer_plans_origin); /* We finished using the buffers and program */ glDisableVertexAttribArray(0); @@ -755,3 +815,10 @@ void graphics_draw(const void *gl_area) glFlush(); } + + + + + + + diff --git a/src/graphics/scories.c.forget b/src/graphics/scories.c.forget new file mode 100644 index 0000000..2c71b83 --- /dev/null +++ b/src/graphics/scories.c.forget @@ -0,0 +1,394 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: OpenGL utils header + * + * Copyright (C) 2023 Jean Sirmai + * + * This file was part of Gem-graph. Forget it now. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +//#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/ui.h" +#include "../../include/graphics.h" +#include "../../include/buffers.h" + +static long vertex_index = 0; +static long colors_index = 0; +static long lines_index = 0; +static long plans_index = 0; + + +#define V 0 + +static bool compute_space_2D(int size_x, + int size_y, + int size_z, + + int pref_mark_unit_space, + int pref_style_lines_planes, + int pref_style_mix_colors, + + GLfloat *vertex_origin, + GLfloat *colors_origin, + GLuint *lines_origin, + GLuint *plans_origin) +{ + + float x = 0; + // for (int k = 0; k < size_x + 1; k++) <=> + 1 + // car on passe du nombre de cases = (n) + // au nombre de séparations entre les cases + les deux bords = (n + 1) + + if (V) printf("space_2D vertex "); + for (int k = 0; k < size_x; k++){ // barres verticales + // + x = ((size_x % 2) * (size_x / 2 - k) + + (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2; + + if (V) printf("[%1.1f] ", x); + + *(vertex_origin + k * 6 + 0) = - x; + *(vertex_origin + k * 6 + 1) = 1.0f / size_x; + *(vertex_origin + k * 6 + 2) = 0.0f; + + *(vertex_origin + k * 6 + 3) = - x; + *(vertex_origin + k * 6 + 4) = - 1.0f / size_x; + *(vertex_origin + k * 6 + 5) = 0.0f; + + // fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f; + + vertex_index += 6; if (V) printf(" => vertex_index = %3ld space 2D\n", vertex_index); + + *(colors_origin + k * 6 + 0) = 1; + *(colors_origin + k * 6 + 1) = 0; + *(colors_origin + k * 6 + 2) = 0; + + *(colors_origin + k * 6 + 3) = 1; + *(colors_origin + k * 6 + 4) = 1; + *(colors_origin + k * 6 + 5) = 0; + + colors_index += 6; + + *(lines_origin + k * 2 + 0) = k * 2 + 0; + *(lines_origin + k * 2 + 1) = k * 2 + 1; + + lines_index += 2; if (V) printf(" => lines_index = %3ld space 2D\n", lines_index); + } + + *(colors_origin + 0) = 0; + *(colors_origin + 1) = 0; + *(colors_origin + 2) = 0; + + *(colors_origin + 3) = 1; + *(colors_origin + 4) = 1; + *(colors_origin + 5) = 1; + + *(colors_origin + (size_x - 1) * 6 + 0) = 1; + *(colors_origin + (size_x - 1) * 6 + 1) = 1; + *(colors_origin + (size_x - 1) * 6 + 2) = 1; + + *(colors_origin + (size_x - 1) * 6 + 3) = 0; + *(colors_origin + (size_x - 1) * 6 + 4) = 0; + *(colors_origin + (size_x - 1) * 6 + 5) = 0; + + colors_index += 12; if (V) printf(" => colors_index = %ld\n", colors_index); + + *(lines_origin + lines_index + 0) = 0; + *(lines_origin + lines_index + 1) = size_x * 2 - 2; // barre horizontale du bas + + *(lines_origin + lines_index + 2) = 1; + *(lines_origin + lines_index + 3) = size_x * 2 - 1; // barre horizontale du haut + + lines_index += 4; if (V) printf("H=> lines_index = %3ld space 2D H\n", lines_index); + + if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit + { + *(lines_origin + lines_index + 0) = 0; + *(lines_origin + lines_index + 1) = 3; + + *(lines_origin + lines_index + 2) = 1; + *(lines_origin + lines_index + 3) = 2; + + lines_index += 4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index); + + } + + if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit + { + *(lines_origin + lines_index + 0) = (size_x - 2) * 2 + 0; + *(lines_origin + lines_index + 1) = (size_x - 2) * 2 + 3; + + *(lines_origin + lines_index + 2) = (size_x - 2) * 2 + 1; + *(lines_origin + lines_index + 3) = (size_x - 2) * 2 + 2; + + lines_index +=4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index); + + } + + if (V) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x); + if (V) printf("space_2D lines_origin (%d - size_x(0)) x (%d - size_x(1)) ", 0, 1); + for (int v = 0; v < size_x + 2; v++) + if (V) printf("(%d-%d) ", *(lines_origin + v), *(lines_origin + v + 1)); + if (V) printf(" n = 4 + (%d x 2)\n", size_x + 2); + + return 1; +} + +static int compute_arrow_2D(int size_x, + int size_y, + int size_z, + + int weight, + int site, + int x, + int y, + int z, + + int pref_style_lines_planes, + int pref_style_mix_colors, + + GLfloat *vertex_origin, + GLfloat *colors_origin, + GLuint *lines_origin, + GLuint *plans_origin) +{ + printf("compute_arrow_2D load = %d site = %d x = %d\n", weight, site, x); + float zero = 0.0f; + float center = (1.0f / size_x) * (2 * x - size_x + 2); + float tip = center + (2 * site - 1) * (1.0f / size_x - 0.01f); + float base = center + (2 * site - 1) * (0.1f / size_x); + float lat = 0.4f / size_x; + + /* for (int i = 0; i < size_x; i++) */ + /* for (int j = 0; j < size_y; j++) */ + /* for (int k = 0; k < size_z; k++) */ + /* { */ + + /* x = - ((size_x % 2) * (size_x / 2 - i) */ + /* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ + /* y = - ((size_x % 2) * (size_x / 2 - j) */ + /* - (size_x % 2 - 1) * (j + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ + /* z = - ((size_x % 2) * (size_x / 2 - k) */ + /* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ + /* } */ + + *(vertex_origin + vertex_index + 0) = tip; + *(vertex_origin + vertex_index + 1) = zero; + *(vertex_origin + vertex_index + 2) = zero; + + *(vertex_origin + vertex_index + 3) = base; + *(vertex_origin + vertex_index + 4) = lat; + *(vertex_origin + vertex_index + 5) = zero; + + *(vertex_origin + vertex_index + 6) = base; + *(vertex_origin + vertex_index + 7) = - lat; + *(vertex_origin + vertex_index + 8) = zero; + + vertex_index += 9; if (V) printf(" => vertex_index = %3ld arrow_2D\n", vertex_index); + + if (pref_style_lines_planes == 0) { + + if (V) printf("0=> lines_index = %ld\n", lines_index); + + *(lines_origin + lines_index + 0) = vertex_index / 3 - 3; + *(lines_origin + lines_index + 1) = vertex_index / 3 - 2; + + *(lines_origin + lines_index + 2) = vertex_index / 3 - 3; + *(lines_origin + lines_index + 3) = vertex_index / 3 - 1; + + *(lines_origin + lines_index + 4) = vertex_index / 3 - 2; + *(lines_origin + lines_index + 5) = vertex_index / 3 - 1; + + lines_index += 6; if (V) printf("|=> lines_index = %3ld arrow_2D\n", lines_index); + } + + + if (pref_style_lines_planes == 1) { + *(plans_origin + plans_index + 0) = vertex_index / 3 + 0; + *(plans_origin + plans_index + 1) = vertex_index / 3 + 1; + *(plans_origin + plans_index + 2) = vertex_index / 3 + 2; + + *(plans_origin + plans_index + 3) = vertex_index / 3 + 0; + *(plans_origin + plans_index + 4) = vertex_index / 3 + 1; + *(plans_origin + plans_index + 5) = vertex_index / 3 + 2; + + plans_index += 6; if (V) printf("|=> plans_index = %ld\n", plans_index); + } + return 0; +} + + /* x = - ((size_x % 2) * (size_x / 2 - i) */ + /* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ + /* y = - ((size_y % 2) * (size_y / 2 - j) */ + /* - (size_y % 2 - 1) * (j + 0.5f - size_y / 2)) / size_y * 2 * EDGE; */ + /* z = - ((size_z % 2) * (size_z / 2 - k) */ + /* - (size_z % 2 - 1) * (k + 0.5f - size_z / 2)) / size_z * 2 * EDGE; */ + +static bool compute_arrow_3D(long size_x, + long size_y, + long size_z, + + int weight, + int site, // North, South, East, West, Zenith, nAdir (NSEWZA) + long x, + long y, + long z, + + int pref_style_lines_planes, + int pref_style_mix_colors, + + GLfloat *vertex_origin, + GLfloat *colors_origin, + GLuint *lines_origin, + GLuint *plans_origin) + +{ + float zero = 0.0f; + float center = (1.0f / size_x) * (2 * x - size_x + 2); + float tip = center + (2 * site - 1) * (1.0f / size_x); + float base = center + (2 * site - 1) * (0.1f / size_x); + + *(vertex_origin + vertex_index + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f); + *(vertex_origin + vertex_index + 1) = zero; + *(vertex_origin + vertex_index + 2) = zero; + + *(vertex_origin + vertex_index + 3) = base; + *(vertex_origin + vertex_index + 4) = 0.4f / size_x; + *(vertex_origin + vertex_index + 5) = 0.4f / size_x; + + *(vertex_origin + vertex_index + 6) = base; + *(vertex_origin + vertex_index + 7) = 0.4f / size_x; + *(vertex_origin + vertex_index + 8) = - 0.4f / size_x; + + *(vertex_origin + vertex_index + 9) = base; + *(vertex_origin + vertex_index + 10) = - 0.4f / size_x; + *(vertex_origin + vertex_index + 11) = - 0.4f / size_x; + + *(vertex_origin + vertex_index + 12) = base; + *(vertex_origin + vertex_index + 13) = - 0.4f / size_x; + *(vertex_origin + vertex_index + 14) = 0.4f / size_x; + + vertex_index += 15; if (V) printf(" => vertex_index = %3ld arrow_3D\n", vertex_index); + + if (V) printf("center = %f tip = %f base = %f\n",\ + center, tip, base); // size_x * 12=%d igap=%d + + if (pref_style_lines_planes == 0) { + + *(lines_origin + lines_index + 0) = vertex_index / 3 - 5; + *(lines_origin + lines_index + 1) = vertex_index / 3 - 4; + + *(lines_origin + lines_index + 2) = vertex_index / 3 - 5; + *(lines_origin + lines_index + 3) = vertex_index / 3 - 3; + + *(lines_origin + lines_index + 4) = vertex_index / 3 - 5; + *(lines_origin + lines_index + 5) = vertex_index / 3 - 2; + + *(lines_origin + lines_index + 6) = vertex_index / 3 - 5; + *(lines_origin + lines_index + 7) = vertex_index / 3 - 1; + + *(lines_origin + lines_index + 8) = vertex_index / 3 - 4; + *(lines_origin + lines_index + 9) = vertex_index / 3 - 3; + + *(lines_origin + lines_index + 10) = vertex_index / 3 - 3; + *(lines_origin + lines_index + 11) = vertex_index / 3 - 2; + + *(lines_origin + lines_index + 12) = vertex_index / 3 - 2; + *(lines_origin + lines_index + 13) = vertex_index / 3 - 1; + + *(lines_origin + lines_index + 14) = vertex_index / 3 - 1; + *(lines_origin + lines_index + 15) = vertex_index / 3 - 4; + + lines_index += 16; if (V) printf("|=> lines_index = %3ld arrow_3D\n", lines_index); + } + + if (pref_style_lines_planes == 1) { + + *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0; + *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1; + *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 2; + + *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0; + *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 3; + *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4; + + *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0; + *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1; + *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 3; + + *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0; + *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 2; + *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4; + + plans_index += 12; if (V) printf("|=> plans_index = %3ld arrow_3D\n", plans_index); + } + + return 1; +} + +static void old_arrows(int model_arrows_nb, + long model_size_x, long model_size_y, long model_size_z, + int pref_style_lines_planes, int pref_style_mix_colors, + GLuint *arrows, GLfloat *vertex_origin, GLfloat *colors_origin, + GLuint *lines_origin, GLuint *plans_origin) +{ + for (int i = 0; i < model_arrows_nb; i++) + compute_arrow_3D (model_size_x, + model_size_y, + model_size_z, + + *(arrows + i * 5 + 0), // weight (load) + *(arrows + i * 5 + 1), // site + *(arrows + i * 5 + 2), // x + *(arrows + i * 5 + 3), // y + *(arrows + i * 5 + 4), // z + + pref_style_lines_planes, + pref_style_mix_colors, + + vertex_origin, + colors_origin, + lines_origin, + plans_origin); + +} + + + // OLD ARROWS (DEPRECATED) + /* old_arrows (model_arrows_nb, model_size_x, model_size_y, model_size_z, arrows, */ + /* pref_style_lines_planes, pref_style_mix_colors, */ + /* vertex_origin, colors_origin, lines_origin, plans_origin); */ + + + + + diff --git a/src/shaders/shader.vert b/src/shaders/shader.vert index 7225b0a..23d289e 100644 --- a/src/shaders/shader.vert +++ b/src/shaders/shader.vert @@ -11,7 +11,8 @@ out vec4 color; void main(void) { - gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_position, 1); - color = vec4(1 * in_color.rgb, 1); - // color = vec4(1 * in_color.rgb, 0.2f); + float zoom = 1.5f, chrominance = 1, luminance = 1; + gl_Position = + projection_matrix * view_matrix * model_matrix * vec4(in_position, zoom); + color = vec4 (chrominance * in_color.rgb, luminance); } \ No newline at end of file