diff --git a/draft getters-setters & co (résumé) b/draft getters-setters & co (résumé) new file mode 100644 index 0000000..296f612 --- /dev/null +++ b/draft getters-setters & co (résumé) @@ -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 + diff --git a/include/arrows.h b/include/arrows.h new file mode 100644 index 0000000..98ac46d --- /dev/null +++ b/include/arrows.h @@ -0,0 +1,114 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: OpenGL utils header + * + * Copyright (C) 2023 Jean Sirmai + * Copyright (C) 2023 Adrien Bourmault + * + * 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 + +/* + * Writes basis and tip for all arrows into vertex and color buffers + * + * @param dimensions (x,y,z) + * + * @return void + */ +void arrows_write_terminations (long x, long y, long z); + +/* + * Writes lines for arrow oriented to the east into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_east (long s, int weight, int site); + +/* + * Writes lines for arrow oriented to the west into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_west (long s, int weight, int site); + +/* + * Writes lines for arrow oriented to the zenith into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_zenith (long s, int weight, int site); + +/* + * Writes lines for arrow oriented to the nadir into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_nadir (long s, int weight, int site); + +/* + * Writes lines for arrow oriented to the south into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_south (long s, int weight, int site); + +/* + * Writes lines for arrow oriented to the north into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_north (long s, int weight, int site); + +/* + * Writes lines for arrow basis into lines buffer + * + * @param n, + * weight, + * site + * + * @return void + */ +void arrows_write_basis(long n); diff --git a/include/base.h b/include/base.h index 18ebfb7..24b7329 100644 --- a/include/base.h +++ b/include/base.h @@ -23,13 +23,18 @@ */ #pragma once +#include +#include +#include +#include #include #include +#include #include -#include +#include +#include #include -#include -#include +#include #define G_APPLICATION_DEFAULT_FLAGS 0 enum @@ -63,6 +68,7 @@ static inline char *read_file(char *filename) filesize = lseek(fd, 0, SEEK_END) + 1 ; contents = g_malloc(filesize * sizeof(char)); + assert (contents); lseek(fd, 0, SEEK_SET); read(fd,contents,filesize); @@ -73,3 +79,18 @@ static inline char *read_file(char *filename) return contents; } + +/* I'm standing on Earth (any planet or star or spinning spheroid, in fact) + * and looking towards its North pole + * + * X - X = EAST - WEST = rouge - cyan + * Y - Y = ZENITH - NADIR = vert - magenta + * Z - Z = NORTH - SOUTH = bleu - jaune + */ + +#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 diff --git a/include/graphics.h b/include/graphics.h index 9274fc5..a066de8 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -24,9 +24,12 @@ */ #pragma once +#include "base.h" #include #include +#include #include +#include /* * Structure describing a gl_area and its parameters, used to create a table @@ -46,6 +49,16 @@ struct gl_area_entry { }; +/* + * Find gl_area_entry from a gl_area ptr + * + * @param gl_area, ptr to the gl_area widget + * + * + * @return entry ptr + */ +struct gl_area_entry *graphics_find_glarea_from_ptr(const char *name); + /* * Initializes a gl_area * @@ -78,18 +91,181 @@ bool graphics_shutdown(const void *gl_area); * * @param gl_area, ptr to the gl_area widget * - * * @return true if initialized */ bool graphics_init_shaders(const void *gl_area); -/* - * Initializes the buffer of a gl_area - * +/* Initializes the buffer of a gl_area + * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget - * - * Note : indices[] is defined in graphics_cube.h - * * @return void */ void graphics_init_buffers(const void *gl_area); + +/* + * Writes values to describe a line from a to b into the line buffer + * + * @param coords GLuint (a,b) + * + * @return void + */ +void graphics_write_line (GLuint a, GLuint b); + +/* + * Writes values to describe a vertex at (x,y,z) into the vertex buffer + * + * @param coords GLfloat(x,y,z) + * + * @return void + */ +void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z); + +/* + * Writes values to describe a color (r,g,b) into the color buffer + * + * @param color GLfloat(r,g,b) + * + * @return void + */ +void graphics_write_color (GLfloat r, GLfloat g, GLfloat b); + +/* + * Writes values to describe an (a,b,c) plan (triangle) into the plan buffer + * + * @param coords GLuint (a,b,c) + * + * @return void + */ +void graphics_write_plan (GLuint a, GLuint b, GLuint c); + +/* + * Initializes an identity matrix + * + * @param res, target ptr + * + * @return void + */ +static inline void compute_i(float *res) +{ + /* initialize to the identity matrix */ + res[0] = 1.f; res[4] = 0.f; res[8] = 0.f; res[12] = 0.f; + res[1] = 0.f; res[5] = 1.f; res[9] = 0.f; res[13] = 0.f; + res[2] = 0.f; res[6] = 0.f; res[10] = 1.f; res[14] = 0.f; + res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f; +} + +/* + * Computes the projection matrix + * + * @param res, target ptr + * phi, XXX + * theta, XXX + * psi, XXX + * + * @return void + */ +static inline void compute_mvp(float *res, float phi, float theta, float psi) +{ + float x = phi *(G_PI / 180.f); + float y = theta *(G_PI / 180.f); + float z = psi *(G_PI / 180.f); + float c1 = cosf(x), s1 = sinf(x); + float c2 = cosf(y), s2 = sinf(y); + float c3 = cosf(z), s3 = sinf(z); + float c3c2 = c3 * c2; + float s3c1 = s3 * c1; + float c3s2s1 = c3 * s2 * s1; + float s3s1 = s3 * s1; + float c3s2c1 = c3 * s2 * c1; + float s3c2 = s3 * c2; + float c3c1 = c3 * c1; + float s3s2s1 = s3 * s2 * s1; + float c3s1 = c3 * s1; + float s3s2c1 = s3 * s2 * c1; + float c2s1 = c2 * s1; + float c2c1 = c2 * c1; + + compute_i(res); + + /* apply all three rotations using the three matrices: + * + * ⎡ c3 s3 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ 1 0 0 ⎤ + * ⎢ -s3 c3 0 ⎥ ⎢ 0 1 0 ⎥ ⎢ 0 c1 s1 ⎥ + * ⎣ 0 0 1 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 -s1 c1 ⎦ + */ + res[0] = c3c2; res[4] = s3c1 + c3s2s1; res[8] = s3s1 - c3s2c1; res[12] = 0.f; + res[1] = -s3c2; res[5] = c3c1 - s3s2s1; res[9] = c3s1 + s3s2c1; res[13] = 0.f; + res[2] = s2; res[6] = -c2s1; res[10] = c2c1; res[14] = 0.f; + res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f; +} + +/* + * Created and compile a shader + * + * @param type, shader type + * src, source code of shader + * + * @return shader id + */ +static inline GLuint create_shader(int type, const char *src) +{ + GLuint shader; + int status; + + shader = glCreateShader(type); + glShaderSource(shader, 1, &src, NULL); + glCompileShader(shader); + + glGetShaderiv(shader, GL_COMPILE_STATUS, &status); + if(status == GL_FALSE) { + int log_len; + char *buffer; + + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); + + buffer = g_malloc(log_len + 1); + assert (buffer); + glGetShaderInfoLog(shader, log_len, NULL, buffer); + + g_warning("Compile failure in %s shader:\n%s", + type == GL_VERTEX_SHADER ? "vertex" : "fragment", + buffer); + + g_free(buffer); + + glDeleteShader(shader); + + return 0; + } + + return shader; +} + +/* + * Find the gl_area_entry size + * + * @param void + * + * @return size of array + */ +extern struct gl_area_entry **gl_area_array; +static inline short gl_area_size(void) +{ + struct gl_area_entry **cur; + short size; + + // Check uninitialized and quit + if (gl_area_array == NULL) return 0; + + cur = gl_area_array; + while(*cur) { + cur++; + size++; + } + + return size; +} + +/*** TEST ***/ + +void main_test_graphics (void); diff --git a/include/buffers.h b/include/grid.h similarity index 50% rename from include/buffers.h rename to include/grid.h index 5df5e51..f8d7d11 100644 --- a/include/buffers.h +++ b/include/grid.h @@ -3,6 +3,7 @@ * * Desc: OpenGL utils header * + * Copyright (C) 2023 Adrien Bourmault * Copyright (C) 2023 Jean Sirmai * * This file is part of Gem-graph. @@ -26,23 +27,48 @@ #include #include -bool compute_space_and_arrows(long model_space_size_x, - long model_space_size_y, - long model_space_size_z, +/* + * Writes grid lines intersections to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_intersections (long x, long y, long 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); +/* + * Writes grid ridges to vertex and color buffers + * + * @param coords long (x,y,z), step_x, step_y, step_z + * + * @return void + */ +void grid_write_ridges (long x, long y, long z); +/* + * Writes grid lines for x axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_x (long x, long y, long z); +/* + * Writes grid lines for y axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_y (long x, long y, long z); + +/* + * Writes grid lines for z axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_z (long x, long y, long z); diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c new file mode 100644 index 0000000..32f0346 --- /dev/null +++ b/src/graphics/arrows.c @@ -0,0 +1,218 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: OpenGL utils header + * + * Copyright (C) 2023 Jean Sirmai + * Copyright (C) 2023 Arien Bourmault + * + * 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 . + */ + +#include "../../include/base.h" +#include "../../include/graphics.h" + +/* I'm standing on Earth (any planet or star or spinning spheroid, in fact) + * and looking towards its North pole + * + * X - X = EAST - WEST = rouge - cyan + * Y - Y = ZENITH - NADIR = vert - magenta + * Z - Z = NORTH - SOUTH = bleu - jaune + */ + +/* + * Writes basis and tip for all arrows into vertex and color buffers + * + * @param dimensions (x,y,z) + * + * @return void + */ +void arrows_write_terminations (long x, long y, long z) +{ + float max, i, j, k, vx, vy, vz, arrow_basis_width, arrow_tip_padding; + + max = fmax(x, y); max = fmax(max, z); + + // arrow_basis_width donne la dimension de l'étoile centrale + arrow_basis_width = 0.3f * (1 / max), + + // décale légèrement les pointes des flèches + // pour qu'elles n'aillent pas jusqu'aux faces des cubes + arrow_tip_padding = 0.1 * (1 / max); + + 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 + (1 / max); + vy = (2 * j / y - 1) * y / max + (1 / max); + vz = (2 * k / z - 1) * z / max + (1 / max); + + // X - X axis - central star (basis) + graphics_write_vertex(vx + arrow_basis_width, vy, vz); + graphics_write_vertex(vx - arrow_basis_width, vy, vz); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // Y - Y axis - central star (basis) + graphics_write_vertex(vx, vy + arrow_basis_width, vz); + graphics_write_vertex(vx, vy - arrow_basis_width, vz); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // Z - Z axis - central star (basis) + graphics_write_vertex(vx, vy, vz + arrow_basis_width); + graphics_write_vertex(vx, vy, vz - arrow_basis_width); + graphics_write_color(0.3f, 0.3f, 0.3f); + graphics_write_color(0.3f, 0.3f, 0.3f); + + // X - X (EAST - WEST) axis - arrows tips + graphics_write_vertex (vx + (1 / max) - arrow_tip_padding, vy, vz); + graphics_write_vertex (vx - (1 / max) + arrow_tip_padding, vy, vz); + graphics_write_color(1.0f, 0.0f, 0.0f); + graphics_write_color(0.0f, 1.0f, 1.0f); + + // Y - Y (ZENITH - NADIR) axis - arrows tips + graphics_write_vertex (vx, vy + (1 / max) - arrow_tip_padding, vz); + graphics_write_vertex (vx, vy - (1 / max) + arrow_tip_padding, vz); + graphics_write_color(0.0f, 1.0f, 0.0f); + graphics_write_color(1.0f, 0.0f, 1.0f); + + // Z - Z axis arrows tips near the faces centers NORTH - SOUTH + graphics_write_vertex (vx, vy, vz + (1 / max) - arrow_tip_padding); + graphics_write_vertex (vx, vy, vz - (1 / max) + arrow_tip_padding); + graphics_write_color(0.0f, 0.0f, 1.0f); + graphics_write_color(1.0f, 1.0f, 0.0f); + }; +} + +/* + * Writes lines for arrow oriented to the east into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_east (long s, int weight, int site) +{ + graphics_write_line (s + 2, s + 6 + site % 2); + graphics_write_line (s + 3, s + 6 + site % 2); + graphics_write_line (s + 4, s + 6 + site % 2); + graphics_write_line (s + 5, s + 6 + site % 2); +} + +/* + * Writes lines for arrow oriented to the west into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_west (long s, int weight, int site) +{ + graphics_write_line (s + 2, s + 6 + site % 2); + graphics_write_line (s + 3, s + 6 + site % 2); + graphics_write_line (s + 4, s + 6 + site % 2); + graphics_write_line (s + 5, s + 6 + site % 2); +} + +/* + * Writes lines for arrow oriented to the zenith into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_zenith (long s, int weight, int site) +{ + graphics_write_line (s + 0, s + 8 + site % 2); + graphics_write_line (s + 1, s + 8 + site % 2); + graphics_write_line (s + 4, s + 8 + site % 2); + graphics_write_line (s + 5, s + 8 + site % 2); +} + +/* + * Writes lines for arrow oriented to the nadir into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_nadir (long s, int weight, int site) +{ + graphics_write_line (s + 0, s + 8 + site % 2); + graphics_write_line (s + 1, s + 8 + site % 2); + graphics_write_line (s + 4, s + 8 + site % 2); + graphics_write_line (s + 5, s + 8 + site % 2); +} + +/* + * Writes lines for arrow oriented to the south into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_south (long s, int weight, int site) +{ + graphics_write_line (s + 0, s + 10 + site % 2); + graphics_write_line (s + 1, s + 10 + site % 2); + graphics_write_line (s + 2, s + 10 + site % 2); + graphics_write_line (s + 3, s + 10 + site % 2); +} + +/* + * Writes lines for arrow oriented to the north into lines buffer + * + * @param s, + * weight, + * site + * + * @return void + */ +void write_arrow_lines_north (long s, int weight, int site) +{ + graphics_write_line (s + 0, s + 10 + site % 2); + graphics_write_line (s + 1, s + 10 + site % 2); + graphics_write_line (s + 2, s + 10 + site % 2); + graphics_write_line (s + 3, s + 10 + site % 2); +} + +/* + * Writes lines for arrow basis into lines buffer + * + * @param n, + * weight, + * site + * + * @return void + */ +void arrows_write_basis(long n) +{ + graphics_write_line (n + 0, n + 1); + graphics_write_line (n + 2, n + 3); + graphics_write_line (n + 4, n + 5); +} diff --git a/src/graphics/buffers.c b/src/graphics/buffers.c deleted file mode 100644 index 8a77fc2..0000000 --- a/src/graphics/buffers.c +++ /dev/null @@ -1,607 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../include/ui.h" -#include "../../include/graphics.h" -#include "../../include/buffers.h" - -static long vertex_index = 0; -static long colors_index = 0; -static long lines_index = 0; -static long plans_index = 0; - - - -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 - diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 34620d8..5077374 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -23,56 +23,83 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//#include "../../include/base.h" +#include "../../include/base.h" #include "../../include/ui.h" #include "../../include/graphics.h" -#include "../../include/buffers.h" +#include "../../include/arrows.h" +#include "../../include/grid.h" #define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define FRAG_SHADER_FILE "src/shaders/shader.frag" -/* ----------------- V A R I A B L E S G L O B A L E S ------------------ */ +static GLuint arrows[] = { + 1, 0, 1, 2, 4, + 1, 1, 1, 2, 4, + 1, 2, 1, 2, 4, + 1, 3, 1, 2, 4, + 1, 4, 1, 2, 4, + 1, 5, 1, 2, 4, -// 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; + 1, 1, 0, 0, 0, + 1, 3, 0, 0, 0, + 1, 5, 0, 0, 0, -GLfloat *buffer_vertex_origin = NULL; -GLfloat *buffer_colors_origin = NULL; -GLuint *buffer_lines_origin = NULL; -GLuint *buffer_plans_origin = NULL; + 1, 0, 2, 0, 0, + 1, 3, 2, 0, 0, + 1, 5, 2, 0, 0, -//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 + 1, 1, 0, 4, 0, + 1, 2, 0, 4, 0, + 1, 5, 0, 4, 0, -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; + 1, 1, 0, 0, 6, + 1, 3, 0, 0, 6, + 1, 4, 0, 0, 6, + + 1, 0, 2, 4, 0, + 1, 2, 2, 4, 0, + 1, 5, 2, 4, 0, + + 1, 0, 2, 0, 6, + 1, 3, 2, 0, 6, + 1, 4, 2, 0, 6, + + 1, 1, 0, 4, 6, + 1, 2, 0, 4, 6, + 1, 4, 0, 4, 6, -/* ----------------- O P E N G L D E B U G M E S S A G E S ------------ */ + 1, 0, 2, 4, 6, + 1, 2, 2, 4, 6, + 1, 4, 2, 4, 6, + +// load, site, x, y, z +}; + +static int model_space_size_x = 0; +static int model_space_size_y = 0; +static int model_space_size_z = 0; +static int model_arrows_nb = 0; +static int central_stars_nb = 0; + +static GLfloat *buffer_vertex_origin = NULL; +static GLfloat *buffer_colors_origin = NULL; +static GLuint *buffer_lines_origin = NULL; +static GLuint *buffer_plans_origin = NULL; + +static int pref_show_grid = 0; + +static volatile int buffer_vertex_size = 0; +static int buffer_colors_size = 0; +static int buffer_lines_size = 0; +static int buffer_plans_size = 0; + +/* + * Dynamic array of ptrs to dynamically allocated gl_area_entry + */ +struct gl_area_entry **gl_area_array = NULL; + +/* -------------------------------------------------------------------------- */ /* * Prints verbose human-readable debug messages @@ -135,270 +162,156 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, /* -------------------------------------------------------------------------- */ -/* - * Dynamic array of ptrs to dynamically allocated gl_area_entry - */ -struct gl_area_entry **gl_area_array = NULL; - - -/* - * Find gl_area_entry from a gl_area ptr - * - * @param gl_area, ptr to the gl_area widget - * - * - * @return entry ptr - */ -struct gl_area_entry *find_entry_from_ptr(const char *name) +static void get_model_data_and_user_preferences() { - struct gl_area_entry **cur; + model_space_size_x = 3; // 0 < model_space_size_x + model_space_size_y = 5; // 0 < model_space_size_y + model_space_size_z = 7; // 0 < model_space_size_z - // Check uninitialized and quit - if (gl_area_array == NULL) return NULL; + 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 - // Seek in array - cur = gl_area_array; - while(*cur) { - if (strncmp((*cur)->name, name, sizeof((*cur)->name)) == 0) return *cur; - cur++; - } + 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; - // Nothing found - return NULL; + pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc + // xyz, 0, x, y, z, xy, xz, yz, xyz +} + +/* -------------------------------------------------------------------------- */ + +/* + * Writes values to describe a line from a to b into the line buffer + * + * @param coords GLuint (a,b) + * + * @return void + */ +void graphics_write_line (GLuint a, GLuint 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; } /* - * Find the gl_area_entry size + * Writes values to describe a vertex at (x,y,z) into the vertex buffer * - * @param void + * @param coords GLfloat(x,y,z) * - * @return size of array + * @return void */ -static inline short gl_area_size(void) +void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z) { - struct gl_area_entry **cur; - short size; + buffer_vertex_origin = g_realloc (buffer_vertex_origin, + (buffer_vertex_size + 3) * sizeof(GLfloat)); - // Check uninitialized and quit - if (gl_area_array == NULL) return 0; + assert (buffer_vertex_origin); - cur = gl_area_array; - while(*cur) { - cur++; - size++; - } + buffer_vertex_origin[buffer_vertex_size + 0] = x; + buffer_vertex_origin[buffer_vertex_size + 1] = y; + buffer_vertex_origin[buffer_vertex_size + 2] = z; - return size; + buffer_vertex_size += 3; + + //printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size); } /* - * Initializes a gl_area + * Writes values to describe a color (r,g,b) into the color buffer * - * @param gl_area, ptr to the gl_area widget + * @param color GLfloat(r,g,b) * - * @return true if initialized + * @return void */ -bool graphics_init(const char *gl_area) +void graphics_write_color (GLfloat r, GLfloat g, GLfloat b) { - short array_size; + buffer_colors_origin = g_realloc (buffer_colors_origin, + (buffer_colors_size + 3) * sizeof(GLfloat)); - glEnable(GL_DEBUG_OUTPUT); - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glEnable(GL_MULTISAMPLE); + assert (buffer_colors_origin); - // Check if not already initialized - if (find_entry_from_ptr(gl_area)) { - errno = EEXIST; - perror("gl_area_array already exists"); - return false; - } + buffer_colors_origin[buffer_colors_size + 0] = r; + buffer_colors_origin[buffer_colors_size + 1] = g; + buffer_colors_origin[buffer_colors_size + 2] = b; - // Get actual array size - array_size = gl_area_size(); - - // If it does not exist, allocs it - if (gl_area_array == NULL) { - gl_area_array = g_malloc0(sizeof(struct gl_area_entry *) * 2); - - // If it does exist, g_reallocs it - } else { - gl_area_array = g_realloc(gl_area_array, - (array_size + 1) - * sizeof(struct gl_area_entry *)); - if (gl_area_array == NULL) { - perror("Not enough memory to allocate gl_area_array"); - return false; - } - - explicit_bzero(gl_area_array + array_size * sizeof(struct gl_area_entry *), - sizeof(struct gl_area_entry *)); - } - - // Alloc new entry - gl_area_array[array_size] = g_malloc0(sizeof(struct gl_area_entry)); - - strcpy(gl_area_array[array_size]->name, gl_area); - - if (!graphics_init_shaders(gl_area)) return false; - - graphics_init_buffers(gl_area); - - glDebugMessageCallback(graphics_debug_callback, NULL); - - return true; + buffer_colors_size += 3; } /* - * Shutdowns a gl_area + * Writes values to describe an (a,b,c) plan (triangle) into the plan buffer * - * @param gl_area, ptr to the gl_area widget + * @param coords GLuint (a,b,c) * - * @return true if success + * @return void */ -bool graphics_shutdown(const void *gl_area) +void graphics_write_plan (GLuint a, GLuint b, GLuint c) +{ + buffer_plans_origin = g_realloc (buffer_plans_origin, + (buffer_plans_size + 3) * sizeof(GLuint)); + + assert (buffer_plans_origin); + + buffer_plans_origin[buffer_plans_size + 0] = a; + buffer_plans_origin[buffer_plans_size + 1] = b; + buffer_plans_origin[buffer_plans_size + 2] = c; + + buffer_plans_size += 3; +} + +/* Initializes the buffer of a gl_area + * Calls according to the user preferences + * @param gl_area, ptr to the gl_area widget + * @return void + */ +void graphics_init_buffers(const void *gl_area) { struct gl_area_entry *entry; + entry = graphics_find_glarea_from_ptr(gl_area); - entry = find_entry_from_ptr(gl_area); + get_model_data_and_user_preferences(); - if (entry == NULL) { - errno = EFAULT; - perror("gl_area_array entry not found"); - return false; + //XXX + main_test_graphics (); + + GLuint vao, vertex_buffer, color_buffer; + + glGenBuffers(1, &vertex_buffer); + glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, buffer_vertex_size * sizeof(buffer_vertex_origin[0]), buffer_vertex_origin, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + + // colors + glGenBuffers(1, &color_buffer); + glBindBuffer(GL_ARRAY_BUFFER, color_buffer); + glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin[0]), buffer_colors_origin, 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; } - - glDeleteBuffers(1, &entry->position_buffer); - glDeleteBuffers(1, &entry->color_buffer); - glDeleteProgram(entry->program); - - // Liberate - g_free(entry); - - entry = NULL; - - gl_area_array = g_realloc(gl_area_array, - (gl_area_size()) - * sizeof(struct gl_area_entry *)); - - g_free(buffer_vertex_origin); - g_free(buffer_colors_origin); - g_free(buffer_lines_origin); - g_free(buffer_plans_origin); - return true; } -/* -------------------------------------------------------------------------- */ - -/* - * Initializes an identity matrix - * - * @param res, target ptr - * - * @return void - */ -static inline void compute_i(float *res) -{ - /* initialize to the identity matrix */ - res[0] = 1.f; res[4] = 0.f; res[8] = 0.f; res[12] = 0.f; - res[1] = 0.f; res[5] = 1.f; res[9] = 0.f; res[13] = 0.f; - res[2] = 0.f; res[6] = 0.f; res[10] = 1.f; res[14] = 0.f; - res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f; -} - -/* - * Computes the projection matrix - * - * @param res, target ptr - * phi, XXX - * theta, XXX - * psi, XXX - * - * @return void - */ -static inline void compute_mvp(float *res, float phi, float theta, float psi) -{ - float x = phi *(G_PI / 180.f); - float y = theta *(G_PI / 180.f); - float z = psi *(G_PI / 180.f); - float c1 = cosf(x), s1 = sinf(x); - float c2 = cosf(y), s2 = sinf(y); - float c3 = cosf(z), s3 = sinf(z); - float c3c2 = c3 * c2; - float s3c1 = s3 * c1; - float c3s2s1 = c3 * s2 * s1; - float s3s1 = s3 * s1; - float c3s2c1 = c3 * s2 * c1; - float s3c2 = s3 * c2; - float c3c1 = c3 * c1; - float s3s2s1 = s3 * s2 * s1; - float c3s1 = c3 * s1; - float s3s2c1 = s3 * s2 * c1; - float c2s1 = c2 * s1; - float c2c1 = c2 * c1; - - compute_i(res); - - /* apply all three rotations using the three matrices: - * - * ⎡ c3 s3 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ 1 0 0 ⎤ - * ⎢ -s3 c3 0 ⎥ ⎢ 0 1 0 ⎥ ⎢ 0 c1 s1 ⎥ - * ⎣ 0 0 1 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 -s1 c1 ⎦ - */ - res[0] = c3c2; res[4] = s3c1 + c3s2s1; res[8] = s3s1 - c3s2c1; res[12] = 0.f; - res[1] = -s3c2; res[5] = c3c1 - s3s2s1; res[9] = c3s1 + s3s2c1; res[13] = 0.f; - res[2] = s2; res[6] = -c2s1; res[10] = c2c1; res[14] = 0.f; - res[3] = 0.f; res[7] = 0.f; res[11] = 0.f; res[15] = 1.f; -} - -/* - * Created and compile a shader - * - * @param type, shader type - * src, source code of shader - * - * @return shader id - */ -static inline GLuint create_shader(int type, const char *src) -{ - GLuint shader; - int status; - - shader = glCreateShader(type); - glShaderSource(shader, 1, &src, NULL); - glCompileShader(shader); - - glGetShaderiv(shader, GL_COMPILE_STATUS, &status); - if(status == GL_FALSE) { - int log_len; - char *buffer; - - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); - - buffer = g_malloc(log_len + 1); - glGetShaderInfoLog(shader, log_len, NULL, buffer); - - g_warning("Compile failure in %s shader:\n%s", - type == GL_VERTEX_SHADER ? "vertex" : "fragment", - buffer); - - g_free(buffer); - - glDeleteShader(shader); - - return 0; - } - - return shader; -} - -/* -------------------------------------------------------------------------- */ - /* * Initializes the shaders of a gl_area and link them to a program * * @param gl_area, ptr to the gl_area widget * - * * @return true if initialized */ bool graphics_init_shaders(const void *gl_area) @@ -413,7 +326,7 @@ bool graphics_init_shaders(const void *gl_area) GLuint v = 0; GLuint p = 0; - entry = find_entry_from_ptr(gl_area); + entry = graphics_find_glarea_from_ptr(gl_area); if (entry == NULL) { errno = EFAULT; @@ -464,6 +377,7 @@ bool graphics_init_shaders(const void *gl_area) glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_len); buffer = g_malloc(log_len + 1); + assert(buffer); glGetProgramInfoLog(program, log_len, NULL, buffer); g_warning("Linking failure:\n%s", buffer); @@ -504,248 +418,6 @@ bool graphics_init_shaders(const void *gl_area) return true; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -static void get_model_data_and_user_preferences(){ - - - model_space_size_x = 4; // 0 < model_space_size_x - model_space_size_y = 3; // 0 < model_space_size_y - model_space_size_z = 3; // 0 < model_space_size_z - - // XXX ONLY space drawed, no arrows yet - - model_arrows_nb = 9; // assert : l'emplacement des flèches est contraint - // par model_space_size_x, y, z et le nombre de sites - - nombre_de_cases_contenant_des_fleches = 8; // à calculer TODO - // ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites) - nombre_de_cases_contenant_des_fleches = model_arrows_nb; - -// pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both -// pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix -// pref_style_mix_colors = 0; // TODO - pref_show_grid = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc - // xyz, 0, x, y, z, xy, xz, yz, xyz - pref_test_diagonal = 0; -} - -GLuint arrows[] = { - 1, 0, 0, 0, 0, - 1, 1, 1, 0, 0, - 1, 2, 2, 1, 1, - 1, 3, 2, 2, 1, - 1, 4, 3, 0, 1, - 1, 5, 3, 0, 2, - 1, 1, 3, 0, 2, - 1, 0, 2, 0, 2, - 1, 5, 2, 1, 1, -// load, site, x, y, z -}; - - - - - - - -static void compute_buffers_sizes(int model_space_size_x, - int model_space_size_y, - int model_space_size_z, - - int model_arrows_nb, - -// int pref_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 - * Calls according to the user preferences - * @param gl_area, ptr to the gl_area widget - * Note : buffer_lines_origin[] is no more defined in graphics_cube.h - * @return void - */ -#define A 0 -void graphics_init_buffers(const void *gl_area) -{ - struct gl_area_entry *entry; - entry = find_entry_from_ptr(gl_area); - - get_model_data_and_user_preferences(); - /* une struct en retour pour ne plus utiliser de variables globales ? */ - - compute_buffers_sizes (model_space_size_x, - model_space_size_y, - model_space_size_z, - - 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_colors_origin = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2); - buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLuint) * 2); - buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLuint) * 2); - - compute_space_and_arrows (model_space_size_x, - model_space_size_y, - model_space_size_z, - - arrows, - model_arrows_nb, - -// pref_mark_unit_space, -// pref_style_lines_planes, -// pref_style_mix_colors, - pref_show_grid, - pref_test_diagonal, - - buffer_vertex_origin, - buffer_colors_origin, - buffer_lines_origin, - buffer_plans_origin); - - GLuint vao, vertex_buffer, color_buffer; - - glGenBuffers(1, &vertex_buffer); - glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); - glBufferData(GL_ARRAY_BUFFER, buffer_vertex_size * sizeof(buffer_vertex_origin[0]), buffer_vertex_origin, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - - // colors - glGenBuffers(1, &color_buffer); - glBindBuffer(GL_ARRAY_BUFFER, color_buffer); - glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin), buffer_colors_origin, 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; - } -} - /* * Draws the current buffer to a gl_area * @@ -760,7 +432,7 @@ void graphics_draw(const void *gl_area) float p[16]; struct gl_area_entry *entry; - entry = find_entry_from_ptr(gl_area); + entry = graphics_find_glarea_from_ptr(gl_area); if (entry == NULL) { errno = EFAULT; @@ -814,11 +486,242 @@ void graphics_draw(const void *gl_area) glFlush(); } - - - - - - +/* -------------------------------------------------------------------------- */ + +/* + * DEBUG + * + */ +static void show_user_choices(long model_space_size_x, + long model_space_size_y, + long model_space_size_z, + + GLuint *arrows, + int model_arrows_nb, + + int pref_show_grid) +{ + printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", model_space_size_x, model_space_size_y, model_space_size_z); + if (model_arrows_nb > 0) printf("[%d] arrows ", model_arrows_nb); + 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("\tbuffer_vertex_size = %d\t lines = %d\n",\ + buffer_vertex_size, buffer_lines_size); + if (model_arrows_nb > 0) printf("\n[ n] load site x y z ---- < arrows array >\ + ------------------------------------------------------------\n"); + 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)); +} + +/* + * Find gl_area_entry from a gl_area ptr + * + * @param gl_area, ptr to the gl_area widget + * + * + * @return entry ptr + */ +struct gl_area_entry *graphics_find_glarea_from_ptr(const char *name) +{ + struct gl_area_entry **cur; + + // Check uninitialized and quit + if (gl_area_array == NULL) return NULL; + + // Seek in array + cur = gl_area_array; + while(*cur) { + if (strncmp((*cur)->name, name, sizeof((*cur)->name)) == 0) return *cur; + cur++; + } + + // Nothing found + return NULL; +} + +/* + * Initializes a gl_area + * + * @param gl_area, ptr to the gl_area widget + * + * @return true if initialized + */ +bool graphics_init(const char *gl_area) +{ + short array_size; + + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + glEnable(GL_MULTISAMPLE); + + // Check if not already initialized + if (graphics_find_glarea_from_ptr(gl_area)) { + errno = EEXIST; + perror("gl_area_array already exists"); + return false; + } + + // Get actual array size + array_size = gl_area_size(); + + // If it does not exist, allocs it + if (gl_area_array == NULL) { + gl_area_array = g_malloc0(sizeof(struct gl_area_entry *) * 2); + assert(gl_area_array); + + // If it does exist, g_reallocs it + } else { + gl_area_array = g_realloc(gl_area_array, + (array_size + 1) + * sizeof(struct gl_area_entry *)); + assert (gl_area_array); + if (gl_area_array == NULL) { + perror("Not enough memory to allocate gl_area_array"); + return false; + } + + explicit_bzero(gl_area_array + array_size * sizeof(struct gl_area_entry *), + sizeof(struct gl_area_entry *)); + } + + // Alloc new entry + gl_area_array[array_size] = g_malloc0(sizeof(struct gl_area_entry)); + assert(gl_area_array[array_size]); + + strcpy(gl_area_array[array_size]->name, gl_area); + + if (!graphics_init_shaders(gl_area)) return false; + + graphics_init_buffers(gl_area); + + glDebugMessageCallback(graphics_debug_callback, NULL); + + return true; +} + +/* + * Shutdowns a gl_area + * + * @param gl_area, ptr to the gl_area widget + * + * @return true if success + */ +bool graphics_shutdown(const void *gl_area) +{ + struct gl_area_entry *entry; + + entry = graphics_find_glarea_from_ptr(gl_area); + + if (entry == NULL) { + errno = EFAULT; + perror("gl_area_array entry not found"); + return false; + } + + glDeleteBuffers(1, &entry->position_buffer); + glDeleteBuffers(1, &entry->color_buffer); + glDeleteProgram(entry->program); + + // Liberate + g_free(entry); + + entry = NULL; + + gl_area_array = g_realloc(gl_area_array, + (gl_area_size()) + * sizeof(struct gl_area_entry *)); + assert (gl_area_array || !gl_area_size()); + + g_free(buffer_vertex_origin); + g_free(buffer_colors_origin); + g_free(buffer_lines_origin); + g_free(buffer_plans_origin); + return true; +} + +/* -------------------------------------------------------------------------- */ + +void main_test_graphics (void) +{ + long stx = model_space_size_z * model_space_size_y, + sty = model_space_size_z, + stz = 1; + + long site = 0, x = 0, y = 0, z = 0; + + show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z, + arrows, model_arrows_nb, + pref_show_grid); + + printf("offset_before_grid = %d\n", buffer_vertex_size / 3); + + /* GRID */ + + grid_write_intersections (model_space_size_x, model_space_size_y, model_space_size_z); + + if (pref_show_grid % 2 == 0) + grid_write_x (model_space_size_x, model_space_size_y, model_space_size_z); + if (pref_show_grid % 3 == 0) + grid_write_y (model_space_size_x, model_space_size_y, model_space_size_z); + if (pref_show_grid % 5 == 0) + grid_write_z (model_space_size_x, model_space_size_y, model_space_size_z); + + if (pref_show_grid > 0) + grid_write_ridges (model_space_size_x, model_space_size_y, model_space_size_z); + + int offset_after_grid = buffer_vertex_size / 3; + printf("offset_after_grid = %d\n", offset_after_grid); + + /* ARROWS */ + arrows_write_terminations (model_space_size_x, model_space_size_y, model_space_size_z); + + for (int i = 0; i < model_arrows_nb; i++) { + site = arrows[i * 5 + 1]; + x = arrows[i * 5 + 2]; + y = arrows[i * 5 + 3]; + z = arrows[i * 5 + 4]; + + // printf("[%ld]\tsite = %d\tx = %ld\ty = %ld\tz = %ld\tstep x = %ld\tstep y = %ld\n", site, i, x, y, z, stx, sty); + + arrows_write_basis (offset_after_grid + 12 * (stx * x + sty * y + stz * z)); // XXX 1 + 12 ? + + switch(site){ + case EAST: + write_arrow_lines_east(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + case WEST: + write_arrow_lines_west(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + case ZENITH: + write_arrow_lines_zenith(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + case NADIR: + write_arrow_lines_nadir(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + case SOUTH: + write_arrow_lines_south(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + case NORTH: + write_arrow_lines_north(offset_after_grid + 12 * (stx * x + sty * y + stz * z), 1, site); + break; + default: + // XXX ? + break; + } + } + + show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z, + arrows, model_arrows_nb, + pref_show_grid); + + printf("main_test_graphics [ok]\n"); +} diff --git a/src/graphics/grid.c b/src/graphics/grid.c new file mode 100644 index 0000000..4c632bd --- /dev/null +++ b/src/graphics/grid.c @@ -0,0 +1,169 @@ +/* + * Gem-graph + * + * Desc: OpenGL grid functions + * + * Copyright (C) 2023 Jean Sirmai + * Copyright (C) 2023 Adrien Bourmault + * + * 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 . + */ + +#include "../../include/base.h" +#include "../../include/graphics.h" + +/* + * Writes grid lines intersections to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_intersections (long x, long y, long z) +{ + + 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; + + graphics_write_vertex (vx, vy, vz); + graphics_write_color (0.64f,0.64f,0.64f); + }; +} + +/* + * Writes grid ridges to vertex and color buffers + * + * @param coords long (x,y,z), step_x, step_y, step_z + * + * @return void + */ +void grid_write_ridges (long x, + long y, + long z) +{ + long step_x = (z + 1) * (y + 1), + step_y = z + 1, + step_z = 1; + + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * 0 + step_y * 0 + step_x * x); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * 0 + step_y * y + step_x * 0); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * z + step_y * 0 + step_x * 0); + + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * z + step_y * y + step_x * 0); + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * z + step_y * 0 + step_x * x); + + graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, + step_z * z + step_y * 0 + step_x * x); + graphics_write_line (step_z * z + step_y * 0 + step_x * 0, + step_z * z + step_y * y + step_x * 0); + + graphics_write_line (step_z * 0 + step_y * y + step_x * 0, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * 0 + step_y * y + step_x * 0, + step_z * z + step_y * y + step_x * 0); + graphics_write_line (step_z * z + step_y * 0 + step_x * 0, + step_z * z + step_y * 0 + step_x * x); +} + +/* + * Writes grid lines for x axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_x (long x, long y, long z) +{ + long step_z = 1, + step_y = z + 1, + step_x = (z + 1) * (y + 1); + + x ++; y ++; z ++; + float calcul = 0; + + for (int u = 0; u < y; u ++){ + for (int w = 0; w < x; w ++){ + calcul = step_x * w + step_y * u; + graphics_write_line (calcul, calcul + step_y - step_z); + } + } +} + +/* + * Writes grid lines for y axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_y (long x, long y, long z) +{ + long step_z = 1, + step_y = z + 1, + step_x = (z + 1) * (y + 1); + + x ++; y ++; z ++; + float calcul = 0; + + for (int u = 0; u < z; u++) { + for (int w = 0; w < x; w ++){ + calcul = step_x * w + step_z * u; + graphics_write_line (calcul, calcul + step_x - step_y); + } + } +} + +/* + * Writes grid lines for z axis to vertex and color buffers + * + * @param coords long (x,y,z) + * + * @return void + */ +void grid_write_z (long x, long y, long z) +{ + long step_z = 1, + step_y = z + 1, + step_x = (z + 1) * (y + 1); + + x ++; y ++; z ++; + float calcul = 0; + + for (int u = 0; u < z; u ++){ + for (int w = 0; w < y; w ++){ + calcul = step_y * w + step_z * u; + graphics_write_line (calcul, calcul + step_x * (x - 1)); + } + } +} + diff --git a/src/graphics/scories.c.forget b/src/graphics/scories.c.forget deleted file mode 100644 index 2c71b83..0000000 --- a/src/graphics/scories.c.forget +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Gem-graph OpenGL experiments - * - * Desc: OpenGL utils header - * - * Copyright (C) 2023 Jean Sirmai - * - * This file was part of Gem-graph. Forget it now. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -//#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../include/ui.h" -#include "../../include/graphics.h" -#include "../../include/buffers.h" - -static long vertex_index = 0; -static long colors_index = 0; -static long lines_index = 0; -static long plans_index = 0; - - -#define V 0 - -static bool compute_space_2D(int size_x, - int size_y, - int size_z, - - int pref_mark_unit_space, - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *colors_origin, - GLuint *lines_origin, - GLuint *plans_origin) -{ - - float x = 0; - // for (int k = 0; k < size_x + 1; k++) <=> + 1 - // car on passe du nombre de cases = (n) - // au nombre de séparations entre les cases + les deux bords = (n + 1) - - if (V) printf("space_2D vertex "); - for (int k = 0; k < size_x; k++){ // barres verticales - // - x = ((size_x % 2) * (size_x / 2 - k) - + (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2; - - if (V) printf("[%1.1f] ", x); - - *(vertex_origin + k * 6 + 0) = - x; - *(vertex_origin + k * 6 + 1) = 1.0f / size_x; - *(vertex_origin + k * 6 + 2) = 0.0f; - - *(vertex_origin + k * 6 + 3) = - x; - *(vertex_origin + k * 6 + 4) = - 1.0f / size_x; - *(vertex_origin + k * 6 + 5) = 0.0f; - - // fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f; - - vertex_index += 6; if (V) printf(" => vertex_index = %3ld space 2D\n", vertex_index); - - *(colors_origin + k * 6 + 0) = 1; - *(colors_origin + k * 6 + 1) = 0; - *(colors_origin + k * 6 + 2) = 0; - - *(colors_origin + k * 6 + 3) = 1; - *(colors_origin + k * 6 + 4) = 1; - *(colors_origin + k * 6 + 5) = 0; - - colors_index += 6; - - *(lines_origin + k * 2 + 0) = k * 2 + 0; - *(lines_origin + k * 2 + 1) = k * 2 + 1; - - lines_index += 2; if (V) printf(" => lines_index = %3ld space 2D\n", lines_index); - } - - *(colors_origin + 0) = 0; - *(colors_origin + 1) = 0; - *(colors_origin + 2) = 0; - - *(colors_origin + 3) = 1; - *(colors_origin + 4) = 1; - *(colors_origin + 5) = 1; - - *(colors_origin + (size_x - 1) * 6 + 0) = 1; - *(colors_origin + (size_x - 1) * 6 + 1) = 1; - *(colors_origin + (size_x - 1) * 6 + 2) = 1; - - *(colors_origin + (size_x - 1) * 6 + 3) = 0; - *(colors_origin + (size_x - 1) * 6 + 4) = 0; - *(colors_origin + (size_x - 1) * 6 + 5) = 0; - - colors_index += 12; if (V) printf(" => colors_index = %ld\n", colors_index); - - *(lines_origin + lines_index + 0) = 0; - *(lines_origin + lines_index + 1) = size_x * 2 - 2; // barre horizontale du bas - - *(lines_origin + lines_index + 2) = 1; - *(lines_origin + lines_index + 3) = size_x * 2 - 1; // barre horizontale du haut - - lines_index += 4; if (V) printf("H=> lines_index = %3ld space 2D H\n", lines_index); - - if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit - { - *(lines_origin + lines_index + 0) = 0; - *(lines_origin + lines_index + 1) = 3; - - *(lines_origin + lines_index + 2) = 1; - *(lines_origin + lines_index + 3) = 2; - - lines_index += 4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index); - - } - - if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit - { - *(lines_origin + lines_index + 0) = (size_x - 2) * 2 + 0; - *(lines_origin + lines_index + 1) = (size_x - 2) * 2 + 3; - - *(lines_origin + lines_index + 2) = (size_x - 2) * 2 + 1; - *(lines_origin + lines_index + 3) = (size_x - 2) * 2 + 2; - - lines_index +=4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index); - - } - - if (V) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x); - if (V) printf("space_2D lines_origin (%d - size_x(0)) x (%d - size_x(1)) ", 0, 1); - for (int v = 0; v < size_x + 2; v++) - if (V) printf("(%d-%d) ", *(lines_origin + v), *(lines_origin + v + 1)); - if (V) printf(" n = 4 + (%d x 2)\n", size_x + 2); - - return 1; -} - -static int compute_arrow_2D(int size_x, - int size_y, - int size_z, - - int weight, - int site, - int x, - int y, - int z, - - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *colors_origin, - GLuint *lines_origin, - GLuint *plans_origin) -{ - printf("compute_arrow_2D load = %d site = %d x = %d\n", weight, site, x); - float zero = 0.0f; - float center = (1.0f / size_x) * (2 * x - size_x + 2); - float tip = center + (2 * site - 1) * (1.0f / size_x - 0.01f); - float base = center + (2 * site - 1) * (0.1f / size_x); - float lat = 0.4f / size_x; - - /* for (int i = 0; i < size_x; i++) */ - /* for (int j = 0; j < size_y; j++) */ - /* for (int k = 0; k < size_z; k++) */ - /* { */ - - /* x = - ((size_x % 2) * (size_x / 2 - i) */ - /* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ - /* y = - ((size_x % 2) * (size_x / 2 - j) */ - /* - (size_x % 2 - 1) * (j + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ - /* z = - ((size_x % 2) * (size_x / 2 - k) */ - /* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ - /* } */ - - *(vertex_origin + vertex_index + 0) = tip; - *(vertex_origin + vertex_index + 1) = zero; - *(vertex_origin + vertex_index + 2) = zero; - - *(vertex_origin + vertex_index + 3) = base; - *(vertex_origin + vertex_index + 4) = lat; - *(vertex_origin + vertex_index + 5) = zero; - - *(vertex_origin + vertex_index + 6) = base; - *(vertex_origin + vertex_index + 7) = - lat; - *(vertex_origin + vertex_index + 8) = zero; - - vertex_index += 9; if (V) printf(" => vertex_index = %3ld arrow_2D\n", vertex_index); - - if (pref_style_lines_planes == 0) { - - if (V) printf("0=> lines_index = %ld\n", lines_index); - - *(lines_origin + lines_index + 0) = vertex_index / 3 - 3; - *(lines_origin + lines_index + 1) = vertex_index / 3 - 2; - - *(lines_origin + lines_index + 2) = vertex_index / 3 - 3; - *(lines_origin + lines_index + 3) = vertex_index / 3 - 1; - - *(lines_origin + lines_index + 4) = vertex_index / 3 - 2; - *(lines_origin + lines_index + 5) = vertex_index / 3 - 1; - - lines_index += 6; if (V) printf("|=> lines_index = %3ld arrow_2D\n", lines_index); - } - - - if (pref_style_lines_planes == 1) { - *(plans_origin + plans_index + 0) = vertex_index / 3 + 0; - *(plans_origin + plans_index + 1) = vertex_index / 3 + 1; - *(plans_origin + plans_index + 2) = vertex_index / 3 + 2; - - *(plans_origin + plans_index + 3) = vertex_index / 3 + 0; - *(plans_origin + plans_index + 4) = vertex_index / 3 + 1; - *(plans_origin + plans_index + 5) = vertex_index / 3 + 2; - - plans_index += 6; if (V) printf("|=> plans_index = %ld\n", plans_index); - } - return 0; -} - - /* x = - ((size_x % 2) * (size_x / 2 - i) */ - /* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ - /* y = - ((size_y % 2) * (size_y / 2 - j) */ - /* - (size_y % 2 - 1) * (j + 0.5f - size_y / 2)) / size_y * 2 * EDGE; */ - /* z = - ((size_z % 2) * (size_z / 2 - k) */ - /* - (size_z % 2 - 1) * (k + 0.5f - size_z / 2)) / size_z * 2 * EDGE; */ - -static bool compute_arrow_3D(long size_x, - long size_y, - long size_z, - - int weight, - int site, // North, South, East, West, Zenith, nAdir (NSEWZA) - long x, - long y, - long z, - - int pref_style_lines_planes, - int pref_style_mix_colors, - - GLfloat *vertex_origin, - GLfloat *colors_origin, - GLuint *lines_origin, - GLuint *plans_origin) - -{ - float zero = 0.0f; - float center = (1.0f / size_x) * (2 * x - size_x + 2); - float tip = center + (2 * site - 1) * (1.0f / size_x); - float base = center + (2 * site - 1) * (0.1f / size_x); - - *(vertex_origin + vertex_index + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f); - *(vertex_origin + vertex_index + 1) = zero; - *(vertex_origin + vertex_index + 2) = zero; - - *(vertex_origin + vertex_index + 3) = base; - *(vertex_origin + vertex_index + 4) = 0.4f / size_x; - *(vertex_origin + vertex_index + 5) = 0.4f / size_x; - - *(vertex_origin + vertex_index + 6) = base; - *(vertex_origin + vertex_index + 7) = 0.4f / size_x; - *(vertex_origin + vertex_index + 8) = - 0.4f / size_x; - - *(vertex_origin + vertex_index + 9) = base; - *(vertex_origin + vertex_index + 10) = - 0.4f / size_x; - *(vertex_origin + vertex_index + 11) = - 0.4f / size_x; - - *(vertex_origin + vertex_index + 12) = base; - *(vertex_origin + vertex_index + 13) = - 0.4f / size_x; - *(vertex_origin + vertex_index + 14) = 0.4f / size_x; - - vertex_index += 15; if (V) printf(" => vertex_index = %3ld arrow_3D\n", vertex_index); - - if (V) printf("center = %f tip = %f base = %f\n",\ - center, tip, base); // size_x * 12=%d igap=%d - - if (pref_style_lines_planes == 0) { - - *(lines_origin + lines_index + 0) = vertex_index / 3 - 5; - *(lines_origin + lines_index + 1) = vertex_index / 3 - 4; - - *(lines_origin + lines_index + 2) = vertex_index / 3 - 5; - *(lines_origin + lines_index + 3) = vertex_index / 3 - 3; - - *(lines_origin + lines_index + 4) = vertex_index / 3 - 5; - *(lines_origin + lines_index + 5) = vertex_index / 3 - 2; - - *(lines_origin + lines_index + 6) = vertex_index / 3 - 5; - *(lines_origin + lines_index + 7) = vertex_index / 3 - 1; - - *(lines_origin + lines_index + 8) = vertex_index / 3 - 4; - *(lines_origin + lines_index + 9) = vertex_index / 3 - 3; - - *(lines_origin + lines_index + 10) = vertex_index / 3 - 3; - *(lines_origin + lines_index + 11) = vertex_index / 3 - 2; - - *(lines_origin + lines_index + 12) = vertex_index / 3 - 2; - *(lines_origin + lines_index + 13) = vertex_index / 3 - 1; - - *(lines_origin + lines_index + 14) = vertex_index / 3 - 1; - *(lines_origin + lines_index + 15) = vertex_index / 3 - 4; - - lines_index += 16; if (V) printf("|=> lines_index = %3ld arrow_3D\n", lines_index); - } - - if (pref_style_lines_planes == 1) { - - *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0; - *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1; - *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 2; - - *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0; - *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 3; - *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4; - - *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0; - *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1; - *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 3; - - *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0; - *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 2; - *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4; - - plans_index += 12; if (V) printf("|=> plans_index = %3ld arrow_3D\n", plans_index); - } - - return 1; -} - -static void old_arrows(int model_arrows_nb, - long model_size_x, long model_size_y, long model_size_z, - int pref_style_lines_planes, int pref_style_mix_colors, - GLuint *arrows, GLfloat *vertex_origin, GLfloat *colors_origin, - GLuint *lines_origin, GLuint *plans_origin) -{ - for (int i = 0; i < model_arrows_nb; i++) - compute_arrow_3D (model_size_x, - model_size_y, - model_size_z, - - *(arrows + i * 5 + 0), // weight (load) - *(arrows + i * 5 + 1), // site - *(arrows + i * 5 + 2), // x - *(arrows + i * 5 + 3), // y - *(arrows + i * 5 + 4), // z - - pref_style_lines_planes, - pref_style_mix_colors, - - vertex_origin, - colors_origin, - lines_origin, - plans_origin); - -} - - - // OLD ARROWS (DEPRECATED) - /* old_arrows (model_arrows_nb, model_size_x, model_size_y, model_size_z, arrows, */ - /* pref_style_lines_planes, pref_style_mix_colors, */ - /* vertex_origin, colors_origin, lines_origin, plans_origin); */ - - - - -