O K P R I N T I N G + O K D R A W I N G ( + C O M M E N T S )
This commit is contained in:
parent
d538e1a0ef
commit
89ffa7fb82
|
@ -38,8 +38,8 @@ typedef struct arrow_t {
|
|||
GLuint z;
|
||||
};
|
||||
|
||||
int write_one_arrow_vertex (int space_X, int space_Y, int space_Z,
|
||||
int draw_one_arrow_vertex (int space_X, int space_Y, int space_Z,
|
||||
int weight, int site, int x, int y, int z, int print);
|
||||
|
||||
int write_one_arrow_line(int offset_vertex, int print);
|
||||
int draw_one_arrow_line(int offset_vertex, int print);
|
||||
|
||||
|
|
|
@ -92,5 +92,5 @@ static inline char *read_file(char *filename)
|
|||
#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
|
||||
#define SOUTH 4 // + z bleu
|
||||
#define NORTH 5 // - z jaune
|
||||
|
|
|
@ -44,8 +44,6 @@ struct gl_area_entry {
|
|||
GLuint m; // init_shaders, draw
|
||||
GLuint v; // init_shaders, draw
|
||||
GLuint p; // init_shaders, draw
|
||||
// GLuint line_indices_nb; // now : graphics.c > int buffer_lines_ndx
|
||||
// GLuint plan_indices_nb; // now : graphics.c > int buffer_plans_ndx
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -101,6 +99,26 @@ bool graphics_init_shaders(const void *gl_area);
|
|||
*/
|
||||
void graphics_init_buffers(const void *gl_area);
|
||||
|
||||
/*
|
||||
* Draws a vertex (x, y, z)
|
||||
* if (console) prints (x, y, z) values to console
|
||||
*
|
||||
* @param GLfloat x, GLfloat y, GLfloat z
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_vertex (GLfloat x, GLfloat y, GLfloat z, int console);
|
||||
|
||||
/*
|
||||
* Draws the color (r, g, b) associated to a vertex
|
||||
* if (console) prints (r, g, b) values to console
|
||||
*
|
||||
* @param GLfloat r, GLfloat g, GLfloat b
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_color (GLfloat r, GLfloat g, GLfloat b, int console);
|
||||
|
||||
/*
|
||||
* Writes values to describe a line from a to b into the line buffer
|
||||
*
|
||||
|
@ -108,25 +126,7 @@ void graphics_init_buffers(const void *gl_area);
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_line (GLuint a, GLuint b, int print);
|
||||
|
||||
/*
|
||||
* 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, int print);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
void graphics_draw_line (GLuint a, GLuint b, int console);
|
||||
|
||||
/*
|
||||
* Writes values to describe an (a,b,c) plan (triangle) into the plan buffer
|
||||
|
@ -135,7 +135,7 @@ void graphics_write_color (GLfloat r, GLfloat g, GLfloat b);
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_plan (GLuint a, GLuint b, GLuint c);
|
||||
void graphics_draw_plan (GLuint a, GLuint b, GLuint c, int console);
|
||||
|
||||
/*
|
||||
* Initializes an identity matrix
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
int write_space_ridges_vertex (long offset_vertex, long x, long y, long z);
|
||||
int write_space_ridges_lines ();
|
||||
int draw_space_ridges_vertex (long offset_vertex, long x, long y, long z, int console);
|
||||
int draw_space_ridges_lines (int console);
|
||||
|
||||
/*
|
||||
* Writes grid lines on space faces
|
||||
|
@ -44,6 +44,6 @@ int write_space_ridges_lines ();
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
long write_grids_on_space_faces_vertex (long x, long y, long z);
|
||||
long write_grids_on_space_faces_lines (long offset_vertex, long x, long y, long z);
|
||||
long draw_grids_on_space_faces_vertex (long x, long y, long z, int console);
|
||||
long draw_grids_on_space_faces_lines (long offset_vertex, long x, long y, long z, int console);
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
* Z - Z = NORTH - SOUTH = bleu - jaune
|
||||
*/
|
||||
|
||||
int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
|
||||
int weight, int site, int arrow_x, int arrow_y, int arrow_z, int print)
|
||||
int draw_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
|
||||
int weight, int site, int arrow_x, int arrow_y, int arrow_z, int console)
|
||||
{
|
||||
|
||||
float max = fmax(space_X_int, space_Y_int);
|
||||
|
@ -46,8 +46,8 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
|
|||
vy = (2 * j / space_Y_int - 1) * space_Y_int / max + (1 / max),
|
||||
vz = (2 * k / space_Z_int - 1) * space_Z_int / max + (1 / max);
|
||||
|
||||
graphics_write_vertex(vx, vy, vz, print);
|
||||
graphics_write_color(0.4f, 0.4f, 0.4f);
|
||||
graphics_draw_vertex(vx, vy, vz, console);
|
||||
graphics_draw_color(0.4f, 0.4f, 0.4f, console);
|
||||
|
||||
// réduit légèrement les longueurs des flèches
|
||||
// pour qu'elles s'arrêtent avant les faces des cubes
|
||||
|
@ -55,28 +55,28 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
|
|||
|
||||
switch(site){
|
||||
case EAST:
|
||||
graphics_write_vertex (vx - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, vy, vz, print);
|
||||
graphics_write_color (1.0f, 0.0f, 0.0f);
|
||||
graphics_draw_vertex (vx - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, vy, vz, console);
|
||||
graphics_draw_color (1.0f, 0.0f, 0.0f, console);
|
||||
break;
|
||||
case WEST:
|
||||
graphics_write_vertex (vx - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, vy, vz, print);
|
||||
graphics_write_color (0.0f, 1.0f, 1.0f);
|
||||
graphics_draw_vertex (vx - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, vy, vz, console);
|
||||
graphics_draw_color (0.0f, 1.0f, 1.0f, console);
|
||||
break;
|
||||
case ZENITH:
|
||||
graphics_write_vertex (vx, vy - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, vz, print);
|
||||
graphics_write_color(0.0f, 0.6f, 0.1f);
|
||||
graphics_draw_vertex (vx, vy - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, vz, console);
|
||||
graphics_draw_color(0.0f, 0.6f, 0.1f, console);
|
||||
break;
|
||||
case NADIR:
|
||||
graphics_write_vertex (vx, vy - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, vz, print);
|
||||
graphics_write_color(0.6f, 0.1f, 0.7f);
|
||||
graphics_draw_vertex (vx, vy - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, vz, console);
|
||||
graphics_draw_color(0.6f, 0.1f, 0.7f, console);
|
||||
break;
|
||||
case SOUTH:
|
||||
graphics_write_vertex (vx, vy, vz - (site % 2 - 1) * (1 / max) + (site % 2 - 1) * arrow_tip_padding, print);
|
||||
graphics_write_color(1.0f, 1.0f, 0.0f);
|
||||
graphics_draw_vertex (vx, vy, vz - (site % 2 + 1) * (1 / max) + (site % 2 + 1) * arrow_tip_padding, console);
|
||||
graphics_draw_color(0.05f, 0.4f, 1.0f, console);
|
||||
break;
|
||||
case NORTH:
|
||||
graphics_write_vertex (vx, vy, vz - (site % 2) * (1 / max) + (site % 2) * arrow_tip_padding, print);
|
||||
graphics_write_color(0.05f, 0.4f, 1.0f);
|
||||
graphics_draw_vertex (vx, vy, vz - (site % 2 - 2) * (1 / max) + (site % 2 - 2) * arrow_tip_padding, console);
|
||||
graphics_draw_color(1.0f, 1.0f, 0.0f, console);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -85,8 +85,8 @@ int write_one_arrow_vertex (int space_X_int, int space_Y_int, int space_Z_int,
|
|||
}
|
||||
|
||||
|
||||
int write_one_arrow_line(int offset_vertex, int print)
|
||||
int draw_one_arrow_line(int offset_vertex, int print)
|
||||
{
|
||||
graphics_write_line (offset_vertex + 0, offset_vertex + 1, print);
|
||||
graphics_draw_line (offset_vertex + 0, offset_vertex + 1, print);
|
||||
return 2;
|
||||
}
|
||||
|
|
|
@ -29,93 +29,6 @@
|
|||
#include "../../include/displays.h"
|
||||
|
||||
|
||||
/* TO REMEMBER : Ici, tout ce qui gène la lecture du code en cours de debugging
|
||||
* #pragma omp parallel schedule(static, 12)
|
||||
* void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
||||
{
|
||||
// assert : space dimensions (x,y,z) > 0
|
||||
// assert : arrows localization within space and sites
|
||||
// assert : no more than one arrow per address
|
||||
// notify : weights are replaced, NOT added (could be !)
|
||||
*
|
||||
* Init space and arrows (= initial state)
|
||||
* and allows ulterior creations, suppressions or modifications of the arrows[] array
|
||||
*
|
||||
* Draws space and arrows
|
||||
*
|
||||
* // Initialisation du générateur pseudo-aléatoire
|
||||
* // Attention, à ce stade, pas de vertex redondant
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* in set_arrow() : */
|
||||
/* if (console) print_vertex_and_lines_buffers (arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */
|
||||
/* if (0) print_vertex_and_lines_buffers (arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */
|
||||
/* if (requested_weight == 0 && console) */
|
||||
/* printf(" - set_arrow() invoked with requested weight = %2d bf_vrtx = %d bf_ln = %d add: %d",\ */
|
||||
/* requested_weight, buffer_vertex_size / 3, buffer_lines_size / 2, address); */
|
||||
/* if (console) show_user_action(arrows_ptr, arrows_nb, address, requested_weight, current_weight, site, x, y, z); */
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
/*
|
||||
* Removes an arrow at address (address)
|
||||
*/
|
||||
/*
|
||||
* Creates a new arrow at address (address)
|
||||
* NB Weights (or loads) are NOT added
|
||||
*/
|
||||
|
||||
/*
|
||||
* Assigns a new load to the arrow at address (address)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
/* I N I T I A L D A T A A R E N O W A L L S P E C I F I E D */
|
||||
|
||||
/* A N D C A N B E D R A W N */
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
/* N E W D A T A W I L L N O W B E S P E C I F I E D */
|
||||
|
||||
/* A N D T H E N D R A W N E D */
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* If load == 0 then erase the arrow at this address v */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 0, 0, 0, 0, console); */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 1, 0, 0, 0, console); */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 2, 0, 0, 0, console); */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 3, 0, 0, 0, console); */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 4, 0, 0, 0, console); */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, 0, 5, 0, 0, 0, console); */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------------------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Prints the arrows[] array
|
||||
*
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define FRAG_SHADER_FILE "src/shaders/shader.frag"
|
||||
|
||||
static struct arrow_t *arrows_ptr;
|
||||
|
||||
GLfloat *buffer_vertex_origin = NULL;
|
||||
GLfloat *buffer_colors_origin = NULL;
|
||||
GLuint *buffer_lines_origin = NULL;
|
||||
|
@ -126,7 +127,7 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id,
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z, int print)
|
||||
void graphics_draw_vertex (GLfloat x, GLfloat y, GLfloat z, int console)
|
||||
{
|
||||
buffer_vertex_origin = g_realloc (buffer_vertex_origin,
|
||||
(buffer_vertex_size + 3) * sizeof(GLfloat));
|
||||
|
@ -137,7 +138,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z, int print)
|
|||
buffer_vertex_origin[buffer_vertex_size + 1] = y;
|
||||
buffer_vertex_origin[buffer_vertex_size + 2] = z;
|
||||
|
||||
if (print) printf("In graphics_write_vertex() buffer_vertex_size => [%2ld] [%2ld > %2ld] (%6.3f,%6.3f,%6.3f)\n",\
|
||||
if (console) printf("In graphics_draw_vertex() buffer_vertex_size => [%2ld] [%2ld > %2ld] (%6.3f,%6.3f,%6.3f)\n",\
|
||||
buffer_vertex_size / 3, buffer_vertex_size + 0, buffer_vertex_size + 2, x, y, z);
|
||||
|
||||
buffer_vertex_size += 3;
|
||||
|
@ -150,7 +151,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z, int print)
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_color (GLfloat r, GLfloat g, GLfloat b)
|
||||
void graphics_draw_color (GLfloat r, GLfloat g, GLfloat b, int console)
|
||||
{
|
||||
buffer_colors_origin = g_realloc (buffer_colors_origin,
|
||||
(buffer_colors_size + 3) * sizeof(GLfloat));
|
||||
|
@ -171,7 +172,7 @@ void graphics_write_color (GLfloat r, GLfloat g, GLfloat b)
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_line (GLuint a, GLuint b, int print)
|
||||
void graphics_draw_line (GLuint a, GLuint b, int console)
|
||||
{
|
||||
buffer_lines_origin = g_realloc (buffer_lines_origin,
|
||||
(buffer_lines_size + 2) * sizeof(GLuint));
|
||||
|
@ -181,7 +182,7 @@ void graphics_write_line (GLuint a, GLuint b, int print)
|
|||
buffer_lines_origin[buffer_lines_size + 0] = a;
|
||||
buffer_lines_origin[buffer_lines_size + 1] = b;
|
||||
|
||||
if (print) printf("In graphics_write_line() buffer_lines_size => [%2ld] [%2ld > %2ld] (%3u > %3u )\n\n",\
|
||||
if (console) printf("In graphics_draw_line() buffer_lines_size => [%2ld] [%2ld > %2ld] (%3u > %3u )\n",\
|
||||
buffer_lines_size / 2, buffer_lines_size + 0, buffer_lines_size + 1, a, b);
|
||||
|
||||
buffer_lines_size += 2;
|
||||
|
@ -194,7 +195,7 @@ void graphics_write_line (GLuint a, GLuint b, int print)
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_write_plan (GLuint a, GLuint b, GLuint c)
|
||||
void graphics_draw_plan (GLuint a, GLuint b, GLuint c, int console)
|
||||
{
|
||||
buffer_plans_origin = g_realloc (buffer_plans_origin,
|
||||
(buffer_plans_size + 3) * sizeof(GLuint));
|
||||
|
@ -553,47 +554,11 @@ bool graphics_shutdown(const void *gl_area)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Depends on set_arrow()
|
||||
* Exchanges current and required site values
|
||||
* when the address of the arrow to be set is already occupied
|
||||
*/
|
||||
static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, int y, int z, int console)
|
||||
{
|
||||
printf("WARNING in rewrite_arrow() <> address or address / 5 ? (et pourquoi ?)\n");
|
||||
|
@ -604,6 +569,10 @@ static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x,
|
|||
return arrows_nb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Depends on set_arrow()
|
||||
* Creates the arrow to be set with the required load at the required address
|
||||
*/
|
||||
static inline int create_arrow (int arrows_nb,
|
||||
int space_X, int space_Y, int space_Z,
|
||||
int load, int site, int x, int y, int z,
|
||||
|
@ -622,8 +591,8 @@ static inline int create_arrow (int arrows_nb,
|
|||
arrows_ptr[arrows_nb].y = y;
|
||||
arrows_ptr[arrows_nb].z = z;
|
||||
|
||||
write_one_arrow_vertex(space_X, space_Y, space_Z, load, site, x, y, z, console);
|
||||
write_one_arrow_line (buffer_vertex_size / 3 - 2, console);
|
||||
draw_one_arrow_vertex(space_X, space_Y, space_Z, load, site, x, y, z, console);
|
||||
draw_one_arrow_line (buffer_vertex_size / 3 - 2, console);
|
||||
|
||||
arrows_nb ++;
|
||||
|
||||
|
@ -632,6 +601,10 @@ static inline int create_arrow (int arrows_nb,
|
|||
return arrows_nb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Depends on set_arrow()
|
||||
* Erases the arrow at the required address
|
||||
*/
|
||||
static inline int erase_arrow (int arrows_nb, int arrow_address_in_list,
|
||||
GLuint site, GLint x, GLint y, GLint z,
|
||||
int console)
|
||||
|
@ -668,9 +641,9 @@ static inline int erase_arrow (int arrows_nb, int arrow_address_in_list,
|
|||
buffer_colors_origin [buffer_colors_0_arrow + arrow_address_in_list * 6 + i]
|
||||
= buffer_colors_origin [buffer_colors_size - 6 + i];
|
||||
|
||||
buffer_vertex_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_write_vertex()
|
||||
buffer_colors_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_write_colors()
|
||||
buffer_lines_size -= 2; // <<< l'inverse de ce qui est fait dans : graphics_write_line()
|
||||
buffer_vertex_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_draw_vertex()
|
||||
buffer_colors_size -= 6; // <<< l'inverse de ce qui est fait dans : graphics_draw_colors()
|
||||
buffer_lines_size -= 2; // <<< l'inverse de ce qui est fait dans : graphics_draw_line()
|
||||
|
||||
void *new_arrows_vertex_ptr = g_realloc(buffer_vertex_origin, buffer_vertex_size * sizeof(GLfloat));
|
||||
if (new_arrows_vertex_ptr) buffer_vertex_origin = new_arrows_vertex_ptr;
|
||||
|
@ -693,13 +666,36 @@ static inline int erase_arrow (int arrows_nb, int arrow_address_in_list,
|
|||
|
||||
|
||||
|
||||
/*
|
||||
* Creates or deletes an arrow or modify the load of an existing one
|
||||
* Acts both by writing the list of arrows : (struct arrow_t *arrows_ptr, int arrows_nb)
|
||||
* and by drawing in the global space
|
||||
*
|
||||
* @param arrows_ptr and arrows_nb before operation,
|
||||
* required load and address (site, x, y, z)
|
||||
*
|
||||
* IF there is no arrow at the required address,
|
||||
* AND IF the load is > 0, an arrow will be created.
|
||||
*
|
||||
* IF there is an arrow at the required address
|
||||
* AND IF the load is = 0, the existing arrow will be deleted.
|
||||
*
|
||||
* IF there is an arrow at the required address
|
||||
* AND IF the load is > 0, the load of the existing arrow will be modified.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @return arrows_nb after operation
|
||||
*/
|
||||
static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int space_X, int space_Y, int space_Z,
|
||||
int requested_weight, int site, int arrow_x, int arrow_y, int arrow_z, int console)
|
||||
{
|
||||
int address = -1, current_weight = -1;
|
||||
|
||||
if (console) printf("in set_arrow (begin) arrows_nb = %d requested site: %d > ", arrows_nb, site);
|
||||
if (console) for (int i = 0; i < arrows_nb; i++) {printf(" [%d] = %d ", i, arrows_ptr[i].site); if (site == arrows_ptr[i].site) break;}
|
||||
/* if (console) for (int i = 0; i < arrows_nb; i++) {printf(" [%d] = %d ", i, arrows_ptr[i].site); if (site == arrows_ptr[i].site) break;} */
|
||||
|
||||
for (int i = 0; i < arrows_nb; i++)
|
||||
if ((site == arrows_ptr[i].site)
|
||||
|
@ -712,6 +708,7 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac
|
|||
break;
|
||||
}
|
||||
assert (address <= arrows_nb);
|
||||
|
||||
if (console) {
|
||||
if (address == -1 && requested_weight > 0) printf(" >> create_arrow() at site %d\n", site);
|
||||
if (address >= 0 && requested_weight == 0) printf(" >> erase_arrow() at site %d\n", site);
|
||||
|
@ -732,32 +729,70 @@ static inline int set_arrow (struct arrow_t *arrows_ptr, int arrows_nb, int spac
|
|||
|
||||
|
||||
|
||||
/* TODO
|
||||
* #pragma omp parallel schedule(static, 12)
|
||||
* void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) {}
|
||||
*
|
||||
// assert : space dimensions (x,y,z) > 0
|
||||
// assert : arrows localization within space and sites
|
||||
// assert : no more than one arrow per address
|
||||
// notify : weights are replaced, NOT added (could be !)
|
||||
*
|
||||
* Init space and arrows (= initial state)
|
||||
* and allows ulterior creations, suppressions or modifications of the arrows[] array
|
||||
*
|
||||
* draws the space()
|
||||
* triggers set_arrows() that modifies the list () and draws arrows
|
||||
*
|
||||
* Initialisation du générateur pseudo-aléatoire
|
||||
* Attention, les vertex centraux de chaque unité d'espace (cube)
|
||||
* peuvent être redondants (max 6)
|
||||
*/
|
||||
void main_test_graphics (void)
|
||||
{
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/* I N I T I A L D A T A S P E C I F I C A T I O N */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
srand(time(NULL)); int rand(void); void srand(unsigned int seed);
|
||||
int randomize = 7, console = 0, arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1;
|
||||
int randomize = 0, console = 0, arrows_nb = 0, space_X = 1, space_Y = 1, space_Z = 1;
|
||||
if (randomize) {
|
||||
space_X = 1 + rand() % randomize;
|
||||
space_Y = 1 + rand() % randomize;
|
||||
space_Z = 1 + rand() % randomize;
|
||||
}
|
||||
int density_max = space_X * space_Y * space_Z, specified_arrows_nb = rand() % density_max;
|
||||
int max = fmax(space_X, space_Y); max = fmax(max, space_Z);
|
||||
int density_max = space_X * space_Y * space_Z, specified_arrows_nb = density_max;
|
||||
/* int max = fmax(space_X, space_Y); max = fmax(max, space_Z); */
|
||||
|
||||
/* S P A C E */
|
||||
|
||||
write_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z);
|
||||
write_space_ridges_lines ();
|
||||
write_grids_on_space_faces_vertex (space_X, space_Y, space_Z);
|
||||
write_grids_on_space_faces_lines (buffer_lines_size, space_X, space_Y, space_Z);
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/* S P A C E D R A W I N G */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
draw_space_ridges_vertex (buffer_vertex_size, space_X, space_Y, space_Z, console);
|
||||
draw_space_ridges_lines (console);
|
||||
draw_grids_on_space_faces_vertex (space_X, space_Y, space_Z, console);
|
||||
draw_grids_on_space_faces_lines (buffer_lines_size, space_X, space_Y, space_Z, console);
|
||||
|
||||
buffer_vertex_0_arrow = buffer_vertex_size;
|
||||
buffer_colors_0_arrow = buffer_colors_size;
|
||||
buffer_lines_0_arrow = buffer_lines_size;
|
||||
|
||||
/* A R R O W S */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
/* A R R O W S D R A W I N G */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
if (randomize) for (int i = 0; i < specified_arrows_nb; i++)
|
||||
{
|
||||
arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z,
|
||||
1, // load
|
||||
rand() % 6, // site
|
||||
|
@ -765,22 +800,38 @@ void main_test_graphics (void)
|
|||
rand() % space_Y, // y
|
||||
rand() % space_Z, // z
|
||||
console);
|
||||
if (i > 0 && i % 1000 == 0) printf("|");
|
||||
if (i > 0 && i % 100000 == 0) printf("\n");
|
||||
}
|
||||
else for (int i = 0; i < 6; i++)
|
||||
arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 1, i, 0, 0, 0, 0);
|
||||
arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 1, i, 0, 0, 0, console);
|
||||
|
||||
int max_arrows_nb = arrows_nb;
|
||||
|
||||
if (randomize) for (int i = 0; i < specified_arrows_nb * 6; i++)
|
||||
arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z,
|
||||
rand() % 1, // load
|
||||
rand() % 6, // site
|
||||
rand() % space_X, // x
|
||||
rand() % space_Y, // y
|
||||
rand() % space_Z, // z
|
||||
console);
|
||||
else for (int i = 0; i < 6; i++)
|
||||
arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, i, 0, 0, 0, 1);
|
||||
/* if (randomize) for (int i = 0; i < 6; i++) */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, space_X, space_Y, space_Z, */
|
||||
/* rand() % 1, // load */
|
||||
/* rand() % 6, // site */
|
||||
/* rand() % space_X, // x */
|
||||
/* rand() % space_Y, // y */
|
||||
/* rand() % space_Z, // z */
|
||||
/* console); */
|
||||
/* else for (int i = 0; i < 6; i++) */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, i, 0, 0, 0, 0); */
|
||||
|
||||
/* int angle = 9; */
|
||||
/* if (space_X > angle && space_Y > angle && space_Z > angle) for (int i = 0; i < angle; i++) */
|
||||
/* for (int u = 0; u < angle; u++) for (int v = 0; v < angle; v++) for (int w = 0; w < angle; w++) */
|
||||
/* if (u + v + w < angle * 3) */
|
||||
/* arrows_nb = set_arrow (arrows_ptr, arrows_nb, 1, 1, 1, 0, i, u, v, w, 0); */
|
||||
|
||||
/* if (space_X > angle && space_Y > angle && space_Z > angle) */
|
||||
/* printf("+ effacement des flèches dans l'angle-origine\ */
|
||||
/* <=> contrôle graphique de la fonction erase_arrow()\n"); */
|
||||
|
||||
if (1) print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 0, 0);
|
||||
|
||||
|
||||
if (randomize) print_user_choices(arrows_ptr, max_arrows_nb, arrows_nb, space_X, space_Y, space_Z, 1, 0);
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
|
||||
|
@ -792,3 +843,4 @@ void main_test_graphics (void)
|
|||
|
||||
free(arrows_ptr); arrows_ptr = NULL; arrows_nb = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,128 +25,128 @@
|
|||
#include "../../include/base.h"
|
||||
#include "../../include/graphics.h"
|
||||
|
||||
int write_space_ridges_vertex (long offset_vertex, long x, long y, long z)
|
||||
int draw_space_ridges_vertex (long offset_vertex, long x, long y, long z, int console)
|
||||
{
|
||||
float max = fmax(x, y); max = fmax(max, z);
|
||||
GLfloat max = fmax(x, y); max = fmax(max, z);
|
||||
|
||||
graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max, 0);
|
||||
graphics_draw_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max, console);
|
||||
|
||||
graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, - z / max, 0);
|
||||
graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, - z / max, 0);
|
||||
graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, + z / max, 0);
|
||||
graphics_draw_vertex (offset_vertex + x / max, offset_vertex - y / max, - z / max, console);
|
||||
graphics_draw_vertex (offset_vertex - x / max, offset_vertex + y / max, - z / max, console);
|
||||
graphics_draw_vertex (offset_vertex - x / max, offset_vertex - y / max, + z / max, console);
|
||||
|
||||
graphics_write_vertex (offset_vertex + x / max, offset_vertex + y / max, - z / max, 0);
|
||||
graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, + z / max, 0);
|
||||
graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, + z / max, 0);
|
||||
graphics_draw_vertex (offset_vertex + x / max, offset_vertex + y / max, - z / max, console);
|
||||
graphics_draw_vertex (offset_vertex + x / max, offset_vertex - y / max, + z / max, console);
|
||||
graphics_draw_vertex (offset_vertex - x / max, offset_vertex + y / max, + z / max, console);
|
||||
|
||||
graphics_write_vertex (offset_vertex + x / max, + y / max, + z / max, 0);
|
||||
graphics_draw_vertex (offset_vertex + x / max, + y / max, + z / max, console);
|
||||
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_write_color (0.8f, 0.6f, 0.5f);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
graphics_draw_color (0.8f, 0.6f, 0.5f, console);
|
||||
|
||||
return 8;
|
||||
}
|
||||
|
||||
int write_space_ridges_lines ()
|
||||
int draw_space_ridges_lines (int console)
|
||||
{
|
||||
graphics_write_line ( 0, 1, 0); graphics_write_line ( 7, 4, 0);
|
||||
graphics_write_line ( 0, 2, 0); graphics_write_line ( 7, 5, 0);
|
||||
graphics_write_line ( 0, 3, 0); graphics_write_line ( 7, 6, 0);
|
||||
graphics_draw_line ( 0, 1, console); graphics_draw_line ( 7, 4, console);
|
||||
graphics_draw_line ( 0, 2, console); graphics_draw_line ( 7, 5, console);
|
||||
graphics_draw_line ( 0, 3, console); graphics_draw_line ( 7, 6, console);
|
||||
|
||||
graphics_write_line ( 1, 4, 0); graphics_write_line ( 2, 4, 0);
|
||||
graphics_write_line ( 1, 5, 0); graphics_write_line ( 3, 5, 0);
|
||||
graphics_write_line ( 2, 6, 0); graphics_write_line ( 3, 6, 0);
|
||||
graphics_draw_line ( 1, 4, console); graphics_draw_line ( 2, 4, console);
|
||||
graphics_draw_line ( 1, 5, console); graphics_draw_line ( 3, 5, console);
|
||||
graphics_draw_line ( 2, 6, console); graphics_draw_line ( 3, 6, console);
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
long write_grids_on_space_faces_vertex (long x, long y, long z)
|
||||
long draw_grids_on_space_faces_vertex (long x, long y, long z, int console)
|
||||
{
|
||||
float i, max = fmax(x, y); max = fmax(max, z);
|
||||
|
||||
for (i = 1; i < x; i++) {
|
||||
|
||||
graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max, 0);
|
||||
graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, z / max, 0);
|
||||
graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, z / max, 0);
|
||||
graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, - z / max, 0);
|
||||
graphics_draw_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max, console);
|
||||
graphics_draw_vertex ((2 * i / x - 1) * x / max, - y / max, z / max, console);
|
||||
graphics_draw_vertex ((2 * i / x - 1) * x / max, y / max, z / max, console);
|
||||
graphics_draw_vertex ((2 * i / x - 1) * x / max, y / max, - z / max, console);
|
||||
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
}
|
||||
|
||||
/* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */
|
||||
|
||||
for (i = 1; i < y; i++) {
|
||||
|
||||
graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, - z / max, 0);
|
||||
graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, z / max, 0);
|
||||
graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, z / max, 0);
|
||||
graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, - z / max, 0);
|
||||
graphics_draw_vertex (- x / max, (2 * i / y - 1) * y / max, - z / max, console);
|
||||
graphics_draw_vertex (- x / max, (2 * i / y - 1) * y / max, z / max, console);
|
||||
graphics_draw_vertex ( x / max, (2 * i / y - 1) * y / max, z / max, console);
|
||||
graphics_draw_vertex ( x / max, (2 * i / y - 1) * y / max, - z / max, console);
|
||||
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
}
|
||||
|
||||
/* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */
|
||||
|
||||
for (i = 1; i < z; i++) {
|
||||
|
||||
graphics_write_vertex (- x / max, - y / max, (2 * i / z - 1) * z / max, 0);
|
||||
graphics_write_vertex (- x / max, y / max, (2 * i / z - 1) * z / max, 0);
|
||||
graphics_write_vertex ( x / max, y / max, (2 * i / z - 1) * z / max, 0);
|
||||
graphics_write_vertex ( x / max, - y / max, (2 * i / z - 1) * z / max, 0);
|
||||
graphics_draw_vertex (- x / max, - y / max, (2 * i / z - 1) * z / max, console);
|
||||
graphics_draw_vertex (- x / max, y / max, (2 * i / z - 1) * z / max, console);
|
||||
graphics_draw_vertex ( x / max, y / max, (2 * i / z - 1) * z / max, console);
|
||||
graphics_draw_vertex ( x / max, - y / max, (2 * i / z - 1) * z / max, console);
|
||||
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_write_color (0.55f, 0.55f, 0.55f);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
graphics_draw_color (0.55f, 0.55f, 0.55f, console);
|
||||
}
|
||||
|
||||
return (x + y + z - 3) * 3;
|
||||
}
|
||||
|
||||
|
||||
long write_grids_on_space_faces_lines (long offset_vertex, long x, long y, long z)
|
||||
long draw_grids_on_space_faces_lines (long offset_vertex, long x, long y, long z, int console)
|
||||
{
|
||||
offset_vertex = offset_vertex / 3;
|
||||
|
||||
for (int i = 0; i < x - 1; i ++) {
|
||||
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, 0); */
|
||||
graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, 0);
|
||||
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, 0);
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, 0); */
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, console); */
|
||||
graphics_draw_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, console);
|
||||
graphics_draw_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, console);
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, console); */
|
||||
}
|
||||
|
||||
offset_vertex += (x - 1) * 4;
|
||||
|
||||
for (int i = 0; i < y - 1; i ++) {
|
||||
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, 0); */
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, 0); */
|
||||
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, 0);
|
||||
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, 0);
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, console); */
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, console); */
|
||||
graphics_draw_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, console);
|
||||
graphics_draw_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, console);
|
||||
}
|
||||
|
||||
offset_vertex += (y - 1) * 4;
|
||||
|
||||
for (int i = 0; i < z - 1; i ++) {
|
||||
|
||||
graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, 0);
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, 0); */
|
||||
/* graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, 0); */
|
||||
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, 0);
|
||||
graphics_draw_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1, console);
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2, console); */
|
||||
/* graphics_draw_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3, console); */
|
||||
graphics_draw_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0, console);
|
||||
}
|
||||
|
||||
return (x + y + z - 3) * 4;
|
||||
|
|
Loading…
Reference in New Issue