Reprise de l'étude des shaders avec la version OK de la fonction set_arrow()
This commit is contained in:
parent
babdaca5b7
commit
1cd59ca012
|
@ -32,240 +32,15 @@
|
||||||
#define VERTEX_SHADER_FILE "src/shaders/shader.vert"
|
#define VERTEX_SHADER_FILE "src/shaders/shader.vert"
|
||||||
#define FRAG_SHADER_FILE "src/shaders/shader.frag"
|
#define FRAG_SHADER_FILE "src/shaders/shader.frag"
|
||||||
|
|
||||||
static int model_space_size_x = 0;
|
|
||||||
static int model_space_size_y = 0;
|
|
||||||
static int model_space_size_z = 0;
|
|
||||||
|
|
||||||
static GLfloat *buffer_vertex_origin = NULL;
|
static GLfloat *buffer_vertex_origin = NULL;
|
||||||
static GLfloat *buffer_colors_origin = NULL;
|
static GLfloat *buffer_colors_origin = NULL;
|
||||||
static GLuint *buffer_lines_origin = NULL;
|
static GLuint *buffer_lines_origin = NULL;
|
||||||
static GLuint *buffer_plans_origin = NULL;
|
static GLuint *buffer_plans_origin = NULL;
|
||||||
|
|
||||||
static int pref_show_grids = 0;
|
|
||||||
|
|
||||||
static volatile int buffer_vertex_size = 0;
|
static volatile int buffer_vertex_size = 0;
|
||||||
static int buffer_colors_size = 0;
|
static volatile int buffer_lines_size = 0;
|
||||||
static int buffer_lines_size = 0;
|
static volatile int buffer_colors_size = 0;
|
||||||
static int buffer_plans_size = 0;
|
static volatile int buffer_plans_size = 0;
|
||||||
|
|
||||||
// assert : l'emplacement des flèches est contraint
|
|
||||||
// par model_space_size_x, y, z et le nombre de sites
|
|
||||||
static GLuint arrows[] = {};
|
|
||||||
static GLuint arrows_init[] = {
|
|
||||||
1, 0, 0, 0, 0,
|
|
||||||
1, 1, 1, 0, 0,
|
|
||||||
/* 1, 1, 0, 0, 0, */
|
|
||||||
/* 1, 2, 0, 0, 0, */
|
|
||||||
/* 1, 3, 0, 0, 0, */
|
|
||||||
/* 1, 4, 0, 0, 0, */
|
|
||||||
/* 1, 5, 0, 0, 0, */
|
|
||||||
// load, site, x, y, z
|
|
||||||
};
|
|
||||||
|
|
||||||
static int get_arrows_nb(){
|
|
||||||
if (sizeof(arrows) == 0) return 0;
|
|
||||||
else return sizeof(arrows) / sizeof(arrows[0]) / 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_arrows_init_nb(){
|
|
||||||
if (sizeof(arrows_init) == 0) return 0;
|
|
||||||
else return sizeof(arrows_init) / sizeof(arrows_init[0]) / 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void show_user_choices(int space_size_x,
|
|
||||||
int space_size_y,
|
|
||||||
int space_size_z,
|
|
||||||
int prefer)
|
|
||||||
{
|
|
||||||
int arrows_nb = get_arrows_nb();
|
|
||||||
printf("model + user constraints : space size x,y,z = %d,%d,%d ", space_size_x, space_size_y, space_size_z);
|
|
||||||
if (arrows_nb > 0) printf("[%d] arrows ", arrows_nb);
|
|
||||||
if (prefer == 0) printf("prefer = %d <> show all grids ", prefer);
|
|
||||||
if (prefer == 1) printf("prefer = %d <> show no grid ", prefer);
|
|
||||||
if (prefer > 1) printf("pref_show_grids = %d ", prefer);
|
|
||||||
if (arrows_nb == 0) printf("\tbuffer_vertex_size = %d\t lines = %d\n", buffer_vertex_size, buffer_lines_size);
|
|
||||||
if (arrows_nb > 0) printf("\n [ n] load | site x y z \n -------------------------------\n");
|
|
||||||
for (int i = 0; i < arrows_nb; i++) printf(" [%2d] = %2d | %2d %2d %2d %2d\n",\
|
|
||||||
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
|
|
||||||
if (arrows_nb > 0) printf(" -------------------------------\n");}
|
|
||||||
|
|
||||||
static int set_arrow (int weight, int site, int x, int y, int z);
|
|
||||||
|
|
||||||
static void get_model_data_and_user_preferences()
|
|
||||||
{
|
|
||||||
model_space_size_x = 2; // 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
|
|
||||||
pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
|
||||||
// xyz, 0, x, y, z, xy, xz, yz, xyz
|
|
||||||
show_user_choices(model_space_size_x, model_space_size_y, model_space_size_z,
|
|
||||||
pref_show_grids);
|
|
||||||
|
|
||||||
// set_arrow(1, 3, 1, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DETAIL 0
|
|
||||||
static bool rewrite_arrow (int address, int weight, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
if (DETAIL) printf("write the arrow weight to %d at (%d, %d, %d, %d)\n",\
|
|
||||||
weight, site, x, y, z);
|
|
||||||
|
|
||||||
*(arrows + address + 0) = weight;
|
|
||||||
|
|
||||||
return 1; /* replaces the load of the existing arrow by the load 'weight' */
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool create_arrow (int weight, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
int arrows_nb = get_arrows_nb();
|
|
||||||
arrows_nb ++;
|
|
||||||
buffer_lines_size += (3 + 4) * 8 * sizeof(GLuint);
|
|
||||||
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size);
|
|
||||||
|
|
||||||
if (1) printf("create a new arrow with weight = %d at (%d, %d, %d, %d)\n",\
|
|
||||||
weight, site, x, y, z);
|
|
||||||
|
|
||||||
*(arrows + arrows_nb * 5 + 0) = weight;
|
|
||||||
*(arrows + arrows_nb * 5 + 1) = site;
|
|
||||||
*(arrows + arrows_nb * 5 + 2) = x;
|
|
||||||
*(arrows + arrows_nb * 5 + 3) = y;
|
|
||||||
*(arrows + arrows_nb * 5 + 4) = z;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool erase_arrow (int address, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
int arrows_nb = get_arrows_nb();
|
|
||||||
if (DETAIL) printf("erase arrow at address %d with values (%d, %d, %d, %d)",\
|
|
||||||
address / 5, site, x, y, z);
|
|
||||||
if (DETAIL) printf(" last arrow is %d, %d, %d, %d, %d\n",
|
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 0),
|
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 1),
|
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 2),
|
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 3),
|
|
||||||
*(arrows + (arrows_nb - 1) * 5 + 4));
|
|
||||||
|
|
||||||
*(arrows + address + 0) = *(arrows + (arrows_nb - 1) * 5 + 0);
|
|
||||||
*(arrows + address + 1) = *(arrows + (arrows_nb - 1) * 5 + 1);
|
|
||||||
*(arrows + address + 2) = *(arrows + (arrows_nb - 1) * 5 + 2);
|
|
||||||
*(arrows + address + 3) = *(arrows + (arrows_nb - 1) * 5 + 3);
|
|
||||||
*(arrows + address + 4) = *(arrows + (arrows_nb - 1) * 5 + 4);
|
|
||||||
|
|
||||||
arrows_nb --;
|
|
||||||
buffer_lines_size -= (3 + 4) * 2;
|
|
||||||
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * 2 * sizeof(GLuint));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_for_arrow (int weight, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
int arrows_nb = get_arrows_nb();
|
|
||||||
if (arrows_nb == 0) return -1;
|
|
||||||
|
|
||||||
int 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_weight == weight && f_site == site && f_x == x && f_y == y && f_z == z) {
|
|
||||||
address = i * 5;
|
|
||||||
if (DETAIL) printf("arrows_nb = %d checked arrow (%d,%d,%d,%d) found at address %d (line %d)",\
|
|
||||||
arrows_nb, site, x, y, z, address, address / 5);
|
|
||||||
if (DETAIL && f_weight > 1) printf(" weight = %d", f_weight);
|
|
||||||
if (DETAIL) printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return address; /* returns the address of the arrow if there is one
|
|
||||||
* or (-1) if there is none */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void show_arrows_array (int address, int weight, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
int arrows_nb = get_arrows_nb();
|
|
||||||
int arrows_init_nb = get_arrows_init_nb();
|
|
||||||
printf("\n [ n] load | site x y z ----- < arrows_nb = %d > ------", arrows_nb);
|
|
||||||
if (arrows_nb == 0) printf("--------------------------- no arrows\n");
|
|
||||||
else if (address == -1) printf("--------------------------- create new arrow\n");
|
|
||||||
else printf("--------------------------- erase arrow at address = %d / 5\n", address);
|
|
||||||
|
|
||||||
for (int i = 0; i < arrows_init_nb; i++)
|
|
||||||
{
|
|
||||||
printf(" [%2d] = %2d | %2d, %2d, %2d, %2d ",\
|
|
||||||
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
|
||||||
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
|
|
||||||
if (weight == 0 && i == address / 5) printf(" <<<| < - > (%d, %d, %d, %d) @ [%d]",\
|
|
||||||
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
|
||||||
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
|
|
||||||
if (weight > 0 && i == arrows_nb - 1) printf(" <<< < + > (%d, %d, %d, %d) @ [%d]",\
|
|
||||||
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2),\
|
|
||||||
*(arrows + i * 5 + 3), *(arrows + i * 5 + 4), address / 5);
|
|
||||||
if (weight == 0 && i > address / 5 && i < arrows_nb - 1) printf(" |");
|
|
||||||
if (weight == 0 && i == arrows_nb - 1 && i != address / 5) printf(" >>>|");
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int set_arrow (int weight, int site, int x, int y, int z)
|
|
||||||
{
|
|
||||||
int address = (check_for_arrow (weight, site, x, y, z));
|
|
||||||
// show_arrows_array(address, weight, site, x, y, z);
|
|
||||||
|
|
||||||
if (address == -1 && weight == 0) return 0;
|
|
||||||
// if (address == -1 && weight > 0) return create_arrow (weight, site, x, y, z);
|
|
||||||
if (address >= 0 && weight == 0) return erase_arrow (address, site, x, y, z);
|
|
||||||
if (address >= 0 && weight > 0) return rewrite_arrow (address, weight, site, x, y, z);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dynamic array of ptrs to dynamically allocated gl_area_entry
|
* Dynamic array of ptrs to dynamically allocated gl_area_entry
|
||||||
|
@ -333,6 +108,12 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id,
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* void graphics_erase_line (GLuint a, GLuint b){} TODO and to use ?
|
||||||
|
* As, in this version only lines can be erased,
|
||||||
|
* similar functions for vertex and plans are not considered. But ?...
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Writes values to describe a line from a to b into the line buffer
|
* Writes values to describe a line from a to b into the line buffer
|
||||||
*
|
*
|
||||||
|
@ -428,8 +209,6 @@ void graphics_init_buffers(const void *gl_area)
|
||||||
struct gl_area_entry *entry;
|
struct gl_area_entry *entry;
|
||||||
entry = graphics_find_glarea_from_ptr(gl_area);
|
entry = graphics_find_glarea_from_ptr(gl_area);
|
||||||
|
|
||||||
get_model_data_and_user_preferences();
|
|
||||||
|
|
||||||
//XXX
|
//XXX
|
||||||
main_test_graphics ();
|
main_test_graphics ();
|
||||||
|
|
||||||
|
@ -765,73 +544,282 @@ bool graphics_shutdown(const void *gl_area)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void main_test_graphics (void)
|
/*
|
||||||
|
* Prints the arrows[] array
|
||||||
|
*
|
||||||
|
* For each arrow the following parameters are displayed :
|
||||||
|
* - rank in the array
|
||||||
|
* - weight (or load)
|
||||||
|
* - coordinates in space (site, x, y, z)
|
||||||
|
*/
|
||||||
|
static void show_arrows_array (GLuint *arrows, int arrows_nb, int x, int y, int z)
|
||||||
{
|
{
|
||||||
long weight = 0, site = 0,
|
printf("\n [rank] load | site x y z");
|
||||||
x = model_space_size_x,
|
for (int i = 0; i < arrows_nb; i++)
|
||||||
y = model_space_size_y,
|
printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, *(arrows + i * 5 + 0),\
|
||||||
z = model_space_size_z;
|
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
|
||||||
long stx = z * y,
|
if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---");
|
||||||
sty = z,
|
}
|
||||||
stz = 1;
|
|
||||||
long arrow_offset = 0;
|
|
||||||
|
|
||||||
if (0) printf("buffer_vertex_offset_before_grid = %d\n", buffer_vertex_size / 3);
|
/*
|
||||||
|
* Prints the initial user choices :
|
||||||
|
* - space dimension size and appearance (grids)
|
||||||
|
* - arrows[] array
|
||||||
|
* NB The space may be empty or saturated with arrows or any value in between
|
||||||
|
* Only one arrow per possible coordinates with a load max equal to ? TODO
|
||||||
|
*/
|
||||||
|
static void show_user_choices(GLuint *arrows, int arrows_nb,
|
||||||
|
int space_size_x, int space_size_y, int space_size_z,
|
||||||
|
int prefer, int show_all)
|
||||||
|
{
|
||||||
|
printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\t", space_size_x, space_size_y, space_size_z);
|
||||||
|
if (prefer == 0) printf("prefer = %d <> show all grids", prefer);
|
||||||
|
if (prefer == 1) printf("prefer = %d <> show no grid", prefer);
|
||||||
|
if (prefer > 1) printf("show grids according rule (%d)", prefer);
|
||||||
|
if (show_all) printf("\n\
|
||||||
|
initial arrows data arrows_nb = %d", arrows_nb);
|
||||||
|
show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z);
|
||||||
|
}
|
||||||
|
|
||||||
/* GRID */
|
/*
|
||||||
grid_write_intersections (x, y, z);
|
* Prints the result of the function set_arrow()
|
||||||
|
* and indicates the reasons of the choice (call) this function makes (see this function)
|
||||||
|
*/
|
||||||
|
static void show_user_action(GLuint *arrows, int arrows_nb, int address, int requested_weight,
|
||||||
|
int current_weight, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
if (address == -1 && requested_weight > 0) {printf("no such arrow found (%d,%d,%d,%d)\n\
|
||||||
|
requested weight == %d => CREATE",\
|
||||||
|
arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], requested_weight); return;}
|
||||||
|
|
||||||
if (pref_show_grids % 2 == 0) grid_write_x (x, y, z);
|
if (address >= 0 && requested_weight == 0) {printf("arrow (%d,%d,%d,%d) found at address %d; current_weight = %d;\n\
|
||||||
if (pref_show_grids % 3 == 0) grid_write_y (x, y, z);
|
requested weight == %d => ERASE",\
|
||||||
if (pref_show_grids % 5 == 0) grid_write_z (x, y, z);
|
arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight, requested_weight); return;}
|
||||||
|
|
||||||
if (pref_show_grids > 0) grid_write_ridges (x, y, z);
|
if (address >= 0 && current_weight != requested_weight) {printf("arrow (%d,%d,%d,%d) found at address %d; current_weight = %d;\n\
|
||||||
|
requested weight != current weight => MODIFY",\
|
||||||
|
arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight); return;}
|
||||||
|
|
||||||
int offset_after_grids = buffer_vertex_size / 3;
|
if (address >= 0 && current_weight == requested_weight){
|
||||||
|
printf("arrow (%d,%d,%d,%d) found at address %d;\n\
|
||||||
|
requested_weight == current_weight => END",\
|
||||||
|
arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5); return;}
|
||||||
|
|
||||||
if (1) printf("buffer_vertex_offset_after grids = %d (x+1)*(y+1)*(z+1) = %ld\n",\
|
if (address == -1 && requested_weight == 0) {printf("no such arrow found (%d,%d,%d,%d)\n\
|
||||||
offset_after_grids, (x+1)*(y+1)*(z+1));
|
requested weight == 0 => END",\
|
||||||
|
arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]); return;}
|
||||||
/* ARROWS */
|
}
|
||||||
arrows_write_terminations (x, y, z);
|
|
||||||
|
|
||||||
int arrows_init_nb = get_arrows_init_nb(), cube_coord = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < arrows_init_nb; i++) {
|
|
||||||
weight = arrows_init[i * 5 + 0];
|
|
||||||
site = arrows_init[i * 5 + 1];
|
|
||||||
x = arrows_init[i * 5 + 2];
|
|
||||||
y = arrows_init[i * 5 + 3];
|
|
||||||
z = arrows_init[i * 5 + 4];
|
|
||||||
|
|
||||||
// set_arrow (weight, site, x, y, z);
|
|
||||||
|
|
||||||
cube_coord = 12 * (stx * x + sty * y + stz * z);
|
|
||||||
arrow_offset = offset_after_grids + cube_coord;
|
|
||||||
arrows_write_basis (arrow_offset);
|
|
||||||
|
|
||||||
switch(site){
|
|
||||||
case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, 1, site); break;
|
|
||||||
case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (arrow_offset, 1, site); break;
|
|
||||||
case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, 1, site); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prints vertex and lines buffers_states (sizes) at major steps and at the end of a session.
|
||||||
|
* Major steps are creation of grids and creation of arrows
|
||||||
|
* Arithmetic verification is provided at each step
|
||||||
|
*/
|
||||||
|
static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrows_nb,
|
||||||
|
int offset_after_grids, int buffer_vertex_size,
|
||||||
|
int buffer_lines_size_after_cubes, int buffer_lines_size)
|
||||||
|
{
|
||||||
int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids;
|
int offset_after_arrows = buffer_vertex_size / 3, difference = offset_after_arrows - offset_after_grids;
|
||||||
// TODO Qu'est-ce que j'affiche, là ?! < À vérifier
|
|
||||||
if (1) printf("buffer_vertex_offset_after arrows = %d (%d - %d = %d, %d / 12 = %d cubes)\n",\
|
printf("\n - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||||
|
printf("\n buffer_vertex_offset_after grids = %6d\t%6d = (x+1)*(y+1)*(z+1); <--> (x,y,z = %d,%d,%d)",\
|
||||||
|
offset_after_grids, (space_X + 1)*(space_Y + 1)*(space_Z + 1), space_X, space_Y, space_Z);
|
||||||
|
|
||||||
|
printf("\n buffer_vertex_offset_after arrows = %6d\t%6d = %d + %d; <--> %d = 12 x %d (there are %d cubes)",\
|
||||||
offset_after_arrows, offset_after_arrows, offset_after_grids,\
|
offset_after_arrows, offset_after_arrows, offset_after_grids,\
|
||||||
difference, difference, difference / 12);
|
difference, difference, difference / 12, difference / 12);
|
||||||
if (0) printf("main_test_graphics [ok]\n");
|
|
||||||
if (1) printf("\n Et maintenant, il faut distinguer les arrows-data des arrows-en-place\n\
|
printf("\n buffer_lines_offset after cubes = %6d\t%6d = 2 * (%dx%d + %dx%d + %dx%d); <--> 2 * (x*y + x*z + y*z)",\
|
||||||
[to be] vs. [done]\n");
|
buffer_lines_size_after_cubes, ((space_X+1) * (space_Y+1) + (space_X+1) * (space_Z+1) + (space_Y+1) * (space_Z+1)) * 2,
|
||||||
if (1) printf("\n Et donc... Les flèches sont dessinées dans main_test_graphics()\n\
|
space_X+1, space_Y+1, space_X+1, space_Z+1, space_Y+1, space_Z+1);
|
||||||
et pas dans set_arrow (weight, site, x, y, z);\n\
|
|
||||||
(qui sert à quoi ? au fait ... ) \n\n");
|
printf("\n buffer_lines_offset after arrows = %6d\t%6d = %d + %d; <--> %d = (3 + 4) x 2 x %d (arrows_nb = %d)\n",\
|
||||||
|
buffer_lines_size, buffer_lines_size, buffer_lines_size_after_cubes,\
|
||||||
|
buffer_lines_size - buffer_lines_size_after_cubes, arrows_nb * 14, arrows_nb, arrows_nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Assigns a new weight to the arrow at address (address)
|
||||||
|
*/
|
||||||
|
static int rewrite_arrow (GLuint *arrows, int arrows_nb, int address, int weight, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
*(arrows + address * 5 + 0) = weight;
|
||||||
|
|
||||||
|
show_arrows_array (arrows, arrows_nb, x, y, z);
|
||||||
|
|
||||||
|
return arrows_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates a new arrow at address (address)
|
||||||
|
* NB Weights (or loads) are NOT added
|
||||||
|
*/
|
||||||
|
static int create_arrow (GLuint *arrows, int arrows_nb, int weight, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
||||||
|
|
||||||
|
assert (buffer_lines_origin); assert (buffer_lines_size);
|
||||||
|
|
||||||
|
*(arrows + arrows_nb * 5 + 0) = weight;
|
||||||
|
*(arrows + arrows_nb * 5 + 1) = site;
|
||||||
|
*(arrows + arrows_nb * 5 + 2) = x;
|
||||||
|
*(arrows + arrows_nb * 5 + 3) = y;
|
||||||
|
*(arrows + arrows_nb * 5 + 4) = z;
|
||||||
|
|
||||||
|
arrows_nb ++;
|
||||||
|
|
||||||
|
show_arrows_array (arrows, arrows_nb, x, y, z);
|
||||||
|
|
||||||
|
return arrows_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes an arrow at address (address)
|
||||||
|
*/
|
||||||
|
static int erase_arrow (GLuint *arrows, int arrows_nb, int address, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
arrows_nb --;
|
||||||
|
|
||||||
|
if (arrows_nb > 0)
|
||||||
|
{
|
||||||
|
*(arrows + address + 0) = *(arrows + arrows_nb * 5 + 0);
|
||||||
|
*(arrows + address + 1) = *(arrows + arrows_nb * 5 + 1);
|
||||||
|
*(arrows + address + 2) = *(arrows + arrows_nb * 5 + 2);
|
||||||
|
*(arrows + address + 3) = *(arrows + arrows_nb * 5 + 3);
|
||||||
|
*(arrows + address + 4) = *(arrows + arrows_nb * 5 + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_lines_origin = g_realloc(buffer_lines_origin, buffer_lines_size * sizeof(GLuint));
|
||||||
|
|
||||||
|
show_arrows_array (arrows, arrows_nb, x, y, z);
|
||||||
|
|
||||||
|
return arrows_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calls one of the functions create_arrow(), erase_arrow() or rewrite_arrow()
|
||||||
|
* according to requested weight and address (coord site, x, y, z)
|
||||||
|
*
|
||||||
|
* May not call any of these three functions if :
|
||||||
|
* - Current_weight of an arrow located at the requested address == requested_weight
|
||||||
|
* - No arrow was found at the requested addres AND current_weight == requested_weight
|
||||||
|
*/
|
||||||
|
static int set_arrow (GLuint *arrows, int arrows_nb, int requested_weight, int site, int x, int y, int z)
|
||||||
|
{
|
||||||
|
int address = -1, current_weight = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < arrows_nb; i++) {
|
||||||
|
if ((site == *(arrows + i * 5 + 1))
|
||||||
|
&& (x == *(arrows + i * 5 + 2))
|
||||||
|
&& (y == *(arrows + i * 5 + 3))
|
||||||
|
&& (z == *(arrows + i * 5 + 4)))
|
||||||
|
{
|
||||||
|
address = i * 5;
|
||||||
|
current_weight = *(arrows + i * 5 + 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nset_arrow() invoked with requested weight = %d > ", requested_weight);
|
||||||
|
|
||||||
|
show_user_action(arrows, arrows_nb, address, requested_weight, current_weight, site, x, y, z);
|
||||||
|
|
||||||
|
if (address == -1 && requested_weight > 0)
|
||||||
|
return create_arrow (arrows, arrows_nb, requested_weight, site, x, y, z);
|
||||||
|
|
||||||
|
if (address >= 0 && requested_weight == 0)
|
||||||
|
return erase_arrow (arrows, arrows_nb, address, site, x, y, z);
|
||||||
|
|
||||||
|
if (address >= 0 && current_weight != requested_weight)
|
||||||
|
return rewrite_arrow (arrows, arrows_nb, address/5, requested_weight, site, x, y, z);
|
||||||
|
|
||||||
|
if (address >= 0 && current_weight == requested_weight) show_arrows_array(arrows, arrows_nb, x, y, z);
|
||||||
|
|
||||||
|
if (address == -1 && requested_weight == 0) show_arrows_array(arrows, arrows_nb, x, y, z);
|
||||||
|
|
||||||
|
return arrows_nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Init space and arrows (= initial state)
|
||||||
|
* and allows ulterior creations, suppressions or modifications of the arrows[] array
|
||||||
|
*
|
||||||
|
* Draws space and arrows
|
||||||
|
*/
|
||||||
|
void main_test_graphics (void)
|
||||||
|
{
|
||||||
|
// assert : space dimensions (x,y,z) > 0 TODO NOT checked before init
|
||||||
|
// assert : arrows localization within space and sites TODO NOT checked when invoking set_arrow()
|
||||||
|
// assert : no more than one arrow per address TODO NOT checked before init
|
||||||
|
// notify : weights are replaced, NOT added (could be !) TODO
|
||||||
|
|
||||||
|
int space_X = 4, space_Y = 1, space_Z = 1;
|
||||||
|
int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
||||||
|
// xyz, 0, x, y, z, xy, xz, yz, xyz
|
||||||
|
GLuint arrows[] = {
|
||||||
|
1, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 0, 0,
|
||||||
|
1, 0, 2, 0, 0,
|
||||||
|
1, 1, 3, 0, 0,
|
||||||
|
// load, site, x, y, z
|
||||||
|
};
|
||||||
|
int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5;
|
||||||
|
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1);
|
||||||
|
/* GRID */
|
||||||
|
grid_write_intersections (space_X, space_Y, space_Z);
|
||||||
|
if (pref_show_grids % 2 == 0) grid_write_x (space_X, space_Y, space_Z);
|
||||||
|
if (pref_show_grids % 3 == 0) grid_write_y (space_X, space_Y, space_Z);
|
||||||
|
if (pref_show_grids % 5 == 0) grid_write_z (space_X, space_Y, space_Z);
|
||||||
|
if (pref_show_grids > 0) grid_write_ridges (space_X, space_Y, space_Z);
|
||||||
|
int offset_after_grids = buffer_vertex_size / 3;
|
||||||
|
int buffer_lines_size_after_cubes = buffer_lines_size;
|
||||||
|
int offset_up_to_this_cube_coords = 0, x, y, z;
|
||||||
|
/* ARROWS */
|
||||||
|
/* NB The 12 vertices required to draw 6 arrows in each cube
|
||||||
|
* are always defined (whether arrows are drawn or not). */
|
||||||
|
arrows_write_terminations (space_X, space_Y, space_Z);
|
||||||
|
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 2, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 3, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 1, 0, 1, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 1, 1, 2, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 8, 1, 3, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 8, 1, 3, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 3, 0, 0);
|
||||||
|
arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0);
|
||||||
|
|
||||||
|
int weight = 0, site = 0,
|
||||||
|
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < arrows_nb; i++) {
|
||||||
|
weight = arrows[i * 5 + 0];
|
||||||
|
site = arrows[i * 5 + 1];
|
||||||
|
x = arrows[i * 5 + 2];
|
||||||
|
y = arrows[i * 5 + 3];
|
||||||
|
z = arrows[i * 5 + 4];
|
||||||
|
|
||||||
|
offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z);
|
||||||
|
arrow_offset = offset_after_grids + offset_up_to_this_cube_coords;
|
||||||
|
|
||||||
|
arrows_write_basis (arrow_offset);
|
||||||
|
|
||||||
|
switch(site){
|
||||||
|
case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, weight, site); break;
|
||||||
|
case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (arrow_offset, weight, site); break;
|
||||||
|
case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, weight, site); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
show_buffers_states(space_X, space_Y, space_Z, arrows_nb,
|
||||||
|
offset_after_grids, buffer_vertex_size,
|
||||||
|
buffer_lines_size_after_cubes, buffer_lines_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue