WIP: Bon. C'est blindé d'erreurs mais ça le fait en 3D + 1 p'tite flèche. A nettoyer ++

This commit is contained in:
Jean Sirmai 2023-06-15 21:29:15 +02:00
parent e9d45b3e88
commit 4d5aa2c993
Signed by: jean
GPG Key ID: FB3115C340E057E3
7 changed files with 161 additions and 197 deletions

View File

@ -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);

34
include/arrow_3D.h Normal file
View File

@ -0,0 +1,34 @@
/*
* 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,4 +26,5 @@
#include <stdbool.h>
#include <GL/glu.h>
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);

View File

@ -21,6 +21,11 @@
* 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, int ad_hoc_diag);

View File

@ -21,7 +21,11 @@
* 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,

104
src/graphics/arrow_3D.c Normal file
View File

@ -0,0 +1,104 @@
/*
* 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;
}

View File

@ -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; */