OK (space & arrows) pour de petits nombres. Nettoyage en cours.

This commit is contained in:
Jean Sirmai 2023-10-12 10:01:23 +02:00 committed by Adrien 'neox' Bourmault
parent 551c5a5df2
commit 246e73111f
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
5 changed files with 201 additions and 473 deletions

View File

@ -38,54 +38,7 @@ typedef struct arrow_t {
GLuint z; GLuint z;
}; };
/* int write_one_arrow(int offset_vertex,
* Writes basis and tip for all arrows into vertex and color buffers int space_X, int space_Y, int space_Z,
* int weight, int site, int x, int y, int z);
* @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 or west into lines buffer
*
* @param s,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_east_west (long s, int weight, int site);
/*
* Writes lines for arrow oriented to the zenith or nadir into lines buffer
*
* @param s,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_zenith_nadir (long s, int weight, int site);
/*
* Writes lines for arrow oriented to the south or north into lines buffer
*
* @param s,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_south_north (long s, int weight, int site);
/*
* Writes three lines that draw arrow basis (central star) into lines buffer
*
* @param n
*
* @return void
*/
void arrows_write_basis(long n);

View File

@ -27,19 +27,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <GL/glu.h> #include <GL/glu.h>
void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z);
void write_space_faces_grids (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style);
/*
* 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);
/* /*
* Writes grid ridges to vertex and color buffers * Writes grid ridges to vertex and color buffers
* *
@ -47,41 +34,14 @@ void grid_write_intersections (long x, long y, long z);
* *
* @return void * @return void
*/ */
void grid_write_ridges (long x, long y, long z); int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z);
/* /*
* Writes marks (each space unit) along space ridges * Writes grid lines on space faces
*
* @param coords long (x,y,z) // , step_x, step_y, step_z
*
* @return void
*/
void grid_write_marks (long x, long y, long z);
/*
* Writes grid lines for x axis to vertex and color buffers
* *
* @param coords long (x,y,z) * @param coords long (x,y,z)
* *
* @return void * @return void
*/ */
void grid_write_x (long x, long y, long z); long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style);
/*
* 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);

View File

@ -19,7 +19,7 @@
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* aint with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../../include/base.h" #include "../../include/base.h"
@ -40,26 +40,96 @@
* *
* @return void * @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, nuance = 0.24f;
max = fmax(x, y); max = fmax(max, z);
/*
* Writes lines for arrow oriented towards east or west into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
static void write_arrow_lines_east_west (long offset, int weight, int site)
{
graphics_write_line (offset + 2, offset + 6 + site % 2);
graphics_write_line (offset + 3, offset + 6 + site % 2);
graphics_write_line (offset + 4, offset + 6 + site % 2);
graphics_write_line (offset + 5, offset + 6 + site % 2);
}
/*
* Writes lines for arrow oriented towards zenith or nadir into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
static void write_arrow_lines_zenith_nadir (long offset, int weight, int site)
{
graphics_write_line (offset + 0, offset + 8 + site % 2);
graphics_write_line (offset + 1, offset + 8 + site % 2);
graphics_write_line (offset + 4, offset + 8 + site % 2);
graphics_write_line (offset + 5, offset + 8 + site % 2);
}
/*
* Writes lines for arrow oriented towards south or north into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
static void write_arrow_lines_south_north (long offset, int weight, int site)
{
graphics_write_line (offset + 0, offset + 10 + site % 2);
graphics_write_line (offset + 1, offset + 10 + site % 2);
graphics_write_line (offset + 2, offset + 10 + site % 2);
graphics_write_line (offset + 3, offset + 10 + site % 2);
}
/*
* Writes lines for arrow basis into lines buffer
*
* @param offset
*
* @return void
*/
static void arrows_write_basis(long offset)
{
graphics_write_line (offset + 0, offset + 1);
graphics_write_line (offset + 2, offset + 3);
graphics_write_line (offset + 4, offset + 5);
}
/******************************************************************************/
int write_one_arrow(int offset_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)
{
float max = fmax(space_X_int, space_Y_int);
max = fmax(max, space_Z_int);
float i = arrow_x, j = arrow_y, k = arrow_z;
float vx = (2 * i / space_X_int - 1) * space_X_int / max + (1 / max),
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);
// arrow_basis_width donne la dimension de l'étoile centrale // arrow_basis_width donne la dimension de l'étoile centrale
arrow_basis_width = 0.3f * (1 / max), GLfloat arrow_basis_width = (1 / max) / 5;
// décale légèrement les pointes des flèches // décale légèrement les pointes des flèches
// pour qu'elles n'aillent pas jusqu'aux faces des cubes // pour qu'elles n'aillent pas jusqu'aux faces des cubes
arrow_tip_padding = 0.1 * (1 / max); GLfloat arrow_tip_padding = (1 / max) / 10;
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) // X - X axis - central star (basis)
graphics_write_vertex(vx + arrow_basis_width, vy, vz); graphics_write_vertex(vx + arrow_basis_width, vy, vz);
@ -79,6 +149,13 @@ void arrows_write_terminations (long x, long y, long z)
graphics_write_color(0.3f, 0.3f, 0.3f); graphics_write_color(0.3f, 0.3f, 0.3f);
graphics_write_color(0.3f, 0.3f, 0.3f); graphics_write_color(0.3f, 0.3f, 0.3f);
graphics_write_line (offset_vertex + 0, offset_vertex + 1);
graphics_write_line (offset_vertex + 2, offset_vertex + 3);
graphics_write_line (offset_vertex + 4, offset_vertex + 5);
GLfloat nuance = 0.24f;
// X - X (EAST - WEST) axis - arrows tips (red - green) // X - X (EAST - WEST) axis - arrows tips (red - green)
graphics_write_vertex (vx + (1 / max) - arrow_tip_padding, vy, vz); graphics_write_vertex (vx + (1 / max) - arrow_tip_padding, vy, vz);
graphics_write_vertex (vx - (1 / max) + arrow_tip_padding, vy, vz); graphics_write_vertex (vx - (1 / max) + arrow_tip_padding, vy, vz);
@ -94,73 +171,18 @@ void arrows_write_terminations (long x, long y, long z)
// Z - Z (NORTH - SOUTH) axis - arrows tips (blue - yellow) // Z - Z (NORTH - SOUTH) axis - arrows tips (blue - yellow)
graphics_write_vertex (vx, vy, vz + (1 / max) - arrow_tip_padding); graphics_write_vertex (vx, vy, vz + (1 / max) - arrow_tip_padding);
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 + nuance, 0.0f + nuance, 1.0f - nuance / 4); graphics_write_color(0.0f + nuance * 2, 0.0f + nuance * 2, 1.0f - nuance);
graphics_write_color(1.0f - nuance / 3, 1.0f - nuance / 3, 0.0f + nuance); graphics_write_color(1.0f - nuance / 3, 1.0f - nuance / 3, 0.0f + nuance);
};
switch(site){
case EAST: case WEST: write_arrow_lines_east_west (offset_vertex, weight, site); break;
case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (offset_vertex, weight, site); break;
case SOUTH: case NORTH: write_arrow_lines_south_north (offset_vertex, weight, site); break;
default: break;
} }
/* return 12;
* Writes lines for arrow oriented towards east or west into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_east_west (long offset, int weight, int site)
{
graphics_write_line (offset + 2, offset + 6 + site % 2);
graphics_write_line (offset + 3, offset + 6 + site % 2);
graphics_write_line (offset + 4, offset + 6 + site % 2);
graphics_write_line (offset + 5, offset + 6 + site % 2);
} }
/*
* Writes lines for arrow oriented towards zenith or nadir into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_zenith_nadir (long offset, int weight, int site)
{
graphics_write_line (offset + 0, offset + 8 + site % 2);
graphics_write_line (offset + 1, offset + 8 + site % 2);
graphics_write_line (offset + 4, offset + 8 + site % 2);
graphics_write_line (offset + 5, offset + 8 + site % 2);
}
/*
* Writes lines for arrow oriented towards south or north into lines buffer
*
* @param offset,
* weight,
* site
*
* @return void
*/
void write_arrow_lines_south_north (long offset, int weight, int site)
{
graphics_write_line (offset + 0, offset + 10 + site % 2);
graphics_write_line (offset + 1, offset + 10 + site % 2);
graphics_write_line (offset + 2, offset + 10 + site % 2);
graphics_write_line (offset + 3, offset + 10 + site % 2);
}
/*
* Writes lines for arrow basis into lines buffer
*
* @param offset
*
* @return void
*/
void arrows_write_basis(long offset)
{
graphics_write_line (offset + 0, offset + 1);
graphics_write_line (offset + 2, offset + 3);
graphics_write_line (offset + 4, offset + 5);
}

View File

@ -152,8 +152,6 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z)
buffer_vertex_origin[buffer_vertex_size + 2] = z; buffer_vertex_origin[buffer_vertex_size + 2] = z;
buffer_vertex_size += 3; buffer_vertex_size += 3;
//printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size);
} }
/* /*
@ -381,7 +379,7 @@ void graphics_draw(const void *gl_area)
/* Use our shaders */ /* Use our shaders */
glUseProgram(entry->program); glUseProgram(entry->program);
// if (pref_style_mix_colors == 0) // if (pref_show_space_design_mix_colors == 0)
glClearColor(0, 0, 0, 0.4f); glClearColor(0, 0, 0, 0.4f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -566,16 +564,17 @@ bool graphics_shutdown(const void *gl_area)
* *
* For each arrow the following parameters are displayed : * For each arrow the following parameters are displayed :
* - rank in the array * - rank in the array
* - weight (or load) * - load (or weight)
* - coordinates in space (site, x, y, z) * - coordinates in space (site, x, y, z)
*/ */
static void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z) static void print_arrows_array (struct arrow_t *arrows, int arrows_nb)
{ {
printf("\n [rank] load | site x y z"); printf(" [rank] load | site x y z");
for (int i = 0; i < arrows_nb; i++) for (int i = 0; i < arrows_nb; i++)
printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, *(arrows + i * 5 + 0),\ printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d", i, arrows[i].load,\
*(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z);
if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---"); if (arrows_nb == 0) printf("\n [NULL] ---- | ---- --- --- ---");
printf("\n");
} }
/* /*
@ -585,59 +584,17 @@ static void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int
* NB The space may be empty or saturated with arrows or any value in between * 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 * Only one arrow per possible coordinates with a load max equal to ? TODO
*/ */
static void show_user_choices(struct arrow_t *arrows, int arrows_nb, static void print_user_choices(struct arrow_t *arrows, int arrows_nb,
int space_size_x, int space_size_y, int space_size_z, int space_size_x, int space_size_y, int space_size_z,
int prefer, int show_all, int show_array) int show_array, int show_space_design)
{ {
if (show_array) printf("\n"); printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\tarrows nb = %d\t",\
printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\t", space_size_x, space_size_y, space_size_z); space_size_x, space_size_y, space_size_z, arrows_nb);
if (show_all && prefer == 0) printf("prefer = %d <> show all grids", prefer);
if (show_all && prefer == 1) printf("prefer = %d <> show no grid", prefer); if (show_space_design) printf("orientations grilles alternées");
if (show_all && prefer > 1) printf("show grids according rule (%d)", prefer);
printf("\n"); printf("\n");
if (show_all) printf("\n\ if (show_array) print_arrows_array (arrows, arrows_nb);
initial arrows data with arrows_nb = %d", arrows_nb);
if (show_array) show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z);
}
/*
* 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;
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,\
difference, difference, difference / 12, difference / 12);
printf("\n buffer_lines_offset after cubes = %6d\t%6d = 2 * (%dx%d + %dx%d + %dx%d); <--> 2 * (x*y + x*z + y*z)",\
buffer_lines_size_after_cubes, ((space_X+1) * (space_Y+1) + (space_X+1) * (space_Z+1) + (space_Y+1) * (space_Z+1)) * 2,
space_X+1, space_Y+1, space_X+1, space_Z+1, space_Y+1, space_Z+1);
printf("\n buffer_lines_offset after arrows = %6d\t%6d = %d + %d; <--> %d = (3 + 4) x 2 x %d (arrows_nb = %d)",\
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);
if (arrows_nb < 0) // LOL ! This error no more exists !
printf("\n ERR : %d - %d = %d %d = %d x %d\n",\
arrows_nb * 14, buffer_lines_size - buffer_lines_size_after_cubes,\
arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes),\
arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes),\
(arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes)) / arrows_nb, arrows_nb);
if (arrows_nb > 1)
printf("\n WARNING In this test, it may happens that some arrows (whatever their weights) are drawn superimposed (check the list).\n");
else printf("\n");
} }
@ -661,14 +618,14 @@ static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrow
/* /*
* Assigns a new weight to the arrow at address (address) * Assigns a new load to the arrow at address (address)
*/ */
static int rewrite_arrow (int arrows_nb, int address, int weight, int site, int x, int y, int z) static int rewrite_arrow (int arrows_nb, int address, int load, int site, int x, int y, int z)
{ {
arrows[address].load = weight; arrows[address].load = load;
// if (! TEST) // if (! TEST)
// show_arrows_array (arrows, arrows_nb, x, y, z); // print_arrows_array (arrows, arrows_nb);
return arrows_nb; return arrows_nb;
} }
@ -677,7 +634,7 @@ static int rewrite_arrow (int arrows_nb, int address, int weight, int site, int
* Creates a new arrow at address (address) * Creates a new arrow at address (address)
* NB Weights (or loads) are NOT added * NB Weights (or loads) are NOT added
*/ */
static inline int create_arrow (int arrows_nb, int weight, int site, int x, int y, int z) static inline int create_arrow (int arrows_nb, int load, int site, int x, int y, int z)
{ {
void *newptr = g_realloc(arrows, (arrows_nb + 1) * sizeof(struct arrow_t)); void *newptr = g_realloc(arrows, (arrows_nb + 1) * sizeof(struct arrow_t));
@ -686,7 +643,7 @@ static inline int create_arrow (int arrows_nb, int weight, int site, int x, int
else else
perror("Can't allocate new arrow buffer!\n"); perror("Can't allocate new arrow buffer!\n");
arrows[arrows_nb].load = weight; arrows[arrows_nb].load = load;
arrows[arrows_nb].site = site; arrows[arrows_nb].site = site;
arrows[arrows_nb].x = x; arrows[arrows_nb].x = x;
arrows[arrows_nb].y = y; arrows[arrows_nb].y = y;
@ -695,7 +652,7 @@ static inline int create_arrow (int arrows_nb, int weight, int site, int x, int
arrows_nb ++; arrows_nb ++;
// if (! TEST) // if (! TEST)
// show_arrows_array (arrows, arrows_nb, x, y, z); // print_arrows_array (arrows, arrows_nb);
return arrows_nb; return arrows_nb;
} }
@ -724,7 +681,7 @@ static inline int erase_arrow (int arrows_nb, int address, int site, int x, int
perror("Can't allocate new arrow buffer!\n"); perror("Can't allocate new arrow buffer!\n");
// if (! TEST) // if (! TEST)
// show_arrows_array (arrows, arrows_nb, x, y, z); // print_arrows_array (arrows, arrows_nb);
return arrows_nb; return arrows_nb;
} }
@ -768,9 +725,9 @@ static inline int set_arrow (struct arrow_t *arrows, int arrows_nb, int requeste
if (address >= 0 && current_weight != requested_weight) if (address >= 0 && current_weight != requested_weight)
return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z); return rewrite_arrow (arrows_nb, address/5, requested_weight, site, x, y, z);
// if (! TEST && address >= 0 && current_weight == requested_weight) show_arrows_array(arrows, arrows_nb, x, y, z); // if (! TEST && address >= 0 && current_weight == requested_weight) print_arrows_array(arrows, arrows_nb, x, y, z);
// if (! TEST && address == -1 && requested_weight == 0) show_arrows_array(arrows, arrows_nb, x, y, z); // if (! TEST && address == -1 && requested_weight == 0) print_arrows_array(arrows, arrows_nb, x, y, z);
return arrows_nb; return arrows_nb;
} }
@ -872,74 +829,58 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
int rand(void); int rand(void);
void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min);
int arbitrary = 20; int arbitrary = 10;
int space_X = 1 + rand() % arbitrary, int space_X = 1 + rand() % arbitrary,
space_Y = 1 + rand() % arbitrary, space_Y = 1 + rand() % arbitrary,
space_Z = 1 + rand() % arbitrary; space_Z = 1 + rand() % arbitrary;
int density_max = space_X * space_Y * space_Z; int density_max = space_X * space_Y * space_Z;
int arrows_nb = 0;//rand() % density_max; int max = fmax(space_X, space_Y); max = fmax(max, space_Z);
int pref_show_grids = 1; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
// xyz, 0, x, y, z, xy, xz, yz, xyz
int weight = 0, site = 0,
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;
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;
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0); int show_space_design = 0, print_arrows_array = 0;
long offset_vertex = 0, offset_colors = 0, offset_lines = 0; int load = 0, site = 0, x = 0, y = 0, z = 0;
write_space_ridges (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); int specif_arrows_nb = rand() % density_max / 3;
int arrows_nb = 0;
offset_vertex = 8, offset_colors = 8, offset_lines = 12; while (arrows_nb < specif_arrows_nb){
write_space_faces_grids (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, 0); arrows_nb = set_arrow (arrows, arrows_nb,
rand() % arbitrary, // load / weight
/* ARROWS */ rand() % 6, // site,
/* NB The 12 vertices required to draw 6 arrows in each cube rand() % space_X, // x
* are always defined (whether arrows are drawn or not). */ rand() % space_Y, // y
/* Therefore: if (arrows_nb > 0) is not required (next line) */ rand() % space_Z); // z
/* arrows_write_terminations (space_X, space_Y, space_Z); */ }
/* volatile int remaining = arbitrary; */ print_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, print_arrows_array, show_space_design);
/* while (remaining) { */
/* for (int l = 0; l < 10; l++) { */ /* DATA ARE NOW ALL SPECIFIED - DRAWING CAN START */
/* arrows_nb = set_arrow (arrows, arrows_nb, */
/* rand() % arbitrary, // load / weight */ int offset_vertex = 0, offset_colors = 0, offset_lines = 0;
/* rand() % 6, // site, */
/* rand() % space_X, // x */ offset_vertex += write_space_ridges (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z);
/* rand() % space_Y, // y */ offset_colors = offset_vertex;
/* rand() % space_Z); // z */
/* } */ offset_vertex += write_grids_on_space_faces (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, show_space_design);
/* remaining -= 10; */ offset_colors = offset_vertex;
/* for (int i = 0; i < arrows_nb; i++) { */ /* ARROWS */
/* weight = arrows[i].load; */
/* site = arrows[i].site; */ for (int i = 0; i < arrows_nb; i++) {
/* x = arrows[i].x; */ load = arrows[i].load;
/* y = arrows[i].y; */ site = arrows[i].site;
/* z = arrows[i].z; */ x = arrows[i].x;
y = arrows[i].y;
/* offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z); */ z = arrows[i].z;
/* arrow_offset = offset_after_grids + offset_up_to_this_cube_coords; */
offset_vertex += write_one_arrow(offset_vertex,
/* arrows_write_basis (arrow_offset); */ space_X, space_Y, space_Z,
load, site, x, y, z);
/* switch(site){ */ offset_colors = offset_vertex;
/* 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; */ // ? free (space) TODO
/* default: break; */ free(arrows);
/* } */ arrows = NULL;
/* } */ arrows_nb = 0;
/* free(arrows); */
/* arrows = NULL; */
/* arrows_nb = 0; */
/* if (TEST) printf("\nCreated %d arrows", arbitrary - remaining); */
/* } */
/* 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); */
} }

View File

@ -19,36 +19,35 @@
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* aint with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/graphics.h" #include "../../include/graphics.h"
void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) int write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z)
{ {
float max = fmax(x, y); max = fmax(max, z); float max = fmax(x, y); max = fmax(max, z);
graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, - z / max);
graphics_write_vertex (- x / max, - y / max, - z / max); graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, - z / max);
graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, - z / max);
graphics_write_vertex (offset_vertex - x / max, offset_vertex - y / max, + z / max);
graphics_write_vertex (+ x / max, - y / max, - z / max); graphics_write_vertex (offset_vertex + x / max, offset_vertex + y / max, - z / max);
graphics_write_vertex (- x / max, + y / max, - z / max); graphics_write_vertex (offset_vertex + x / max, offset_vertex - y / max, + z / max);
graphics_write_vertex (- x / max, - y / max, + z / max); graphics_write_vertex (offset_vertex - x / max, offset_vertex + y / max, + z / max);
graphics_write_vertex (+ x / max, + y / max, - z / max); graphics_write_vertex (offset_vertex + x / max, + y / max, + z / max);
graphics_write_vertex (+ x / max, - y / max, + z / max);
graphics_write_vertex (- x / max, + y / max, + z / max);
graphics_write_vertex (+ x / max, + y / max, + z / max); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f); graphics_write_color (0.9f, 0.2f, 0.1f);
graphics_write_color (0.9f, 0.4f, 0.2f);
graphics_write_color (0.9f, 0.4f, 0.2f);
graphics_write_line ( 0, 1); graphics_write_line ( 7, 4); graphics_write_line ( 0, 1); graphics_write_line ( 7, 4);
graphics_write_line ( 0, 2); graphics_write_line ( 7, 5); graphics_write_line ( 0, 2); graphics_write_line ( 7, 5);
@ -57,13 +56,15 @@ void write_space_ridges (long offset_vertex, long offset_colors, long offset_lin
graphics_write_line ( 1, 4); graphics_write_line ( 2, 4); graphics_write_line ( 1, 4); graphics_write_line ( 2, 4);
graphics_write_line ( 1, 5); graphics_write_line ( 3, 5); graphics_write_line ( 1, 5); graphics_write_line ( 3, 5);
graphics_write_line ( 2, 6); graphics_write_line ( 3, 6); graphics_write_line ( 2, 6); graphics_write_line ( 3, 6);
return 8;
} }
void write_space_faces_grids (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) long write_grids_on_space_faces (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style)
{ {
float i, max = fmax(x, y); max = fmax(max, z); float i, max = fmax(x, y); max = fmax(max, z);
if (style) for (i = 1; i < x; i++) { for (i = 1; i < x; i++) { // (x - 2) * 4
graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max);
graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, z / max);
@ -76,18 +77,21 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse
graphics_write_color (0.5f, 0.5f, 0.5f); graphics_write_color (0.5f, 0.5f, 0.5f);
} }
if (style) for (i = 0; i < x; i ++) { for (i = 0; i < x - 1; i ++) {
if (style)
graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
if (style)
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
} }
if (style) offset_vertex += (x - 1) * 4; offset_vertex += (x - 1) * 4;
if (style) offset_colors += (x - 1) * 4; offset_colors += (x - 1) * 4;
if (style) offset_lines += (x - 1) * 2; else offset_lines += (x - 1) * 4;
for (i = 1; i < y; i++) { for (i = 1; i < y; i++) { // (y - 2) * 4
graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, - z / max); graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, - z / max);
graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, z / max); graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, z / max);
@ -104,6 +108,7 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse
if (style) if (style)
graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
if (style)
graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
@ -111,8 +116,9 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse
offset_vertex += (y - 1) * 4; offset_vertex += (y - 1) * 4;
offset_colors += (y - 1) * 4; offset_colors += (y - 1) * 4;
if (style) offset_lines += (y - 1) * 2; else offset_lines += (y - 1) * 4;
for (i = 1; i < z; i++) { for (i = 1; i < z; i++) { // (z - 2) * 4
graphics_write_vertex (- x / max, - y / max, (2 * i / z - 1) * z / max); graphics_write_vertex (- x / max, - y / max, (2 * i / z - 1) * z / max);
graphics_write_vertex (- x / max, y / max, (2 * i / z - 1) * z / max); graphics_write_vertex (- x / max, y / max, (2 * i / z - 1) * z / max);
@ -125,174 +131,20 @@ void write_space_faces_grids (long offset_vertex, long offset_colors, long offse
graphics_write_color (0.5f, 0.5f, 0.5f); graphics_write_color (0.5f, 0.5f, 0.5f);
} }
for (i = 0; i <= z; i ++) { for (i = 0; i < z - 1; i ++) {
graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
if (style)
graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
if (style) if (style)
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
} }
return (x + y + z - 3) * 4;
/* if (style) offset_lines += 2 * (space_X + space_Y + space_Z - 3); */
/* else offset_lines += 4 * (space_X + space_Y + space_Z - 3); */
} }
/*
* 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_marks (long x, long y, long z)
{
long step_x = (z + 1) * (y + 1), step_y = z + 1, step_z = 1;
int delta = 1.0f;
for (int i=1; i < z; i ++) {
// graphics_write_vertex (delta, delta, i); graphics_write_vertex (delta, - delta, i);
// graphics_write_color (0.3f,0.3f,0.3f); graphics_write_color (0.3f,0.3f,0.3f);
// graphics_write_line (0, step_z * z + step_y * y + step_x * x);
graphics_write_line ( i * step_z, i * step_z + x);
// graphics_write_line ( i * step_z, i * step_z + y);
}
}
void grid_write_ridges (long x, long y, long z)
{
long step_x = (z + 1) * (y + 1),
step_y = z + 1,
step_z = 1;
long r_000 = step_z * 0 + step_y * 0 + step_x * 0,
r_100 = step_z * 0 + step_y * 0 + step_x * x,
r_010 = step_z * 0 + step_y * y + step_x * 0,
r_001 = step_z * z + step_y * 0 + step_x * 0,
r_011 = step_z * z + step_y * y + step_x * 0,
r_101 = step_z * z + step_y * 0 + step_x * x,
r_110 = step_z * 0 + step_y * y + step_x * x,
r_111 = step_z * z + step_y * y + step_x * x;
graphics_write_line (r_000, r_100); graphics_write_line (r_111, r_011);
graphics_write_line (r_000, r_010); graphics_write_line (r_111, r_101);
graphics_write_line (r_000, r_001); graphics_write_line (r_111, r_110);
graphics_write_line (r_100, r_110); graphics_write_line (r_011, r_001);
graphics_write_line (r_100, r_101); graphics_write_line (r_011, r_010);
graphics_write_line (r_010, r_110); graphics_write_line (r_101, r_001);
}
/*
* 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));
}
}
}