WIP: Je crois bien que la fonction 'erase_arrow' est arrivée.
This commit is contained in:
parent
f030bd72fb
commit
945e7be9ad
|
@ -26,7 +26,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
bool compute_space_and_arrows(long model_space_size_x,
|
bool compute_space(long model_space_size_x,
|
||||||
long model_space_size_y,
|
long model_space_size_y,
|
||||||
long model_space_size_z,
|
long model_space_size_z,
|
||||||
|
|
||||||
|
@ -48,3 +48,6 @@ bool draw_some_arrows (GLuint *lines_origin,
|
||||||
long s, long stx, long sty,
|
long s, long stx, long sty,
|
||||||
GLuint *arrows, int arrows_nb);
|
GLuint *arrows, int arrows_nb);
|
||||||
|
|
||||||
|
void show_user_choices(long model_size_x, long model_size_y, long model_size_z,
|
||||||
|
GLuint *arrows, int model_arrows_nb, int pref_show_grid);
|
||||||
|
|
||||||
|
|
|
@ -440,33 +440,6 @@ static void draw_a_central_star(GLuint *lines_origin, long n)
|
||||||
#define SOUTH 4 // + z jaune
|
#define SOUTH 4 // + z jaune
|
||||||
#define NORTH 5 // - z bleu
|
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool draw_some_arrows (GLuint *lines_origin, long s, long stx, long sty,
|
bool draw_some_arrows (GLuint *lines_origin, long s, long stx, long sty,
|
||||||
GLuint *arrows, int arrows_nb)
|
GLuint *arrows, int arrows_nb)
|
||||||
{
|
{
|
||||||
|
@ -506,17 +479,8 @@ bool draw_some_arrows (GLuint *lines_origin, long s, long stx, long sty,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void show_user_choices(long model_size_x,
|
void show_user_choices(long model_size_x, long model_size_y, long model_size_z,
|
||||||
long model_size_y,
|
GLuint *arrows, int model_arrows_nb, int pref_show_grid)
|
||||||
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);
|
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);
|
||||||
|
@ -543,16 +507,9 @@ static void show_user_choices(long model_size_x,
|
||||||
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(...)',\
|
printf("NB If you play : 'draw_some_arrows(...)' and add some more arrows (in graphics.c below line 571),\
|
||||||
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\
|
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");
|
The 'central_stars_nb' is automatically set equal to the number_of_arrows (line 559).\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -563,7 +520,7 @@ static void show_user_choices(long model_size_x,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_size_z,
|
bool compute_space(long model_size_x, long model_size_y, long model_size_z,
|
||||||
|
|
||||||
GLuint *arrows, int model_arrows_nb,
|
GLuint *arrows, int model_arrows_nb,
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@
|
||||||
int model_space_size_x = 0;
|
int model_space_size_x = 0;
|
||||||
int model_space_size_y = 0;
|
int model_space_size_y = 0;
|
||||||
int model_space_size_z = 0;
|
int model_space_size_z = 0;
|
||||||
int model_arrows_nb = 0;
|
int arrows_nb = 0;
|
||||||
int nombre_de_cases_contenant_des_fleches = 0;
|
int central_stars_nb = 0;
|
||||||
|
|
||||||
GLfloat *buffer_vertex_origin = NULL;
|
GLfloat *buffer_vertex_origin = NULL;
|
||||||
GLfloat *buffer_colors_origin = NULL;
|
GLfloat *buffer_colors_origin = NULL;
|
||||||
|
@ -209,7 +209,7 @@ bool graphics_init(const char *gl_area)
|
||||||
// Check if not already initialized
|
// Check if not already initialized
|
||||||
if (find_entry_from_ptr(gl_area)) {
|
if (find_entry_from_ptr(gl_area)) {
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
perror("gl_area_array already exists");
|
perror("gl_area_array already address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,16 +548,17 @@ static void get_model_data_and_user_preferences(){
|
||||||
|
|
||||||
model_space_size_x = 4; // 0 < model_space_size_x
|
model_space_size_x = 4; // 0 < model_space_size_x
|
||||||
model_space_size_y = 3; // 0 < model_space_size_y
|
model_space_size_y = 3; // 0 < model_space_size_y
|
||||||
model_space_size_z = 3; // 0 < model_space_size_z
|
model_space_size_z = 2; // 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
|
arrows_nb = 12; // 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 sera à calculer pour éviter de redessiner les central_stars TODO
|
||||||
// ! WARNING ! Pour l'instant égal au nombre de flèches ! (central stars réécrites)
|
central_stars_nb = arrows_nb; // ! WARNING ! Pour l'instant égal au nombre de flèches !
|
||||||
nombre_de_cases_contenant_des_fleches = model_arrows_nb;
|
// (les "central stars" sont donc systématiquement redessinées
|
||||||
|
// s'il y a plusieurs flèches dans le même cube)
|
||||||
|
|
||||||
// pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both
|
// 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_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix
|
||||||
|
@ -572,11 +573,14 @@ GLuint arrows[] = {
|
||||||
1, 1, 1, 0, 0,
|
1, 1, 1, 0, 0,
|
||||||
1, 2, 2, 1, 1,
|
1, 2, 2, 1, 1,
|
||||||
1, 3, 2, 2, 1,
|
1, 3, 2, 2, 1,
|
||||||
1, 4, 3, 0, 1,
|
1, 4, 3, 0, 0,
|
||||||
1, 5, 3, 0, 2,
|
1, 5, 3, 0, 1,
|
||||||
1, 1, 3, 0, 2,
|
1, 1, 3, 0, 0,
|
||||||
1, 0, 2, 0, 2,
|
1, 0, 2, 0, 0,
|
||||||
1, 5, 2, 1, 1,
|
1, 5, 2, 1, 1,
|
||||||
|
1, 4, 2, 1, 0,
|
||||||
|
1, 4, 0, 1, 0,
|
||||||
|
1, 5, 0, 1, 1,
|
||||||
// load, site, x, y, z
|
// load, site, x, y, z
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -590,7 +594,7 @@ 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 arrows_nb,
|
||||||
|
|
||||||
// int pref_mark_unit_space,
|
// int pref_mark_unit_space,
|
||||||
// int pref_style_lines_planes,
|
// int pref_style_lines_planes,
|
||||||
|
@ -608,10 +612,10 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
* (6 + 6); // 6 is to draw the small central star
|
* (6 + 6); // 6 is to draw the small central star
|
||||||
// 6 is for the six faces centers
|
// 6 is for the six faces centers
|
||||||
|
|
||||||
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)
|
// + cubes_nb * (8 + 6) + 15 * arrows_nb;// OLD ARROWS (DEPRECATED)
|
||||||
buffer_vertex_size += arrows_anchors * 3;
|
buffer_vertex_size += arrows_anchors * 3;
|
||||||
|
|
||||||
buffer_vertex_size += 8 * 3; // draw a small cube
|
buffer_vertex_size += 8 * 3; // draw a small cube
|
||||||
|
@ -632,9 +636,9 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
|
|
||||||
if (pref_test_diagonal) buffer_lines_size += 2; // la diagonale test [0 - max]
|
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 += 6 * central_stars_nb; // test central stars
|
||||||
|
|
||||||
buffer_lines_size += 8 * model_arrows_nb; // flèches
|
buffer_lines_size += 8 * arrows_nb; // flèches
|
||||||
|
|
||||||
// buffer_lines_size += 16 + 20; // draw a small cube with diagonals
|
// buffer_lines_size += 16 + 20; // draw a small cube with diagonals
|
||||||
|
|
||||||
|
@ -650,11 +654,89 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static bool rewrite_arrow (GLuint *arrows, int arrows_nb,
|
||||||
|
long address, long weight,
|
||||||
|
long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
printf("write the arrow weight to %ld at (%ld, %ld, %ld, %ld)\n",\
|
||||||
|
weight, site, x, y, z);
|
||||||
|
return 1; /* replaces the load of the existing arrow by the load 'weight' */
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool create_arrow (GLuint *arrows, int arrows_nb,
|
||||||
|
long weight, long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
printf("create a new arrow with weight = %ld at (%ld, %ld, %ld, %ld)\n",\
|
||||||
|
weight, site, x, y, z);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool erase_arrow (GLuint *arrows, int arrows_nb, long address,
|
||||||
|
long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
if (1) printf("erase arrow at address %ld with values (%ld, %ld, %ld, %ld)\n",\
|
||||||
|
address / 5, site, x, y, z);
|
||||||
|
if (1) 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 + (arrows_nb - 1) * 5 + 0) = 0; // est-ce bien utile ?
|
||||||
|
*(arrows + (arrows_nb - 1) * 5 + 1) = 0;
|
||||||
|
*(arrows + (arrows_nb - 1) * 5 + 2) = 0;
|
||||||
|
*(arrows + (arrows_nb - 1) * 5 + 3) = 0;
|
||||||
|
*(arrows + (arrows_nb - 1) * 5 + 4) = 0;
|
||||||
|
|
||||||
|
arrows_nb --;
|
||||||
|
buffer_lines_size -= 14;
|
||||||
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint) * 2);
|
||||||
|
|
||||||
|
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
|
||||||
|
arrows, arrows_nb, pref_show_grid);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long check_for_arrow (GLuint *arrows, int arrows_nb,
|
||||||
|
long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
printf("found at %ld (%ld / 5 = %ld)\n", address, address, address / 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return address; /* returns the address of the arrow if there is one
|
||||||
|
* or (-1) if there is none */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool set_arrow (GLuint *arrows, int arrows_nb,
|
||||||
|
long weight, long site, long x, long y, long z)
|
||||||
|
{
|
||||||
|
long address = (check_for_arrow (arrows, arrows_nb, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -678,7 +760,7 @@ static void compute_buffers_sizes(int model_space_size_x,
|
||||||
* Note : buffer_lines_origin[] is no more defined in graphics_cube.h
|
* Note : buffer_lines_origin[] is no more defined in graphics_cube.h
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
#define A 0
|
|
||||||
void graphics_init_buffers(const void *gl_area)
|
void graphics_init_buffers(const void *gl_area)
|
||||||
{
|
{
|
||||||
struct gl_area_entry *entry;
|
struct gl_area_entry *entry;
|
||||||
|
@ -691,7 +773,7 @@ void graphics_init_buffers(const void *gl_area)
|
||||||
model_space_size_y,
|
model_space_size_y,
|
||||||
model_space_size_z,
|
model_space_size_z,
|
||||||
|
|
||||||
model_arrows_nb,
|
arrows_nb,
|
||||||
|
|
||||||
// pref_mark_unit_space,
|
// pref_mark_unit_space,
|
||||||
// pref_style_lines_planes,
|
// pref_style_lines_planes,
|
||||||
|
@ -703,12 +785,12 @@ void graphics_init_buffers(const void *gl_area)
|
||||||
buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLuint) * 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);
|
buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLuint) * 2);
|
||||||
|
|
||||||
compute_space_and_arrows (model_space_size_x,
|
compute_space (model_space_size_x,
|
||||||
model_space_size_y,
|
model_space_size_y,
|
||||||
model_space_size_z,
|
model_space_size_z,
|
||||||
|
|
||||||
arrows,
|
arrows,
|
||||||
model_arrows_nb,
|
arrows_nb,
|
||||||
|
|
||||||
// pref_mark_unit_space,
|
// pref_mark_unit_space,
|
||||||
// pref_style_lines_planes,
|
// pref_style_lines_planes,
|
||||||
|
@ -729,7 +811,15 @@ void graphics_init_buffers(const void *gl_area)
|
||||||
|
|
||||||
draw_some_arrows (buffer_lines_origin, s,
|
draw_some_arrows (buffer_lines_origin, s,
|
||||||
model_space_size_z * model_space_size_y, model_space_size_z,
|
model_space_size_z * model_space_size_y, model_space_size_z,
|
||||||
arrows, model_arrows_nb);
|
arrows, arrows_nb);
|
||||||
|
|
||||||
|
set_arrow(arrows, arrows_nb, 0, 4, 3, 0, 0);
|
||||||
|
set_arrow(arrows, arrows_nb, 0, 5, 3, 0, 1);
|
||||||
|
|
||||||
|
draw_some_arrows (buffer_lines_origin, s,
|
||||||
|
model_space_size_z * model_space_size_y, model_space_size_z,
|
||||||
|
arrows, arrows_nb);
|
||||||
|
|
||||||
|
|
||||||
GLuint vao, vertex_buffer, color_buffer;
|
GLuint vao, vertex_buffer, color_buffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue