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 <jean@a-lec.org>
Acked-by: neox <neox@a-lec.org>
This commit is contained in:
Jean Sirmai 2023-06-29 22:21:06 +02:00 committed by Adrien 'neox' Bourmault
parent eaa39dc29f
commit 5549f334b8
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
18 changed files with 1306 additions and 1139 deletions

46
TODO (next version).txt Normal file
View File

@ -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 ?

View File

@ -1,34 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <GL/glu.h>
bool compute_arrow_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx,
int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z);

View File

@ -26,9 +26,23 @@
#include <stdbool.h> #include <stdbool.h>
#include <GL/glu.h> #include <GL/glu.h>
bool compute_arrow_2D(int state_size, bool compute_space_and_arrows(long model_space_size_x,
GLfloat *vertex_base, GLfloat *color_base, long model_space_size_y,
GLubyte *line_ndx, GLubyte *plan_ndx, long model_space_size_z,
int vgap, int igap, int cgap,
int weight, int site, int x, int y, int 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 *color_origin,
GLuint *line_origin,
GLuint *plan_origin);

View File

@ -5,6 +5,7 @@
* *
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org> * Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org> * Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
* *
* This file is part of Gem-graph. * This file is part of Gem-graph.
* *
@ -40,8 +41,9 @@ struct gl_area_entry {
GLuint m; // init_shaders, draw GLuint m; // init_shaders, draw
GLuint v; // init_shaders, draw GLuint v; // init_shaders, draw
GLuint p; // init_shaders, draw GLuint p; // init_shaders, draw
GLuint line_indices_nb; // init_buffers, draw, compute_space, arrow_2D, 3D // GLuint line_indices_nb; // now : graphics.c > int buffer_lines_ndx
GLuint plan_indices_nb; // init_buffers, draw, compute_space, arrow_2D, 3D // GLuint plan_indices_nb; // now : graphics.c > int buffer_plans_ndx
}; };
/* /*

View File

@ -1,44 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <GL/glu.h>
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);
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);

View File

@ -1,103 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
/* -------------------------------------------------------------------------- */
// v5----- v4
// /| /|
// v1------v0|
// | | | |
// | |v6---|-|v7
// |/ |/
// v2------v3
//
// static GLfloat vertex_base[] = {
// 0.5, 0.5, 0.5, // v0
// -0.5, 0.5, 0.5, // v1
// -0.5,-0.5, 0.5, // v2
// 0.5,-0.5, 0.5, // v3
// 0.5, 0.5,-0.5, // v4
// -0.5, 0.5,-0.5, // v5
// -0.5,-0.5,-0.5, // v6
// 0.5,-0.5,-0.5, // v7
// };
static GLfloat vertex_base_ignore[] = {
0.5, .0f, .0f, // v0
-0.5, .0f, .0f, // v1
-0.5,-0.5, .0f, // v2
0.5,-0.5, .0f, // v3
0.5, .0f,-.0f, // v4
-0.5, .0f,-.0f, // v5
-0.5,-0.5,-.0f, // v6
0.5,-0.5,-.0f, // v7
};
static GLubyte indices_ignore[] = {
0,1,
1,2,
2,3,
3,0,
4,5,
5,6,
6,7,
7,4,
0,4,
1,5,
2,6,
3,7,
// 2,4,
// 3,5,
// 0,6,
// 1,7,
};
// v5------v4
// /| /|
// v1------v0|
// | | | |
// | v6----|-v7
// |/ |/
// v2------v3
//
static GLfloat color_base[] = {
0.8, 0.8, 0.8, // blanc
0.8, 0.8, 0.2, // jaune
0.8, 0.2, 0.2, // rouge
0.2, 0.2, 0.2, // noir
0.2, 0.2, 0.2, // gris
0.2, 0.8, 0.8, // cyan
0.2, 0.8, 0.2, // vert
0.8, 0.2, 0.8, // magenta
};
/* -------------------------------------------------------------------------- */

View File

@ -1,32 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <GL/glu.h>
bool compute_space_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx,
bool pref_mark_unit_space_zero, int dgap);

View File

@ -1,32 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <GL/glu.h>
bool compute_space_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx,
bool pref_mark_unit_space_zero, int dgap);

View File

@ -1,71 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <epoxy/gl.h>
//#include <GL/glu.h>
bool compute_arrow_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx,
int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z){
float zero = 0.0f;
float center = (1.0f / state_size) * (2 * x - state_size + 2);
// float tip = center + (2 * site - 1) * (1.0f / state_size);
float base = center + (2 * site - 1) * (0.1f / state_size);
*(vertex_base + vgap + 0) = center + (2 * site - 1) * (1.0f / state_size - 0.01f);
*(vertex_base + vgap + 1) = zero;
*(vertex_base + vgap + 2) = zero;
*(vertex_base + vgap + 3) = base;
*(vertex_base + vgap + 4) = 0.4f / state_size;
*(vertex_base + vgap + 5) = zero;
*(vertex_base + vgap + 6) = base;
*(vertex_base + vgap + 7) = - 0.4f / state_size;
*(vertex_base + vgap + 8) = zero;
*(line_ndx + igap + 0) = vgap / 3 + 0;
*(line_ndx + igap + 1) = vgap / 3 + 1;
*(line_ndx + igap + 2) = vgap / 3 + 0;
*(line_ndx + igap + 3) = vgap / 3 + 2;
*(line_ndx + igap + 4) = vgap / 3 + 1;
*(line_ndx + igap + 5) = vgap / 3 + 2;
*(plan_ndx + 0) = vgap / 3 + 0;
*(plan_ndx + 1) = vgap / 3 + 1;
*(plan_ndx + 2) = vgap / 3 + 2;
*(plan_ndx + 3) = vgap / 3 + 0;
*(plan_ndx + 4) = vgap / 3 + 1;
*(plan_ndx + 5) = vgap / 3 + 2;
return 1;
}

View File

@ -1,104 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <epoxy/gl.h>
//#include <GL/glu.h>
#include <stdio.h>
#define A 0
bool compute_arrow_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx, GLubyte *plan_ndx,
int vgap, int igap, int cgap,
int weight, int site, int x, int y, int z){
float zero = 0.0f;
float center = (1.0f / state_size) * (2 * x - state_size + 2);
float tip = center + (2 * site - 1) * (1.0f / state_size);
float base = center + (2 * site - 1) * (0.1f / state_size);
if (A) printf("compute_arrow_3D vgap = %d\n", vgap);
*(vertex_base + vgap + 0) = center + (2 * site - 1) * (1.0f / state_size - 0.01f);
*(vertex_base + vgap + 1) = zero;
*(vertex_base + vgap + 2) = zero;
*(vertex_base + vgap + 3) = base;
*(vertex_base + vgap + 4) = 0.4f / state_size;
*(vertex_base + vgap + 5) = 0.4f / state_size;
*(vertex_base + vgap + 6) = base;
*(vertex_base + vgap + 7) = 0.4f / state_size;
*(vertex_base + vgap + 8) = - 0.4f / state_size;
*(vertex_base + vgap + 9) = base;
*(vertex_base + vgap + 10) = - 0.4f / state_size;
*(vertex_base + vgap + 11) = - 0.4f / state_size;
*(vertex_base + vgap + 12) = base;
*(vertex_base + vgap + 13) = - 0.4f / state_size;
*(vertex_base + vgap + 14) = 0.4f / state_size;
if (A) printf("x = %d site = %d center = %f tip = %f base = %f\n",\
x, site, center, tip, base); // vgap=%d igap=%d
*(line_ndx + igap + 0) = vgap / 3 + 0;
*(line_ndx + igap + 1) = vgap / 3 + 1;
*(line_ndx + igap + 2) = vgap / 3 + 0;
*(line_ndx + igap + 3) = vgap / 3 + 2;
*(line_ndx + igap + 4) = vgap / 3 + 0;
*(line_ndx + igap + 5) = vgap / 3 + 3;
*(line_ndx + igap + 6) = vgap / 3 + 0;
*(line_ndx + igap + 7) = vgap / 3 + 4;
*(line_ndx + igap + 8) = vgap / 3 + 1;
*(line_ndx + igap + 9) = vgap / 3 + 2;
*(line_ndx + igap + 10) = vgap / 3 + 2;
*(line_ndx + igap + 11) = vgap / 3 + 3;
*(line_ndx + igap + 12) = vgap / 3 + 3;
*(line_ndx + igap + 13) = vgap / 3 + 4;
*(line_ndx + igap + 14) = vgap / 3 + 4;
*(line_ndx + igap + 15) = vgap / 3 + 1;
*(plan_ndx + 0) = vgap / 3 + 0;
*(plan_ndx + 1) = vgap / 3 + 1;
*(plan_ndx + 2) = vgap / 3 + 2;
*(plan_ndx + 3) = vgap / 3 + 0;
*(plan_ndx + 4) = vgap / 3 + 1;
*(plan_ndx + 5) = vgap / 3 + 2;
return 1;
}

607
src/graphics/buffers.c Normal file
View File

@ -0,0 +1,607 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
//#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <glib-2.0/glib.h>
#include <math.h>
#include <errno.h>
#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;
static bool grids_intersections (long x, long y, long z,
GLfloat *vertex_origin, GLfloat *colors_origin)
{
float i, j, k, vx, vy, vz, max = fmax(x, y);
max = fmax(max, z);
for (i = 0; i <= x; i++)
for (j = 0; j <= y; j++)
for (k = 0; k <= z; k++){
vx = (2 * i / x - 1) * x / max;
vy = (2 * j / y - 1) * y / max;
vz = (2 * k / z - 1) * z / max;
*(vertex_origin + vertex_index + 0) = vx;
*(vertex_origin + vertex_index + 1) = vy;
*(vertex_origin + vertex_index + 2) = vz;
vertex_index += 3;
*(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;
colors_index += 3;
};
return 1;
}
static bool arrows_anchors (long x, long y, long z,
GLfloat *vertex_origin, GLfloat *colors_origin)
{
/* beaucoup de ^c ^v ici (peu d'info) (mais un peu)
X - X = EAST - WEST = rouge - cyan
Y - Y = ZENITH - NADIR = vert - magenta
Z - Z = NORTH - SOUTH = bleu - jaune
*/
float max = fmax(x, y);
max = fmax(max, z);
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 (0) printf("arrows_anchors 1 / max = %5.2f max / 2 = %5.2f\n", ad, max / 2);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
for (k = 0; k < z; k++){
vx = (2 * i / x - 1) * x / max + ad;
vy = (2 * j / y - 1) * y / max + ad;
vz = (2 * k / z - 1) * z / max + ad;
// X - X axis Central Star
*(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));
}
}
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);
}
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 void diagonal_test(long x, long y, long z,
long step_x, long step_y, long step_z,
GLuint *lines_origin)
{
draw_line (lines_origin, 0, step_z * z + step_y * y + step_x * x);
}
static void draw_an_arrow_East_or_West (GLuint *lines_origin, long s, int weight, int site)
{
draw_line (lines_origin, s + 2, s + 6 + site % 2);
draw_line (lines_origin, s + 3, s + 6 + site % 2);
draw_line (lines_origin, s + 4, s + 6 + site % 2);
draw_line (lines_origin, s + 5, s + 6 + site % 2);
}
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);
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_mark_unit_space,
// int pref_style_lines_planes,
// int pref_style_mix_colors,
int pref_show_grid)
{
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++)
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));
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");
printf("NB The same is true if you play : 'draw_some_arrows(...)',\
and modify the number of arrows described above the line 570.\n");
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");
}
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

View File

@ -36,24 +36,43 @@
#include <math.h> #include <math.h>
#include <errno.h> #include <errno.h>
#include "../../include/base.h" //#include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
#include "../../include/graphics_control.h" #include "../../include/graphics.h"
#include "../../include/space_2D.h" #include "../../include/buffers.h"
#include "../../include/space_3D.h"
#include "../../include/arrow_2D.h"
#include "../../include/arrow_3D.h"
#define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define VERTEX_SHADER_FILE "src/shaders/shader.vert"
#define FRAG_SHADER_FILE "src/shaders/shader.frag" #define FRAG_SHADER_FILE "src/shaders/shader.frag"
#define K 0
GLfloat *vertex_base = NULL; /* ----------------- V A R I A B L E S G L O B A L E S ------------------ */
GLfloat *color_base = NULL;
GLubyte *line_ndx = NULL;
GLubyte *plan_ndx = NULL;
/* -------------------------------------------------------------------------- */ // int model_dim; < INUTILE : dim est fonction de model_space_size_x, y ,z) */
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;
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_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;
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;
/* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */
/* /*
* Prints verbose human-readable debug messages * Prints verbose human-readable debug messages
@ -261,10 +280,10 @@ bool graphics_shutdown(const void *gl_area)
(gl_area_size()) (gl_area_size())
* sizeof(struct gl_area_entry *)); * sizeof(struct gl_area_entry *));
g_free(vertex_base); g_free(buffer_vertex_origin);
g_free(color_base); g_free(buffer_colors_origin);
g_free(line_ndx); g_free(buffer_lines_origin);
g_free(plan_ndx); g_free(buffer_plans_origin);
return true; return true;
} }
@ -408,6 +427,7 @@ bool graphics_init_shaders(const void *gl_area)
return false; return false;
vertex = create_shader(GL_VERTEX_SHADER, vertex_shader); 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) { if(vertex == 0) {
entry->program = 0; entry->program = 0;
g_free(vertex_shader); g_free(vertex_shader);
@ -484,68 +504,178 @@ bool graphics_init_shaders(const void *gl_area)
return true; return true;
} }
/* -------------------------------------------------------------------------- */
int dim = 0;
int state_size = 0;
int vertex_nb = 0;
int colors_nb = 0;
int lines_nb = 0;
int plans_nb = 0;
int arrows_nb = 0;
bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D
bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D
bool pref_mark_unit_space_zero = 0; // default == 0 == no mark
/* -------------------------------------------------------------------------- */
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)
// { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 };
dim = 1;
state_size = 9; // 2 < state_size < 32 model_space_size_x = 4; // 0 < model_space_size_x
arrows_nb = 4; // assert : leur emplacement doit être fonction de state_size model_space_size_y = 3; // 0 < model_space_size_y
pref_3D_xor_2D_space = 0; // default == 0 == 3D model_space_size_z = 3; // 0 < model_space_size_z
pref_3D_xor_2D_arrows = 1; // default == 0 == 3D
pref_mark_unit_space_zero = 1; // default == 0 == no mark // 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
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;
} }
static void compute_vertex_colors_lines_plans_nb(int dim, GLuint arrows[] = {
int state_size, 1, 0, 0, 0, 0,
int arrows_nb, 1, 1, 1, 0, 0,
bool pref_3D_xor_2D_space, 1, 2, 2, 1, 1,
bool pref_3D_xor_2D_arrows, 1, 3, 2, 2, 1,
bool pref_mark_unit_space_zero, 1, 4, 3, 0, 1,
struct gl_area_entry *entry){ 1, 5, 3, 0, 2,
if (pref_3D_xor_2D_space) vertex_nb = (state_size + 1) * 6 + arrows_nb * 9; // case 2D 1, 1, 3, 0, 2,
else vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; // case 3D 1, 0, 2, 0, 2,
1, 5, 2, 1, 1,
// load, site, x, y, z
};
if (pref_3D_xor_2D_space) lines_nb = (2 + state_size) + (arrows_nb * 3); // case 2D
else lines_nb = (4 + state_size * 4) + (arrows_nb * 8); // case 3D
if (pref_mark_unit_space_zero) lines_nb += 2; // 2 diagonal lines
//
plans_nb = 8; // (4 + state_size * 4) + (arrows_nb * 8) + 2;
entry->line_indices_nb = lines_nb * 2;
entry->plan_indices_nb = plans_nb * 3;
colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO
assert(state_size * 6 < vertex_nb); assert(state_size * 6 + 5 < vertex_nb);
printf("Prefer : mark_unit_space_zero = %d pref_3D_xor_2D_space = %d state_size = %d\n",
pref_mark_unit_space_zero, pref_3D_xor_2D_space, state_size);
printf("Initialization of buffers with %u line_ndx, %u vertices and %u colors & state_size = %d\n", static void compute_buffers_sizes(int model_space_size_x,
entry->line_indices_nb, vertex_nb, colors_nb, state_size); int model_space_size_y,
int model_space_size_z,
int model_arrows_nb,
// int pref_mark_unit_space,
// int pref_style_lines_planes,
// int pref_style_mix_colors,
int pref_test_diagonal)
{
// XXX ONLY space and no arrows
long grids_intersections = (model_space_size_x + 1)
* (model_space_size_y + 1)
* (model_space_size_z + 1);
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
long cubes_nb = model_space_size_x * model_space_size_y * model_space_size_z;
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;
buffer_vertex_size += 8 * 3; // draw a small cube
buffer_colors_size = buffer_vertex_size;
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 /* 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 : buffer_lines_origin[] is no more defined in graphics_cube.h
* @return void * @return void
*/ */
#define A 0 #define A 0
@ -555,70 +685,54 @@ void graphics_init_buffers(const void *gl_area)
entry = find_entry_from_ptr(gl_area); entry = find_entry_from_ptr(gl_area);
get_model_data_and_user_preferences(); get_model_data_and_user_preferences();
compute_vertex_colors_lines_plans_nb(dim, state_size, arrows_nb, /* une struct en retour pour ne plus utiliser de variables globales ? */
pref_3D_xor_2D_space,
pref_3D_xor_2D_arrows,
pref_mark_unit_space_zero,
entry);
// g_malloc compute_buffers_sizes (model_space_size_x,
vertex_base = g_malloc0(vertex_nb * sizeof(GLfloat) * 2); model_space_size_y,
color_base = g_malloc0(colors_nb * sizeof(GLfloat) * 2); model_space_size_z,
line_ndx = g_malloc0(lines_nb * 2 * sizeof(GLubyte) * 2);
plan_ndx = g_malloc0(plans_nb * 3 * sizeof(GLubyte) * 2);
model_arrows_nb,
int vgap = 0, igap = 0, cgap = 0, dgap = 0; // pref_mark_unit_space,
// pref_style_lines_planes,
// pref_style_mix_colors,
pref_test_diagonal);
if (pref_mark_unit_space_zero) dgap = 4; // 4 vertices for 2 diagonal lines buffer_vertex_origin = g_malloc0(buffer_vertex_size * sizeof(GLfloat) * 2);
vgap += (6 * state_size); buffer_colors_origin = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2);
igap += state_size * 2 + dgap; buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLuint) * 2);
cgap += (6 * state_size); buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLuint) * 2);
if (pref_3D_xor_2D_space) compute_space_2D(state_size, compute_space_and_arrows (model_space_size_x,
vertex_base, color_base, model_space_size_y,
line_ndx, model_space_size_z,
pref_mark_unit_space_zero, dgap);
else compute_space_3D(state_size, arrows,
vertex_base, color_base, model_arrows_nb,
line_ndx,
pref_mark_unit_space_zero, dgap);
for (int k = 0; k < state_size; k++){ // pref_mark_unit_space,
assert(k * 12 < vertex_nb); assert(k * 12 + 11 < vertex_nb); // pref_style_lines_planes,
assert(k * 12 < colors_nb); assert(k * 12 + 11 < colors_nb); // pref_style_mix_colors,
assert(k + 8 < entry->line_indices_nb); assert(k + 16 < entry->line_indices_nb); pref_show_grid,
} pref_test_diagonal,
assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); buffer_vertex_origin,
assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); buffer_colors_origin,
buffer_lines_origin,
buffer_plans_origin);
/* compute_arrow_3D(state_size, */
/* vertex_base, color_base, */
/* line_ndx, plan_ndx, */
/* vgap, igap, cgap, */
/* 1, 0, 0, 0, 0); */
/* vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
/* compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
/* compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
/* compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
/* compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, state_size - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
/* compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, state_size - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; */
GLuint vao, vertex_buffer, color_buffer; GLuint vao, vertex_buffer, color_buffer;
glGenBuffers(1, &vertex_buffer); glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, vertex_nb * sizeof(vertex_base[0]), vertex_base, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, buffer_vertex_size * sizeof(buffer_vertex_origin[0]), buffer_vertex_origin, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
// colors // colors
glGenBuffers(1, &color_buffer); glGenBuffers(1, &color_buffer);
glBindBuffer(GL_ARRAY_BUFFER, color_buffer); glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
glBufferData(GL_ARRAY_BUFFER, colors_nb * sizeof(color_base), color_base, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin), buffer_colors_origin, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
// We only use one VAO, so we always keep it bound // We only use one VAO, so we always keep it bound
@ -667,7 +781,9 @@ void graphics_draw(const void *gl_area)
/* Use our shaders */ /* Use our shaders */
glUseProgram(entry->program); glUseProgram(entry->program);
glClearColor(0, 0, 0, 0.2f); // glClearColor(0.3f, 0, 0, 0.8f); // if (pref_style_mix_colors == 0)
glClearColor(0, 0, 0, 0.4f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Update the "mvp" matrix we use in the shader */ /* Update the "mvp" matrix we use in the shader */
@ -685,10 +801,10 @@ void graphics_draw(const void *gl_area)
glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer); glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0);
glEnable(GL_DEPTH_TEST); //glEnable(GL_DEPTH_TEST);
glDrawElements(GL_LINES, entry->line_indices_nb, GL_UNSIGNED_BYTE, line_ndx); glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_INT, buffer_lines_origin);
glDrawElements(GL_TRIANGLES, entry->plan_indices_nb, GL_UNSIGNED_BYTE, plan_ndx); glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_INT, buffer_plans_origin);
/* We finished using the buffers and program */ /* We finished using the buffers and program */
glDisableVertexAttribArray(0); glDisableVertexAttribArray(0);
@ -699,3 +815,10 @@ void graphics_draw(const void *gl_area)
glFlush(); glFlush();
} }

View File

@ -1,362 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
//#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <glib-2.0/glib.h>
#include <math.h>
#include <errno.h>
#include "../../include/base.h"
#include "../../include/ui.h"
#include "../../include/graphics_control.h"
#include "../../include/graphics_compute.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) + 2; // + 2; pour les 2 diagonales
//// 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,4); // patch provisoire
// pref_mark_unit_space_zero, dgap){
vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size);
/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */
/* 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,4); // patch provisoire
//pref_mark_unit_space_zero, dgap){
vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size);
/* assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); */
/* 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;
/// }
}
}

View File

@ -0,0 +1,394 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: OpenGL utils header
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
//#pragma once
#include <unistd.h>
#include <stdbool.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <glib-2.0/glib.h>
#include <math.h>
#include <errno.h>
#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); */

View File

@ -1,83 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <epoxy/gl.h>
#define V 1
#define I 0
#define EDGE 0.999999
bool compute_space_2D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx,
bool pref_mark_unit_space_zero, int dgap){
float x = 0;
// for (int k = 0; k < state_size + 1; k++) <=> + 1
// car on passe du nombre de cases = (n)
// au nombre de séparations entre les cases + les deux bords = (n + 1)
if (V) printf("vertices ");
for (int k = 0; k < state_size; k++){ // barres verticales
//
x = ((state_size % 2) * (state_size / 2 - k)
+ (state_size % 2 - 1) * (k + 0.5f - state_size / 2)) / state_size * 2 * EDGE;
if (V) printf("[%1.1f] ", x);
*(vertex_base + k * 6 + 0) = - x;
*(vertex_base + k * 6 + 1) = 1.0f / state_size;
*(vertex_base + k * 6 + 2) = 0.0f;
*(vertex_base + k * 6 + 3) = - x;
*(vertex_base + k * 6 + 4) = - 1.0f / state_size;
*(vertex_base + k * 6 + 5) = 0.0f;
}
if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size);
*(line_ndx + 0) = 0;
*(line_ndx + 1) = state_size * 2 - 2; // barre horizontale du bas
*(line_ndx + 2) = 1;
*(line_ndx + 3) = state_size * 2 - 1; // barre horizontale du haut
for (int k = 0; k < state_size * 2; k++) *(line_ndx + k + 4) = k;
if (I) printf("line_ndx (%d - state_size(0)) x (%d - state_size(1)) ", 0, 1);
for (int v = 0; v < state_size + 2; v++) {
if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1));
}
if (pref_mark_unit_space_zero) { // diagonales pour marquer la case zéro
*(line_ndx + state_size * 2 + 6 + dgap + 0) = 0;
*(line_ndx + state_size * 2 + 6 + dgap + 1) = 3;
*(line_ndx + state_size * 2 + 6 + dgap + 2) = 1;
*(line_ndx + state_size * 2 + 6 + dgap + 3) = 2;
}
if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2);
return 1;
}

View File

@ -1,156 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <epoxy/gl.h>
#define V 1
#define I 1
#define EDGE 0.999999
bool compute_space_3D(int state_size,
GLfloat *vertex_base, GLfloat *color_base,
GLubyte *line_ndx,
bool pref_mark_unit_space_zero, int dgap){
float x = 0;
// for (int k = 0; k < state_size + 1; k++) <=> + 1 car
// on passe du nombre de cases = (n)
// au nombre de séparations entre les cases + les deux bords = (n + 1)
if (V) printf("vertices ");
for (int k = 0; k < state_size; k++){ // barres verticales
//
x = ((state_size % 2) * (state_size / 2 - k)
+ (state_size % 2 - 1) * (k + 0.5f - state_size / 2)) / state_size * 2 * EDGE;
if (V) printf("[%1.1f] ", x);
*(vertex_base + k * 12 + 0) = - x;
*(vertex_base + k * 12 + 1) = 1.0f / state_size;
*(vertex_base + k * 12 + 2) = 1.0f / state_size;
*(vertex_base + k * 12 + 3) = - x;
*(vertex_base + k * 12 + 4) = - 1.0f / state_size;
*(vertex_base + k * 12 + 5) = - 1.0f / state_size;
*(vertex_base + k * 12 + 6) = - x;
*(vertex_base + k * 12 + 7) = 1.0f / state_size;
*(vertex_base + k * 12 + 8) = - 1.0f / state_size;
*(vertex_base + k * 12 + 9) = - x;
*(vertex_base + k * 12 + 10) = - 1.0f / state_size;
*(vertex_base + k * 12 + 11) = 1.0f / state_size;
*(color_base + k * 12 + 0) = 1 - (k / state_size);
*(color_base + k * 12 + 1) = 0.2f;
*(color_base + k * 12 + 2) = (k / state_size);
*(color_base + k * 12 + 3) = 0.8f;
*(color_base + k * 12 + 4) = 0.8f;
*(color_base + k * 12 + 5) = 0.2f;
*(color_base + k * 12 + 6) = 0.8f;
*(color_base + k * 12 + 7) = (k / state_size);
*(color_base + k * 12 + 8) = 0.2f;
*(color_base + k * 12 + 9) = 1 - (k / state_size);
*(color_base + k * 12 + 10) = 0.2f;
*(color_base + k * 12 + 11) = 0.9f;
// if (k == 0) for (int j = 0; j < 12; j++) *(color_base + j) = 0.2f;
/* 0.8, 0.8, 0.8, // blanc */
/* 0.8, 0.8, 0.2, // jaune */
/* 0.8, 0.2, 0.2, // rouge */
/* 0.2, 0.2, 0.2, // noir */
/* 0.2, 0.2, 0.2, // gris */
/* 0.2, 0.8, 0.8, // cyan */
/* 0.2, 0.8, 0.2, // vert */
/* 0.8, 0.2, 0.8, // magenta */
}
if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size);
*(line_ndx + 4) = 0;
*(line_ndx + 5) = state_size * 4 - 4; // barre horizontale du bas arr
*(line_ndx + 6) = 1;
*(line_ndx + 7) = state_size * 4 - 3; // barre horizontale du haut arr
*(line_ndx + 0) = 2;
*(line_ndx + 1) = state_size * 4 - 2; // barre horizontale du bas av
*(line_ndx + 2) = 3;
*(line_ndx + 3) = state_size * 4 - 1; // barre horizontale du haut av
/* *(plan_ndx + 0) = 0; */
/* *(plan_ndx + 1) = 1; */
/* *(plan_ndx + 2) = 2; */
/* *(plan_ndx + 3) = 0; */
/* *(plan_ndx + 4) = 1; */
/* *(plan_ndx + 5) = 3; */
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_ndx + k + 1) = k / 2 - 2; // + 2;
*(line_ndx + k + 2) = k / 2 - 3; // + 1;
*(line_ndx + k + 3) = k / 2 - 1; // + 3;
*(line_ndx + k + 4) = k / 2 - 4; // + 0;
*(line_ndx + k + 5) = k / 2 - 1; // + 3;
*(line_ndx + k + 6) = k / 2 - 3; // + 1;
*(line_ndx + k + 7) = k / 2 - 2; // + 2;
}
if (pref_mark_unit_space_zero) {
*(line_ndx + (2 + state_size) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro
*(line_ndx + (2 + state_size) * 8 - 3) = 0 + 1;
*(line_ndx + (2 + state_size) * 8 - 2) = 0 + 2; // diagonales pour marquer la case zéro
*(line_ndx + (2 + state_size) * 8 - 1) = 0 + 3;
}
if (I) printf("line_ndx ");
for (int v = 0; v < state_size + 2; v++) {
if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1));
}
if (I) printf(" n = 4 + (%d x 2) dgap = %d\n", state_size + 2, dgap);
if (I) printf("pref_mark_unit_space_zero = %d ", pref_mark_unit_space_zero);
return 1;
}

View File

@ -11,6 +11,8 @@ out vec4 color;
void main(void) void main(void)
{ {
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_position, 1); float zoom = 1.5f, chrominance = 1, luminance = 1;
color = vec4(1 * in_color.rgb, 0.2f); gl_Position =
projection_matrix * view_matrix * model_matrix * vec4(in_position, zoom);
color = vec4 (chrominance * in_color.rgb, luminance);
} }

View File

@ -25,7 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/graphics_control.h" #include "../../include/graphics.h"
#include "../../include/ui.h" #include "../../include/ui.h"