src/graphics/*: Reworked modularity, buffer allocation and reallocation of lines buffer

Acked-by: Adrien 'neox' Bourmault <neox@a-lec.org>
This commit is contained in:
Jean Sirmai 2023-09-05 15:00:48 +02:00 committed by Adrien 'neox' Bourmault
parent bdad3857a9
commit 7f010b87c7
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
8 changed files with 925 additions and 197 deletions

View File

@ -0,0 +1,143 @@
static GLuint *buffer_lines_origin = NULL;
---
long get_buffer_lines_size() {return buffer_lines_size / 2;}
void inc_buffer_lines_size(long inc) {buffer_lines_size += inc * 2;}
void dec_buffer_lines_size(long dec) {buffer_lines_size -= dec * 2;}
void xxx_draw_line (GLuint *lines_origin, int a, int b, long lines_index)
{
// https://docs.gtk.org/glib/func.realloc.html
printf("xxx_draw_line %ld\n", lines_index);
buffer_lines_origin = g_realloc(lines_origin, sizeof(GLuint) * 2);
*(lines_origin + lines_index + 0) = a; // lines_index ++;
*(lines_origin + lines_index + 1) = b; // lines_index ++;
}
/* (gdb) help
List of classes of commands:
aliases -- User-defined aliases of other commands.
breakpoints -- Making program stop at certain points.
data -- Examining data.
files -- Specifying and examining files.
internals -- Maintenance commands.
obscure -- Obscure features.
running -- Running the program.
stack -- Examining the stack.
status -- Status inquiries.
support -- Support facilities.
text-user-interface -- TUI is the GDB text based interface.
tracepoints -- Tracing of program execution without stopping the program.
user-defined -- User-defined commands.
*/
-------------------------------------------------------------------------------------------
GLuint arrows[] = {
1, 0, 0, 0, 0,
/* 1, 1, 1, 0, 0, */
/* 1, 2, 2, 1, 1, */
/* 1, 3, 2, 2, 1, */
/* 1, 4, 3, 0, 1, */
/* 1, 5, 3, 0, 2, */
/* 1, 1, 3, 0, 2, */
/* 1, 0, 2, 0, 2, */
/* 1, 5, 2, 1, 1, */
// load, site, x, y, z
};
static void get_model_data_and_user_preferences(){
model_space_size_x = 1; // 0 < model_space_size_x
model_space_size_y = 1; // 0 < model_space_size_y
model_space_size_z = 1; // 0 < model_space_size_z
// XXX ONLY space drawed, no arrows yet
model_arrows_nb = sizeof(arrows); // assert : l'emplacement des flèches est contraint
// par model_space_size_x, y, z et le nombre de sites
central_stars_nb = 0; // à calculer TODO
// ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites)
central_stars_nb = 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 = 1;
}
-------------------------------------------------------------------------------------------
in buffers.c (line 283)
static void draw_line (GLuint *lines_origin, int a, int b)
{
xxx_draw_line (lines_origin, a, b, lines_index);
lines_index += 2;
// *(lines_origin + lines_index) = a; lines_index ++;
// *(lines_origin + lines_index) = b; lines_index ++;
}
---------------------------------------------------------------------------
[ n] load site x y z ---- < arrows array > ------------------------------------------------------------
[ 0] = 1, 0, 0, 0, 0
[ 1] = 0, 0, 0, 217808480, 32708
[ 2] = 217809344, 32708, 217807968, 32708, 217810080
[ 3] = 32708, -69297984, 32707, 229965808, 32708
[ 4] = 229944176, 32708, 217808608, 32708, 229970384
[ 5] = 32708, 217808576, 32708, 217809024, 32708
[ 6] = 217808992, 32708, -69297888, 32707, 229954976
[ 7] = 32708, 217808512, 32708, 229949456, 32708
[ 8] = 229942736, 32708, 0, 0, 0
[ 9] = 0, 0, 0, 226977440, 32708
[10] = 217810048, 32708, 217808352, 32708, 217808704
[11] = 32708, -69297600, 32707, 217808448, 32708
[12] = 217807808, 32708, 217808896, 32708, 217809312
[13] = 32708, 217807872, 32708, 225561296, 32708
[14] = 217814880, 32708, 217814944, 32708, 217807776
[15] = 32708, 229974752, 32708, 217811040, 32708
[16] = 229947200, 32708, 0, 0, 33506144
[17] = 0, 0, 0, 0, 0
[18] = 33204048, 0, 0, 0, 33587952
[19] = 0, 30217696, 0, 30245088, 0
[ n] load site x y z ---- < arrows array > ------------------------------------------------------------
[ 0] = 1, 0, 0, 0, 0
[ 1] = 0, 0, 0, 2105314912, 32683
[ 2] = 2105315776, 32683, 2105314400, 32683, 2105316512
[ 3] = 32683, 2019551424, 32683, 2117545968, 32683
[ 4] = 2117524336, 32683, 2105315040, 32683, 2117550544
[ 5] = 32683, 2105315008, 32683, 2105315456, 32683
[ 6] = 2105315424, 32683, 2019551520, 32683, 2117535136
[ 7] = 32683, 2105314944, 32683, 2117529616, 32683
[ 8] = 2117522896, 32683, 0, 0, 0
[ 9] = 0, 0, 0, 2114557600, 32683
[10] = 2105316480, 32683, 2105314784, 32683, 2105315136
[11] = 32683, 2019551808, 32683, 2105314880, 32683
[12] = 2105314240, 32683, 2105315328, 32683, 2105315744
[13] = 32683, 2105314304, 32683, 2113141456, 32683
[14] = 2105321312, 32683, 2105321376, 32683, 2105314208
[15] = 32683, 2117554912, 32683, 2105317472, 32683
[16] = 2117527360, 32683, 0, 0, 16032608
[17] = 0, 0, 0, 0, 0
[18] = 15766240, 0, 0, 0, 15950576
[19] = 0, 12654048, 0, 12681440, 0

42
include/arrows.h Normal file
View File

@ -0,0 +1,42 @@
/*
* 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>
void check_arrows_data(int x, int y, int z,
GLuint *arrows, int arrows_nb, int central_stars_nb);
long compute_vertex_nb(int vertex_nb, int x, int y, int z);
long compute_lines_nb(int lines_nb, int arrows_nb, int central_stars_nb);
bool alloc_arrows_vertex (long x, long y, long z,
GLfloat *vertex_origin, GLfloat *colors_origin,
int vertex_index, int colors_index);
bool alloc_arrows_lines (long space_size_x, long space_size_y, long space_size_z,
GLuint *arrows, int arrows_nb);

View File

@ -33,11 +33,7 @@ bool compute_space_and_arrows(long model_space_size_x,
GLuint *arrows, GLuint *arrows,
int model_arrows_nb, 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_show_grid,
int pref_test_diagonal,
GLfloat *vertex_origin, GLfloat *vertex_origin,
GLfloat *color_origin, GLfloat *color_origin,
@ -45,4 +41,7 @@ bool compute_space_and_arrows(long model_space_size_x,
GLuint *plan_origin); GLuint *plan_origin);
long get_buffer_lines_size();
void inc_buffer_lines_size(long inc);
void dec_buffer_lines_size(long dec);

View File

@ -93,3 +93,36 @@ bool graphics_init_shaders(const void *gl_area);
* @return void * @return void
*/ */
void graphics_init_buffers(const void *gl_area); void graphics_init_buffers(const void *gl_area);
/*
* 2023-09-05 Sur la branche dev/graphics2
* >>> Restructuration [state // arrows]
*
* Le calcul du nombre et de la position des vertex et des couleurs
* est fait au début de chaque session de travail en fonction de :
* - x,y,z
* - user preferences
*
* Le premier but de la restructuration est que :
* le calcul des valeurs des vertex départ/arrivée des lignes
* et l'allocation du buffer lignes (! LIGNES ! <> pas vertex)
* soit fait par des realloc(),
* (une realloc à chaque écriture (ou effacement) d'une flèche)
* et non, comme actuellement, en une seule fois lors de l'initialisation
* bdad3857a9ede7f96dac430505c4f3c5da39744f
*
* Cette restructuration sera plus lisible si le code qui décrit les flèches
* est nettement séparé de celui qui décrit l'espace.
*
* Certaines fonctions des actuels fichiers '/graphics' et '/buffers'
* doivent donc être transférées vers deux nouveaux fichiers :
* '/space' et '/arrows'
*
* La fonction draw_line(a,b) sera utilisée pour tracer toutes les lignes
* (qu'elles décrivent l'espace ou les flèches).
* Elle calcule les adresses mémoire des vertex (a) et (b)
* en fonction de leur position dans l'espace
* et réalloue le buffer lines avant d'y écrire :
*/
void draw_line (int a, int b);

61
include/space.h Normal file
View File

@ -0,0 +1,61 @@
/*
* 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>
void check_space_data_and_user_preferences(int x, int y, int z,
int grid, int diagonal);
// void do_alloc_buffers(){}; // ?!? Pourquoi ne dois-je pas déclarer cette fonction ici ?
void compute_buffers_sizes(int model_space_size_x,
int model_space_size_y,
int model_space_size_z,
long central_stars_nb,
long arrows_nb,
int pref_test_diagonal);
long compute_space_vertex_nb(int x, int y, int z);
long compute_space_lines_nb(int x, int y, int z, int pref_show_grid);
// bool alloc_space_vertex (long x, long y, long z,
// GLfloat *vertex_origin, GLfloat *colors_origin,
// int vertex_index, int colors_index);
bool alloc_space_vertex_and_colors (long x, long y, long z);
void draw_a_cube_at(long u, long v, long w,
long size_x, long size_y, long size_z, bool diagonals);
void draw_ridges_3D (long x, long y, long z,
long step_x, long step_y, long step_z);
bool draw_grids_3D (long x, long y, long z,
long step_x, long step_y, long step_z,
int pref_show_grid);
void diagonal_test(long x, long y, long z,
long step_x, long step_y, long step_z);

490
src/graphics/arrows.c Normal file
View File

@ -0,0 +1,490 @@
/*
* 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
* aint 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"
bool alloc_arrows_vertex (long x, long y, long z,
GLfloat *vertex_origin, GLfloat *colors_origin,
int vertex_index, int colors_index)
{
// X - X = EAST - WEST = rouge - cyan
// Y - Y = ZENITH - NADIR = vert - magenta
// Z - Z = SOUTH - NORTH = jaune - bleu
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;
}
void check_arrows_data(int x, int y, int z,
GLuint *arrows, int arrows_nb, int central_stars_nb)
{
// TODO assert : l'emplacement de chaque flèche est contraint
// par model_space_size_x, y, z et le nombre de sites possibles.
// ! WARNING ! Pour l'instant égal au nombre de flèches !
// Les "central stars" sont donc systématiquement redessinées
// s'il y a plusieurs flèches d'orientation différente dans le même cube.
printf("ARROWS x,y,z = (%d,%d,%d) arrows_nb = %d central_stars_nb = %d\n",\
x, y, z, arrows_nb, central_stars_nb);
if (arrows_nb > 0) printf("\n[ n] load site x y z ---- < arrows array >\
------------------------------------------------------------\n");
for (int i = 0; i < 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));
}
long compute_vertex_nb(int vertex_nb, int x, int y, int z)
{
// int vertex_nb = (x + 1) * (y + 1) * (z + 1); <> cf graphics/space.c
int unit_cubes_nb = x * y * z;
vertex_nb += 12 * unit_cubes_nb; // 6 for the central star
// 6 for the unit cubes faces centers
return vertex_nb;
}
long compute_lines_nb(int lines_nb, int arrows_nb, int central_stars_nb)
{
// TODO central_stars_nb sera à calculer pour éviter de redessiner les central_stars
central_stars_nb = arrows_nb; // ! WARNING ! Pour l'instant égal au nombre de flèches !
// Les "central stars" sont donc systématiquement redessinées
// s'il y a plusieurs flèches d'orientation différente dans le même cube.
lines_nb = 3 * 2 * central_stars_nb; // test central stars
lines_nb += 4 * 2 * arrows_nb; // flèches
return lines_nb;
}
#define VERBOSE 0
static bool rewrite_arrow (GLuint *arrows, long arrows_nb, long address, long weight,
long site, long x, long y, long z)
{
if (VERBOSE) printf("write the arrow weight to %ld at (%ld, %ld, %ld, %ld)\n",\
weight, site, x, y, z);
*(arrows + address + 0) = weight;
return 1; /* replaces the load of the existing arrow by the load 'weight' */
}
static bool create_arrow (GLuint *arrows, long arrows_nb, long weight, long site, long x, long y, long z)
{
if (VERBOSE) printf("create a new arrow with weight = %ld at (%ld, %ld, %ld, %ld)\n",\
weight, site, x, y, z);
arrows_nb ++;
inc_buffer_lines_size ((3 + 4) * 2);
set_buffer_lines_origin (g_realloc (get_buffer_lines_origin(), get_buffer_lines_size() * 2 * sizeof(GLuint) * 2));
*(arrows + arrows_nb + 0) = weight;
*(arrows + arrows_nb + 1) = site;
*(arrows + arrows_nb + 2) = x;
*(arrows + arrows_nb + 3) = y;
*(arrows + arrows_nb + 4) = z;
return 1;
}
static bool erase_arrow (GLuint *arrows, long arrows_nb, long address,
long site, long x, long y, long z)
{
if (VERBOSE) printf("erase arrow at address %ld with values (%ld, %ld, %ld, %ld)",\
address / 5, site, x, y, z);
if (VERBOSE) printf(" last arrow is %d, %d, %d, %d, %d\n",
*(arrows + (arrows_nb - 1) * 5 + 0),
*(arrows + (arrows_nb - 1) * 5 + 1),
*(arrows + (arrows_nb - 1) * 5 + 2),
*(arrows + (arrows_nb - 1) * 5 + 3),
*(arrows + (arrows_nb - 1) * 5 + 4));
*(arrows + address + 0) = *(arrows + (arrows_nb - 1) * 5 + 0);
*(arrows + address + 1) = *(arrows + (arrows_nb - 1) * 5 + 1);
*(arrows + address + 2) = *(arrows + (arrows_nb - 1) * 5 + 2);
*(arrows + address + 3) = *(arrows + (arrows_nb - 1) * 5 + 3);
*(arrows + address + 4) = *(arrows + (arrows_nb - 1) * 5 + 4);
arrows_nb --;
dec_buffer_lines_size ((3 + 4) * 2);
set_buffer_lines_origin (g_realloc (get_buffer_lines_origin(), get_buffer_lines_size() * 2 * sizeof(GLuint) * 2));
return 1;
}
static long check_for_arrow (GLuint *arrows, long arrows_nb, long site, long x, long y, long z)
{
if (arrows_nb == 0) return -1;
long address = -1, f_weight = -1, f_site = -1, f_x = -1, f_y = -1, f_z = -1;
for (int i = 0; i < arrows_nb; i++)
{
f_weight = *(arrows + i * 5 + 0);
f_site = *(arrows + i * 5 + 1);
f_x = *(arrows + i * 5 + 2);
f_y = *(arrows + i * 5 + 3);
f_z = *(arrows + i * 5 + 4);
if (f_site == site && f_x == x && f_y == y && f_z == z) {
address = i * 5;
if (VERBOSE) printf("arrows_nb = %ld checked arrow (%ld,%ld,%ld,%ld) found at address %ld (line %ld)",\
arrows_nb, site, x, y, z, address, address / 5);
if (VERBOSE && f_weight > 1) printf(" weight = %ld", f_weight);
if (VERBOSE) printf("\n");
}
}
return address; /* returns the address of the arrow if there is one
* or (-1) if there is none */
}
static void show_arrows_array (GLuint *arrows, long arrows_nb, long address, long weight, long site, long x, long y, long z)
{
printf("\n[ n] load | site x y z ----- < arrows_nb = %ld > ------", arrows_nb);
if (arrows_nb == 0) printf("--------------------------- no arrows\n");
else if (address == -1) printf("--------------------------- create new arrow\n");
else printf("--------------------------- erase arrow at address = %ld / 5\n", address);
for (int i = 0; i < arrows_nb; i++)
{
printf("[%2d] = %2d | %2d, %2d, %2d, %2d ",\
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
if (weight == 0 && i == address / 5) printf(" <<<| < - > (%d, %d, %d, %d) @ [%ld]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight > 0 && i == arrows_nb - 1) printf(" <<< < + > (%d, %d, %d, %d) @ [%ld]",\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
if (weight == 0 && i > address / 5 && i < arrows_nb - 1) printf(" |");
if (weight == 0 && i == arrows_nb - 1 && i != address / 5) printf(" >>>|");
printf("\n");
}
}
static bool set_arrow (GLuint *arrows, long arrows_nb, long weight, long site, long x, long y, long z)
{
long address = (check_for_arrow (arrows, arrows_nb, site, x, y, z));
show_arrows_array(arrows, arrows_nb, address, weight, site, x, y, z);
if (address == -1 && weight == 0) return 0;
if (address == -1 && weight > 0) return create_arrow (arrows, arrows_nb, weight, site, x, y, z);
if (address >= 0 && weight == 0) return erase_arrow (arrows, arrows_nb, address, site, x, y, z);
if (address >= 0 && weight > 0) return rewrite_arrow (arrows, arrows_nb, address, weight, site, x, y, z);
return 0;
}
static void old_draw_line (int a, int b)
{
// *(lines_origin + lines_index) = a; lines_index ++;
// *(get_buffer_lines_origin() + get_buffer_lines_size()) = a; inc_buffer_lines_size(1);
// *(get_buffer_lines_origin() + get_buffer_lines_size()) = b; inc_buffer_lines_size(1);
}
static void draw_an_arrow_East_or_West (long s, int weight, int site)
{
old_draw_line (s + 2, s + 6 + site % 2);
old_draw_line (s + 3, s + 6 + site % 2);
old_draw_line (s + 4, s + 6 + site % 2);
old_draw_line (s + 5, s + 6 + site % 2);
}
static void draw_an_arrow_Zenith_or_Nadir (long s, int weight, int site)
{
old_draw_line (s + 0, s + 8 + site % 2);
old_draw_line (s + 1, s + 8 + site % 2);
old_draw_line (s + 4, s + 8 + site % 2);
old_draw_line (s + 5, s + 8 + site % 2);
}
static void draw_an_arrow_North_or_South (long s, int weight, int site)
{
old_draw_line (s + 0, s + 10 + site % 2);
old_draw_line (s + 1, s + 10 + site % 2);
old_draw_line (s + 2, s + 10 + site % 2);
old_draw_line (s + 3, s + 10 + site % 2);
}
static void draw_a_central_star(long n)
{
old_draw_line (n + 0, n + 1);
old_draw_line (n + 2, n + 3);
old_draw_line (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
bool alloc_arrows_lines (long space_size_x, long space_size_y, long space_size_z,
GLuint *arrows, int arrows_nb)
{
long step_z = 1,
step_y = space_size_z + 1,
step_x = (space_size_z + 1) * (space_size_y + 1);
long s = step_z * space_size_z + step_y * space_size_y
+ step_x * space_size_x;
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);
draw_a_central_star (s + 1 + 12 * (step_x * x + step_y * y + step_z * z));
if (site >-1 && site < 2) draw_an_arrow_East_or_West (s + 1 + 12 * (step_x * x + step_y * y + step_z * z), 1, site);
if (site > 3 && site < 6) draw_an_arrow_North_or_South (s + 1 + 12 * (step_x * x + step_y * y + step_z * z), 1, site);
if (site > 1 && site < 4) draw_an_arrow_Zenith_or_Nadir (s + 1 + 12 * (step_x * x + step_y * y + step_z * z), 1, site);
}
return 1;
}
// X - X = EAST - WEST = rouge - cyan
// Y - Y = ZENITH - NADIR = vert - magenta
// Z - Z = SOUTH - NORTH = jaune - bleu

View File

@ -43,7 +43,12 @@
static long vertex_index = 0; static long vertex_index = 0;
static long colors_index = 0; static long colors_index = 0;
static long lines_index = 0; static long primitive_lines_index = 0;
long get_buffer_lines_size() {return primitive_lines_index / 2;}
void inc_buffer_lines_size(long inc) {primitive_lines_index += inc * 2;}
void dec_buffer_lines_size(long dec) {primitive_lines_index -= dec * 2;}
static long plans_index = 0; static long plans_index = 0;
@ -83,12 +88,10 @@ static bool grids_intersections (long x, long y, long z,
static bool arrows_anchors (long x, long y, long z, static bool arrows_anchors (long x, long y, long z,
GLfloat *vertex_origin, GLfloat *colors_origin) GLfloat *vertex_origin, GLfloat *colors_origin)
{ {
/* beaucoup de ^c ^v ici (peu d'info) (mais un peu) /*
X - X = EAST - WEST = rouge - cyan X - X = EAST - WEST = rouge - cyan
Y - Y = ZENITH - NADIR = vert - magenta Y - Y = ZENITH - NADIR = vert - magenta
Z - Z = NORTH - SOUTH = bleu - jaune Z - Z = NORTH - SOUTH = bleu - jaune
*/ */
float max = fmax(x, y); float max = fmax(x, y);
@ -100,9 +103,6 @@ static bool arrows_anchors (long x, long y, long z,
eps = 0.1 * ad; // eps(ilon) servira à décaler légèrement les pointes des flèches 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 // 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 (i = 0; i < x; i++)
for (j = 0; j < y; j++) for (j = 0; j < y; j++)
for (k = 0; k < z; k++){ for (k = 0; k < z; k++){
@ -281,10 +281,10 @@ static bool arrows_anchors (long x, long y, long z,
} }
static void draw_line (GLuint *lines_origin, int a, int b) static void primitive_draw_line (GLuint *lines_origin, int a, int b)
{ {
*(lines_origin + lines_index) = a; lines_index ++; *(lines_origin + primitive_lines_index) = a; primitive_lines_index ++;
*(lines_origin + lines_index) = b; lines_index ++; *(lines_origin + primitive_lines_index) = b; primitive_lines_index ++;
} }
static void draw_a_cube_at(long u, long v, long w, GLuint *lines_origin, static void draw_a_cube_at(long u, long v, long w, GLuint *lines_origin,
@ -292,33 +292,33 @@ static void draw_a_cube_at(long u, long v, long w, GLuint *lines_origin,
{ {
long step_z = 1, step_y = size_z, step_x = size_y * size_z, x = u + 1, y = v + 1, z = w + 1; 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); // draw_line (0,21); draw_line (21,42);
// ce qui suit ne vaut que dans un espace 3 x 3 x 3 (le reste est à corriger - ou à oublier ?) // 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 (21,22); draw_line (21,25);
draw_line (lines_origin, 25,26); draw_line (lines_origin, 22,26); draw_line (25,26); draw_line (22,26);
draw_line (lines_origin, 37,41); draw_line (lines_origin, 41,42); draw_line (37,41); draw_line (41,42);
draw_line (lines_origin, 38,42); draw_line (lines_origin, 37,38); draw_line (38,42); draw_line (37,38);
draw_line (lines_origin, 25,41); draw_line (lines_origin, 21,37); draw_line (25,41); draw_line (21,37);
draw_line (lines_origin, 26,42); draw_line (lines_origin, 22,38); draw_line (26,42); draw_line (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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)); */ /* draw_line (step_z * z + step_y * y + step_x * u, step_z * (w + 0) + step_y * (v + 1) + step_x * (u + 0)); */
if (diagonals){ 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 (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 (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 (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)); draw_line (step_z * w + step_y * y + step_x * u, step_z * (w + 1) + step_y * (v + 0) + step_x * (u + 1));
} }
} }
@ -327,18 +327,18 @@ static void draw_ridges_3D (long x, long y, long z,
long step_x, long step_y, long step_z, long step_x, long step_y, long step_z,
GLuint *lines_origin) 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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); draw_line (step_z * z + step_y * 0 + step_x * 0, step_z * z + step_y * 0 + step_x * x);
} }
@ -354,12 +354,7 @@ static bool draw_grids_3D (long x, long y, long z,
for (int u = 0; u < y; u ++){ for (int u = 0; u < y; u ++){
for (int w = 0; w < x; w ++){ for (int w = 0; w < x; w ++){
calcul = step_x * w + step_y * u; calcul = step_x * w + step_y * u;
// écriture plus concise en utilisant la fonction "draw_line(...){...}" draw_line (calcul, calcul + step_y - step_z);
// 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 ++;
} }
} }
@ -367,8 +362,7 @@ static bool draw_grids_3D (long x, long y, long z,
for (int u = 0; u < z; u ++){ for (int u = 0; u < z; u ++){
for (int w = 0; w < x; w ++){ for (int w = 0; w < x; w ++){
calcul = step_x * w + step_z * u; calcul = step_x * w + step_z * u;
*(lines_origin + lines_index) = calcul; lines_index ++; draw_line (calcul, calcul + step_x - step_y);
*(lines_origin + lines_index) = calcul + step_x - step_y; lines_index ++;
} }
} }
@ -376,8 +370,7 @@ static bool draw_grids_3D (long x, long y, long z,
for (int u = 0; u < z; u ++){ for (int u = 0; u < z; u ++){
for (int w = 0; w < y; w ++){ for (int w = 0; w < y; w ++){
calcul = step_y * w + step_z * u; calcul = step_y * w + step_z * u;
*(lines_origin + lines_index) = calcul; lines_index ++; draw_line (calcul, calcul + step_x * (x - 1));
*(lines_origin + lines_index) = calcul + step_x * (x - 1); lines_index ++;
} }
} }
@ -392,44 +385,44 @@ static void diagonal_test(long x, long y, long z,
long step_x, long step_y, long step_z, long step_x, long step_y, long step_z,
GLuint *lines_origin) GLuint *lines_origin)
{ {
draw_line (lines_origin, 0, step_z * z + step_y * y + step_x * x); draw_line (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) 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 (s + 2, s + 6 + site % 2);
draw_line (lines_origin, s + 3, s + 6 + site % 2); draw_line (s + 3, s + 6 + site % 2);
draw_line (lines_origin, s + 4, s + 6 + site % 2); draw_line (s + 4, s + 6 + site % 2);
draw_line (lines_origin, s + 5, s + 6 + site % 2); draw_line (s + 5, s + 6 + site % 2);
} }
static void draw_an_arrow_Zenith_or_Nadir (GLuint *lines_origin, long s, int weight, int site) 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 (s + 0, s + 8 + site % 2);
draw_line (lines_origin, s + 1, s + 8 + site % 2); draw_line (s + 1, s + 8 + site % 2);
draw_line (lines_origin, s + 4, s + 8 + site % 2); draw_line (s + 4, s + 8 + site % 2);
draw_line (lines_origin, s + 5, s + 8 + site % 2); draw_line (s + 5, s + 8 + site % 2);
} }
static void draw_an_arrow_North_or_South (GLuint *lines_origin, long s, int weight, int site) 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 (s + 0, s + 10 + site % 2);
draw_line (lines_origin, s + 1, s + 10 + site % 2); draw_line (s + 1, s + 10 + site % 2);
draw_line (lines_origin, s + 2, s + 10 + site % 2); draw_line (s + 2, s + 10 + site % 2);
draw_line (lines_origin, s + 3, s + 10 + site % 2); draw_line (s + 3, s + 10 + site % 2);
} }
static void draw_a_central_star(GLuint *lines_origin, long n) static void draw_a_central_star(GLuint *lines_origin, long n)
{ {
draw_line (lines_origin, n + 0, n + 1); draw_line (n + 0, n + 1);
draw_line (lines_origin, n + 2, n + 3); draw_line (n + 2, n + 3);
draw_line (lines_origin, n + 4, n + 5); draw_line (n + 4, n + 5);
} }
// I'm standing on Earth (any planet or star or spinning spheroid, in fact) // I'm standing on Earth (any planet or star or spinning spheroid, in fact)
@ -479,7 +472,8 @@ static void draw_some_arrows (GLuint *lines_origin, long s, long stx, long sty,
{ {
site = *(arrows + i * 5 + 1); site = *(arrows + i * 5 + 1);
x = *(arrows + i * 5 + 2); y = *(arrows + i * 5 + 3); z = *(arrows + i * 5 + 4); 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);
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)); draw_a_central_star (lines_origin, s + 1 + 12 * (stx * x + sty * y + stz * z));
@ -514,21 +508,10 @@ static void show_user_choices(long model_size_x,
GLuint *arrows, GLuint *arrows,
int model_arrows_nb, 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_show_grid)
{ {
printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", model_size_x, model_size_y, model_size_z); 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 (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 == 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 == 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 == 2) printf("pref_show_grid = %d <> show grid xy ", pref_show_grid);
@ -537,23 +520,12 @@ static void show_user_choices(long model_size_x,
if (pref_show_grid == 6) printf("pref_show_grid = %d <> show grids xy & xz ", 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 == 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 (pref_show_grid == 15) printf("pref_show_grid = %d <> show grids xz & yz ", pref_show_grid);
if (model_arrows_nb == 0) printf("\n");
if (model_arrows_nb > 0) printf("\n[ n] load site x y z ---- < arrows array >\ if (model_arrows_nb > 0) printf("\n[ n] load site x y z ---- < arrows array >\
------------------------------------------------------------\n"); ------------------------------------------------------------\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++) for (int i = 0; i < model_arrows_nb; i++)
printf("[%2d] = %2d, %2d, %2d, %2d, %2d \n",\ 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)); 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");
} }
@ -568,8 +540,7 @@ bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_s
GLuint *arrows, int model_arrows_nb, 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_show_grid, int pref_test_diagonal,
GLfloat *vertex_origin, GLfloat *colors_origin, GLfloat *vertex_origin, GLfloat *colors_origin,
GLuint *lines_origin, GLuint *plans_origin) GLuint *lines_origin, GLuint *plans_origin)
@ -577,7 +548,6 @@ bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_s
{ {
show_user_choices(model_size_x, model_size_y, model_size_z, show_user_choices(model_size_x, model_size_y, model_size_z,
arrows, model_arrows_nb, arrows, model_arrows_nb,
// pref_mark_unit_space, pref_style_lines_planes, pref_style_mix_colors,
pref_show_grid); pref_show_grid);
grids_intersections (model_size_x, model_size_y, model_size_z, vertex_origin, colors_origin); grids_intersections (model_size_x, model_size_y, model_size_z, vertex_origin, colors_origin);
@ -589,14 +559,11 @@ bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_s
draw_grids_3D (model_size_x, model_size_y, model_size_z, step_x, step_y, step_z, lines_origin, pref_show_grid); 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_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; 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); 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_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; return 0;
} }

View File

@ -46,30 +46,57 @@
/* ----------------- V A R I A B L E S G L O B A L E S ------------------ */ /* ----------------- V A R I A B L E S G L O B A L E S ------------------ */
// int model_dim; < INUTILE : dim est fonction de model_space_size_x, y ,z) */ static int model_space_size_x = 0;
int model_space_size_x = 0; static int model_space_size_y = 0;
int model_space_size_y = 0; static int model_space_size_z = 0;
int model_space_size_z = 0; static int model_arrows_nb = 0;
int model_arrows_nb = 0; static int central_stars_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 static GLfloat *buffer_vertex_origin = NULL;
//int pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D static GLfloat *buffer_colors_origin = NULL;
//int pref_mark_unit_space = 0; // default == 0 == no marks static GLuint *buffer_lines_origin = NULL;
//int pref_style_lines_planes = 0; // arrows as lines = 0, as planes = 1 static GLuint *buffer_plans_origin = NULL;
//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; static int pref_show_grid = 0;
int buffer_colors_size = 0;
int buffer_lines_size = 0; // previously in graphics.h struct gl_area_entry.GLuint line_indices_nb; static int buffer_vertex_size = 0;
int buffer_plans_size = 0; // previously in graphics.h struct gl_area_entry.GLuint plan_indices_nb; static int buffer_colors_size = 0;
static int buffer_lines_size = 0;
static int buffer_plans_size = 0;
static void set_vertex_xyz(float x, float y, float z){
// *(buffer_vertex_origin + buffer_vertex_size) = x; buffer_vertex_size ++;
// *(buffer_vertex_origin + buffer_vertex_size) = y; buffer_vertex_size ++;
// *(buffer_vertex_origin + buffer_vertex_size) = z; buffer_vertex_size ++;
}
static void set_color_xyz(float x, float y, float z){
// *(buffer_colors_origin + buffer_colors_size) = x; buffer_colors_size ++;
// *(buffer_colors_origin + buffer_colors_size) = y; buffer_colors_size ++;
// *(buffer_colors_origin + buffer_colors_size) = z; buffer_colors_size ++;
}
static void draw_triangle(long a, long b, long c){
// *(buffer_plans_origin + buffer_plans_size) = a; buffer_plans_size ++;
// *(buffer_plans_origin + buffer_plans_size) = b; buffer_plans_size ++;
// *(buffer_plans_origin + buffer_plans_size) = c; buffer_plans_size ++;
}
void draw_line (int a, int b)
{
buffer_lines_origin = g_realloc (buffer_lines_origin,
(buffer_lines_size + 2) * sizeof(GLuint));
assert (buffer_lines_origin);
buffer_lines_origin[buffer_lines_size + 0] = a;
buffer_lines_origin[buffer_lines_size + 1] = b;
buffer_lines_size += 2;
}
/* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */ /* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */
@ -542,44 +569,45 @@ bool graphics_init_shaders(const void *gl_area)
GLuint arrows[] = {
1, 0, 0, 0, 0,
1, 1, 0, 0, 0,
1, 2, 0, 0, 0,
1, 3, 0, 0, 0,
1, 4, 0, 0, 0,
1, 5, 0, 0, 0,
/* 1, 1, 1, 0, 0, */
/* 1, 2, 2, 1, 1, */
/* 1, 3, 2, 2, 1, */
/* 1, 4, 3, 0, 1, */
/* 1, 5, 3, 0, 2, */
/* 1, 1, 3, 0, 2, */
/* 1, 0, 2, 0, 2, */
/* 1, 5, 2, 1, 1, */
// load, site, x, y, z
};
static void get_model_data_and_user_preferences(){ static void get_model_data_and_user_preferences(){
model_space_size_x = 4; // 0 < model_space_size_x model_space_size_x = 1; // 0 < model_space_size_x
model_space_size_y = 3; // 0 < model_space_size_y model_space_size_y = 1; // 0 < model_space_size_y
model_space_size_z = 3; // 0 < model_space_size_z model_space_size_z = 1; // 0 < model_space_size_z
// XXX ONLY space drawed, no arrows yet // XXX ONLY space drawed, no arrows yet
model_arrows_nb = 9; // assert : l'emplacement des flèches est contraint model_arrows_nb = sizeof(arrows) / (5 * 4); // assert : l'emplacement des flèches est contraint
// par model_space_size_x, y, z et le nombre de sites // par model_space_size_x, y, z et le nombre de sites
nombre_de_cases_contenant_des_fleches = 8; // à calculer TODO central_stars_nb = 0; // à calculer TODO
// ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites) // ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites)
nombre_de_cases_contenant_des_fleches = model_arrows_nb; central_stars_nb = 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 pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
// xyz, 0, x, y, z, xy, xz, yz, xyz // xyz, 0, x, y, z, xy, xz, yz, xyz
pref_test_diagonal = 0;
} }
GLuint arrows[] = {
1, 0, 0, 0, 0,
1, 1, 1, 0, 0,
1, 2, 2, 1, 1,
1, 3, 2, 2, 1,
1, 4, 3, 0, 1,
1, 5, 3, 0, 2,
1, 1, 3, 0, 2,
1, 0, 2, 0, 2,
1, 5, 2, 1, 1,
// load, site, x, y, z
};
@ -590,14 +618,8 @@ static void compute_buffers_sizes(int model_space_size_x,
int model_space_size_y, int model_space_size_y,
int model_space_size_z, int model_space_size_z,
int model_arrows_nb, 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) long grids_intersections = (model_space_size_x + 1)
* (model_space_size_y + 1) * (model_space_size_y + 1)
* (model_space_size_z + 1); * (model_space_size_z + 1);
@ -611,36 +633,24 @@ static void compute_buffers_sizes(int model_space_size_x,
long cubes_nb = model_space_size_x * model_space_size_y * model_space_size_z; 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 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_vertex_size += arrows_anchors * 3;
buffer_colors_size = buffer_vertex_size; buffer_colors_size = buffer_vertex_size;
buffer_plans_size = 3; buffer_plans_size = 0;
long grids_lines = long grids_lines =
(pref_show_grid % 2 == 0) * (model_space_size_x + 1) * (model_space_size_y + 1) (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 % 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); + (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 != 1) inc_buffer_lines_size(grids_lines * 2);
if (pref_show_grid > 0) buffer_lines_size += 12 * 2; // space ridges if (pref_show_grid > 0) inc_buffer_lines_size(12 * 2); // space ridges
// sinon, les arêtes de l'espace sont tracées par les grilles // 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] printf("allocated buffers sizes :%4d/3 = %3d vertices, %4d/3 = %3d colors,\
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", %4d/2 = %3d lines, %4d/3 = %3d plans.\n",
buffer_vertex_size, buffer_vertex_size / 3, buffer_vertex_size, buffer_vertex_size / 3,
buffer_colors_size, buffer_colors_size / 3, buffer_colors_size, buffer_colors_size / 3,
@ -685,18 +695,12 @@ 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();
/* une struct en retour pour ne plus utiliser de variables globales ? */
compute_buffers_sizes (model_space_size_x, compute_buffers_sizes (model_space_size_x,
model_space_size_y, model_space_size_y,
model_space_size_z, model_space_size_z,
model_arrows_nb, model_arrows_nb);
// pref_mark_unit_space,
// pref_style_lines_planes,
// pref_style_mix_colors,
pref_test_diagonal);
buffer_vertex_origin = g_malloc0 (buffer_vertex_size * sizeof(GLfloat) * 2); buffer_vertex_origin = g_malloc0 (buffer_vertex_size * sizeof(GLfloat) * 2);
buffer_colors_origin = g_malloc0 (buffer_colors_size * sizeof(GLfloat) * 2); buffer_colors_origin = g_malloc0 (buffer_colors_size * sizeof(GLfloat) * 2);
@ -710,11 +714,7 @@ void graphics_init_buffers(const void *gl_area)
arrows, arrows,
model_arrows_nb, model_arrows_nb,
// pref_mark_unit_space,
// pref_style_lines_planes,
// pref_style_mix_colors,
pref_show_grid, pref_show_grid,
pref_test_diagonal,
buffer_vertex_origin, buffer_vertex_origin,
buffer_colors_origin, buffer_colors_origin,
@ -815,10 +815,3 @@ void graphics_draw(const void *gl_area)
glFlush(); glFlush();
} }