From 4d5aa2c993a5c06f561f9cc56bf44babe3cd82f2 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 15 Jun 2023 21:29:15 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20Bon.=20C'est=20blind=C3=A9=20d'erreurs?= =?UTF-8?q?=20mais=20=C3=A7a=20le=20fait=20en=203D=20+=201=20p'tite=20fl?= =?UTF-8?q?=C3=A8che.=20=20A=20nettoyer=20++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/arrow_2D.h | 1 + include/arrow_3D.h | 34 ++++++ include/space_2D.h | 3 +- include/space_3D.h | 5 + src/graphics/arrow_2D.c | 4 + src/graphics/arrow_3D.c | 104 ++++++++++++++++ src/graphics/graphics_control.c | 207 ++------------------------------ 7 files changed, 161 insertions(+), 197 deletions(-) create mode 100644 include/arrow_3D.h create mode 100644 src/graphics/arrow_3D.c diff --git a/include/arrow_2D.h b/include/arrow_2D.h index 1368a0e..f11b606 100644 --- a/include/arrow_2D.h +++ b/include/arrow_2D.h @@ -31,3 +31,4 @@ bool compute_arrow_2D(int state_size, GLubyte *line_ndx, GLubyte *plan_ndx, int vgap, int igap, int cgap, int weight, int site, int x, int y, int z); + diff --git a/include/arrow_3D.h b/include/arrow_3D.h new file mode 100644 index 0000000..dafed7b --- /dev/null +++ b/include/arrow_3D.h @@ -0,0 +1,34 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: OpenGL utils header + * + * Copyright (C) 2023 Jean Sirmai + * + * 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 + +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); + diff --git a/include/space_2D.h b/include/space_2D.h index 17ba2ea..f6ae70c 100644 --- a/include/space_2D.h +++ b/include/space_2D.h @@ -26,4 +26,5 @@ #include #include -bool compute_space_2D(int state_size, GLfloat *vertex_base, GLubyte *line_ndx); +bool compute_space_2D(int state_size, + GLfloat *vertex_base, GLubyte *line_ndx); diff --git a/include/space_3D.h b/include/space_3D.h index 7a37f62..5be5ab6 100644 --- a/include/space_3D.h +++ b/include/space_3D.h @@ -21,6 +21,11 @@ * along with this program. If not, see . */ +#pragma once +#include +#include +#include + bool compute_space_3D(int state_size, GLfloat *vertex_base, GLfloat *color_base, GLubyte *line_ndx, int ad_hoc_diag); diff --git a/src/graphics/arrow_2D.c b/src/graphics/arrow_2D.c index 03e50f1..9376b79 100644 --- a/src/graphics/arrow_2D.c +++ b/src/graphics/arrow_2D.c @@ -21,7 +21,11 @@ * along with this program. If not, see . */ +#pragma once +#include +#include #include +//#include bool compute_arrow_2D(int state_size, GLfloat *vertex_base, GLfloat *color_base, diff --git a/src/graphics/arrow_3D.c b/src/graphics/arrow_3D.c new file mode 100644 index 0000000..3b41c22 --- /dev/null +++ b/src/graphics/arrow_3D.c @@ -0,0 +1,104 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: GL functions + * + * Copyright (C) 2023 Jean Sirmai + * + * 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 + +#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; +} + + diff --git a/src/graphics/graphics_control.c b/src/graphics/graphics_control.c index 0e4ccdf..e0e3d08 100644 --- a/src/graphics/graphics_control.c +++ b/src/graphics/graphics_control.c @@ -42,6 +42,7 @@ #include "../../include/space_2D.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 FRAG_SHADER_FILE "src/shaders/shader.frag" @@ -547,201 +548,6 @@ bool graphics_init_shaders(const void *gl_area) return true; } - -#define A 0 -static bool compute_arrow_3D(struct gl_area_entry *entry, int state_size, int vgap, int igap, 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); - - printf("compute_arrow_3D vgap = %d vertex_nb = %d\n", vgap, vertex_nb); - - assert(vgap < vertex_nb); - assert(vgap + 9 < vertex_nb); - - *(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 - - assert(igap < entry->line_indices_nb); - assert(igap + 5 < entry->line_indices_nb); - - *(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; - - return 1; -} - -/* #define V 1 */ -/* #define I 0 */ -/* #define EDGE 0.999999 */ - -/* static bool compute_space_3D(struct gl_area_entry *entry, int state_size){ */ - -/* 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); */ - -/* assert(k * 12 < vertex_nb); */ -/* assert(k * 12 + 11 < vertex_nb); */ -/* assert(k * 12 < colors_nb); */ -/* assert(k * 12 + 11 < colors_nb); */ - -/* *(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) = 0.8f; */ -/* *(color_base + k * 12 + 1) = 0.8f; */ -/* *(color_base + k * 12 + 2) = 0.8f; */ - -/* *(color_base + k * 12 + 3) = 0.8f; */ -/* *(color_base + k * 12 + 4) = 0.8f; */ -/* *(color_base + k * 12 + 5) = 0.8f; */ - -/* *(color_base + k * 12 + 6) = 0.8f; */ -/* *(color_base + k * 12 + 7) = 0.8f; */ -/* *(color_base + k * 12 + 8) = 0.8f; */ - -/* *(color_base + k * 12 + 9) = 0.8f; */ -/* *(color_base + k * 12 + 10) = 0.8f; */ -/* *(color_base + k * 12 + 11) = 0.8f; */ - -/* 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){ */ - - -/* assert(k < entry->line_indices_nb); */ -/* assert(k + 8 < entry->line_indices_nb); */ - -/* *(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; */ -/* } */ - - -/* *(line_ndx + entry->line_indices_nb - 4) = 0 + 0; // diagonales pour marquer la case zéro */ -/* *(line_ndx + entry->line_indices_nb - 3) = 0 + 1; */ - -/* *(line_ndx + entry->line_indices_nb - 2) = 0 + 2; // diagonales pour marquer la case zéro */ -/* *(line_ndx + entry->line_indices_nb - 1) = 0 + 3; */ - - -/* 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 (I) printf(" n = 4 + (%d x 2)\n", state_size + 2); */ - -/* return 1; */ -/* } */ - /* Initializes the buffer of a gl_area * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget @@ -826,7 +632,16 @@ void graphics_init_buffers(const void *gl_area) /* line_ndx, plan_ndx, vgap, igap, cgap, 1, 1, state_size - 2, 0, 0); */ /* vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ - /* compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, 0, 0, 0); vgap += 15; igap += 16; 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_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; */