WIP: grilles 'économes' sur les 'parois' de l'espace : première ébauche
This commit is contained in:
parent
5f8be7fc38
commit
294dca34f7
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Gem-graph OpenGL experiments
|
||||||
|
*
|
||||||
|
* Desc: GL functions
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||||
|
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
|
||||||
|
*
|
||||||
|
* This file is part of Gem-graph.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
void show_arrows_array_head(int one_batch_size, long nb_batches_specified, int verbose);
|
||||||
|
void show_one_arrow_in_array(struct arrow_t *arrows, int i);
|
||||||
|
void show_empty_arrows_array();
|
||||||
|
void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* To assert : Only one arrow per possible coordinates with a load max equal to ?
|
||||||
|
*/
|
||||||
|
void show_user_choices(long copy_nb_arrows_specified,
|
||||||
|
int space_size_x, int space_size_y, int space_size_z,
|
||||||
|
int prefer, int arbitrary, int one_batch_size);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prints the result of the function set_arrow()
|
||||||
|
* and indicates the reasons of the choice (call) this function makes (see this function)
|
||||||
|
*/
|
||||||
|
void show_user_action(struct arrow_t *arrows, int arrows_nb, int address, int requested_weight,
|
||||||
|
int current_weight, int site, int x, int y, int z);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prints vertex and lines buffers_states (sizes) at major one_batch_sizes and at the end of a session.
|
||||||
|
* Major one_batch_sizes are creation of grids and creation of arrows
|
||||||
|
* Arithmetic verification is provided at each one_batch_size
|
||||||
|
*/
|
||||||
|
void show_buffers_states(int space_X, int space_Y, int space_Z,
|
||||||
|
long nb_batches_specified, int one_batch_size,
|
||||||
|
int offset_after_grids, int buffer_vertex_size,
|
||||||
|
int buffer_lines_size_after_cubes, int buffer_lines_size);
|
|
@ -27,6 +27,9 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
|
void write_space_ridges (long x, long y, long z);
|
||||||
|
void write_marks_along_space_ridges (long x, long y, long z);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Writes grid lines intersections to vertex and color buffers
|
* Writes grid lines intersections to vertex and color buffers
|
||||||
*
|
*
|
||||||
|
@ -45,6 +48,15 @@ void grid_write_intersections (long x, long y, long z);
|
||||||
*/
|
*/
|
||||||
void grid_write_ridges (long x, long y, long z);
|
void grid_write_ridges (long x, long y, long z);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Writes marks (each space unit) along space ridges
|
||||||
|
*
|
||||||
|
* @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
|
* Writes grid lines for x axis to vertex and color buffers
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Gem-graph OpenGL experiments
|
||||||
|
*
|
||||||
|
* Desc: OpenGL utils header
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
|
||||||
|
*
|
||||||
|
* This file is part of Gem-graph.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "base.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <epoxy/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
#include <GL/glext.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initializes the shaders of a gl_area and link them to a program
|
||||||
|
*
|
||||||
|
* @param gl_area, ptr to the gl_area widget
|
||||||
|
*
|
||||||
|
* @return true if initialized
|
||||||
|
*/
|
||||||
|
bool graphics_init_shaders(const void *gl_area);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Created and compile a shader
|
||||||
|
*
|
||||||
|
* @param type, shader type
|
||||||
|
* src, source code of shader
|
||||||
|
*
|
||||||
|
* @return shader id
|
||||||
|
*/
|
||||||
|
static inline GLuint create_shader(int type, const char *src)
|
||||||
|
{
|
||||||
|
GLuint shader;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
shader = glCreateShader(type);
|
||||||
|
glShaderSource(shader, 1, &src, NULL);
|
||||||
|
glCompileShader(shader);
|
||||||
|
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
||||||
|
if(status == GL_FALSE) {
|
||||||
|
int log_len;
|
||||||
|
char *buffer;
|
||||||
|
|
||||||
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
|
||||||
|
|
||||||
|
buffer = g_malloc(log_len + 1);
|
||||||
|
assert (buffer);
|
||||||
|
glGetShaderInfoLog(shader, log_len, NULL, buffer);
|
||||||
|
|
||||||
|
g_warning("Compile failure in %s shader:\n%s",
|
||||||
|
type == GL_VERTEX_SHADER ? "vertex" : "fragment",
|
||||||
|
buffer);
|
||||||
|
|
||||||
|
g_free(buffer);
|
||||||
|
|
||||||
|
glDeleteShader(shader);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the gl_area_entry size
|
||||||
|
*
|
||||||
|
* @param void
|
||||||
|
*
|
||||||
|
* @return size of array
|
||||||
|
*/
|
||||||
|
// extern struct gl_area_entry **gl_area_array;
|
||||||
|
// static inline short gl_area_size(void)
|
||||||
|
// {
|
||||||
|
// struct gl_area_entry **cur;
|
||||||
|
// short size;
|
||||||
|
|
||||||
|
// Check uninitialized and quit
|
||||||
|
// if (gl_area_array == NULL) return 0;
|
||||||
|
|
||||||
|
// cur = gl_area_array;
|
||||||
|
// while(*cur) {
|
||||||
|
// cur++;
|
||||||
|
// size++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return size;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/*** TEST ***/
|
||||||
|
|
||||||
|
// void main_test_graphics (void);
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
* Gem-graph OpenGL experiments
|
||||||
|
*
|
||||||
|
* Desc: GL functions
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||||
|
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
|
||||||
|
*
|
||||||
|
* This file is part of Gem-graph.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "../../include/graphics.h"
|
||||||
|
#include "../../include/arrows.h"
|
||||||
|
#include "../../include/displays.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
void show_arrows_array_head(int one_batch_size, long nb_batches_specified, int verbose) {
|
||||||
|
printf("\n [rank] load | site x y z");
|
||||||
|
if (verbose) printf(" one batch size = %d nb_batches_specified = %ld",\
|
||||||
|
one_batch_size, nb_batches_specified);
|
||||||
|
}
|
||||||
|
void show_one_arrow_in_array(struct arrow_t *arrows, int i) {
|
||||||
|
printf("\n [%4d] = %2d | %2d, %2d, %2d, %2d",\
|
||||||
|
i, arrows[i].load, arrows[i].site, arrows[i].x, arrows[i].y, arrows[i].z);
|
||||||
|
}
|
||||||
|
void show_empty_arrows_array() {printf("\n [NULL] ---- | ---- --- --- ---");}
|
||||||
|
|
||||||
|
void show_arrows_array (struct arrow_t *arrows, int arrows_nb, int x, int y, int z)
|
||||||
|
{
|
||||||
|
show_arrows_array_head (0,0,0);
|
||||||
|
for (int i = 0; i < arrows_nb; i++)
|
||||||
|
show_one_arrow_in_array(arrows, i);
|
||||||
|
if (arrows_nb == 0) show_empty_arrows_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* To assert : Only one arrow per possible coordinates with a load max equal to ?
|
||||||
|
*/
|
||||||
|
void show_user_choices(long copy_nb_arrows_specified,
|
||||||
|
int space_size_x, int space_size_y, int space_size_z,
|
||||||
|
int prefer, int arbitrary, int one_batch_size)
|
||||||
|
{
|
||||||
|
printf("\nnb arrows specified = %ld", copy_nb_arrows_specified);
|
||||||
|
printf(" space size (x,y,z) = (%d,%d,%d)", space_size_x, space_size_y, space_size_z);
|
||||||
|
printf(" arbitrary = %d one_batch_size = %d", arbitrary, one_batch_size);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prints the result of the function set_arrow()
|
||||||
|
* and indicates the reasons of the choice (call) this function makes (see this function)
|
||||||
|
*/
|
||||||
|
#define TEST 0
|
||||||
|
void show_user_action(struct arrow_t *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) { // *(arrows + i * 5 + 0)
|
||||||
|
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); //arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
|
||||||
|
if (! TEST) printf("\n "); else printf(" ");
|
||||||
|
printf("=> CREATE"); return;}
|
||||||
|
|
||||||
|
if (address >= 0 && requested_weight == 0) {
|
||||||
|
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
|
||||||
|
if (! TEST) printf("\n "); else printf(" ");
|
||||||
|
printf("=> ERASE"); return;}
|
||||||
|
|
||||||
|
if (address >= 0 && current_weight != requested_weight) {
|
||||||
|
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d; current_weight = %2d;", site, x, y, z, address, current_weight); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5, current_weight);
|
||||||
|
if (! TEST) printf("\n "); else printf(" ");
|
||||||
|
printf("=> MODIFY"); return;}
|
||||||
|
|
||||||
|
if (address >= 0 && current_weight == requested_weight){
|
||||||
|
printf("arrow (%2d,%2d,%2d,%2d) found at address %2d;", site, x, y, z, address); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4], address/5);
|
||||||
|
if (! TEST) printf("\n "); else printf(" ");
|
||||||
|
printf("requested_weight == current_weight => END"); return;}
|
||||||
|
|
||||||
|
if (address == -1 && requested_weight == 0) {
|
||||||
|
printf("no such arrow found (%2d,%2d,%2d,%2d)", site, x, y, z); // arrows[address + 1], arrows[address + 2], arrows[address + 3], arrows[address + 4]);
|
||||||
|
if (! TEST) printf("\n "); else printf(" ");
|
||||||
|
printf("=> END"); return;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prints vertex and lines buffers_states (sizes) at major one_batch_sizes and at the end of a session.
|
||||||
|
* Major one_batch_sizes are creation of grids and creation of arrows
|
||||||
|
* Arithmetic verification is provided at each one_batch_size
|
||||||
|
*/
|
||||||
|
void show_buffers_states(int space_X, int space_Y, int space_Z,
|
||||||
|
long nb_batches_specified, int one_batch_size,
|
||||||
|
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 = %9d\t%9d = (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 = %9d\t%9d = %d + %d; <--> %d = 12 x %d (%d cubes)",\
|
||||||
|
offset_after_arrows, offset_after_arrows, offset_after_grids,\
|
||||||
|
difference, difference, difference / 12, difference / 12);
|
||||||
|
|
||||||
|
printf("\n buffer_lines_offset after cubes = %9d\t%9d = 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 = %9d\t%9d = %d + %d; <--> %d = 14 x %d (%d arrows drawned)",\
|
||||||
|
buffer_lines_size, buffer_lines_size, buffer_lines_size_after_cubes,\
|
||||||
|
buffer_lines_size - buffer_lines_size_after_cubes,\
|
||||||
|
buffer_lines_size - buffer_lines_size_after_cubes, (buffer_lines_size - buffer_lines_size_after_cubes) / 14,\
|
||||||
|
(buffer_lines_size - buffer_lines_size_after_cubes) / 14);
|
||||||
|
|
||||||
|
if (nb_batches_specified * one_batch_size == 0) printf("\n");
|
||||||
|
else printf("\n WARNING Arrows of the same address, whatever their weight, are drawn in superimposition. Check their list.");
|
||||||
|
|
||||||
|
printf("\n It happens that NOT all the specified arrows (%ld) = (%ld x %d) are drawned (%d) ! WHY ? (d = %ld)\n",\
|
||||||
|
nb_batches_specified * one_batch_size, nb_batches_specified, one_batch_size, (buffer_lines_size - buffer_lines_size_after_cubes) / 14,\
|
||||||
|
nb_batches_specified * one_batch_size - (buffer_lines_size - buffer_lines_size_after_cubes) / 14);
|
||||||
|
}
|
||||||
|
|
|
@ -113,15 +113,6 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id,
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO ?
|
|
||||||
* Should a function "graphics_erase_line (GLuint a, GLuint b)" be used ?
|
|
||||||
* symetric with graphics_write_line (GLuint a, GLuint b)
|
|
||||||
*
|
|
||||||
* NB in this version lines only can be erased,
|
|
||||||
* and similar functions for vertex and plans have not to be considered.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*
|
*
|
||||||
|
@ -278,7 +269,6 @@ bool graphics_init_shaders(const void *gl_area)
|
||||||
return false;
|
return false;
|
||||||
vertex = create_shader(GL_VERTEX_SHADER, vertex_shader);
|
vertex = create_shader(GL_VERTEX_SHADER, vertex_shader);
|
||||||
|
|
||||||
// ! WARNING ! l'instruction suivante (ou un autre 'free') a pu provoquer un 'double free' (Abandon)
|
|
||||||
if(vertex == 0) {
|
if(vertex == 0) {
|
||||||
entry->program = 0;
|
entry->program = 0;
|
||||||
g_free(vertex_shader);
|
g_free(vertex_shader);
|
||||||
|
@ -601,9 +591,11 @@ static void show_user_choices(struct arrow_t *arrows, int arrows_nb,
|
||||||
{
|
{
|
||||||
if (show_array) printf("\n");
|
if (show_array) printf("\n");
|
||||||
printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\t", space_size_x, space_size_y, space_size_z);
|
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 (show_all && prefer == 0) printf("prefer = %d <> show all grids", prefer);
|
||||||
if (prefer == 1) printf("prefer = %d <> show no grid", prefer);
|
if (show_all && prefer == 1) printf("prefer = %d <> show no grid", prefer);
|
||||||
if (prefer > 1) printf("show grids according rule (%d)", prefer);
|
if (show_all && prefer > 1) printf("show grids according rule (%d)", prefer);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
if (show_all) printf("\n\
|
if (show_all) printf("\n\
|
||||||
initial arrows data with arrows_nb = %d", 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);
|
if (show_array) show_arrows_array (arrows, arrows_nb, space_size_x, space_size_y, space_size_z);
|
||||||
|
@ -645,6 +637,7 @@ static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrow
|
||||||
|
|
||||||
if (arrows_nb > 1)
|
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");
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -879,13 +872,12 @@ 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 = 4000000;
|
int arbitrary = 4;
|
||||||
int space_arbitrary = 200;
|
int space_X = 3, // 1 + rand() % arbitrary,
|
||||||
int space_X = 200 + rand() % space_arbitrary,
|
space_Y = 3, // 1 + rand() % arbitrary,
|
||||||
space_Y = 200 + rand() % space_arbitrary,
|
space_Z = 3; // 1 + rand() % arbitrary;
|
||||||
space_Z = 200 + rand() % space_arbitrary;
|
|
||||||
int density_max = space_X * space_Y * space_Z;
|
int density_max = space_X * space_Y * space_Z;
|
||||||
int arrows_nb = 0;
|
int arrows_nb = 0;//rand() % density_max;
|
||||||
int pref_show_grids = 1; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
int pref_show_grids = 1; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
|
||||||
// xyz, 0, x, y, z, xy, xz, yz, xyz
|
// xyz, 0, x, y, z, xy, xz, yz, xyz
|
||||||
int weight = 0, site = 0,
|
int weight = 0, site = 0,
|
||||||
|
@ -894,81 +886,66 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
|
||||||
int buffer_lines_size_after_cubes = buffer_lines_size;
|
int buffer_lines_size_after_cubes = buffer_lines_size;
|
||||||
int offset_up_to_this_cube_coords = 0, x, y, z;
|
int offset_up_to_this_cube_coords = 0, x, y, z;
|
||||||
|
|
||||||
/* arrows = g_malloc0(arrows_nb * sizeof(struct arrow_t)); */
|
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0);
|
||||||
|
|
||||||
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1, 0);
|
write_space_ridges (space_X, space_Y, space_Z);
|
||||||
|
write_marks_along_space_ridges (space_X, space_Y, space_Z);
|
||||||
// WARNING arrows with same address will be drawn superimposed
|
|
||||||
/* if (arrows_nb > 0) */
|
|
||||||
/* for (int i = 0; i < arrows_nb; i ++) { */
|
|
||||||
/* arrows[i].load = 1 + rand() % arbitrary; */
|
|
||||||
/* arrows[i].site = rand() % 6; */
|
|
||||||
/* arrows[i].x = rand() % space_X; */
|
|
||||||
/* arrows[i].y = rand() % space_Y; */
|
|
||||||
/* arrows[i].z = rand() % space_Z; */
|
|
||||||
/* }; */
|
|
||||||
|
|
||||||
// forget the next two lines during the random tests
|
|
||||||
// arrows[] = {... some values ...}
|
|
||||||
// int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5;
|
|
||||||
|
|
||||||
/* GRID */
|
/* GRID */
|
||||||
grid_write_intersections (space_X, space_Y, space_Z);
|
/* 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 % 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 % 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 % 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);
|
/* if (pref_show_grids > 0) grid_write_ridges (space_X, space_Y, space_Z); */
|
||||||
|
|
||||||
|
/* grid_write_marks (space_X, space_Y, space_Z); */
|
||||||
|
|
||||||
/* ARROWS */
|
/* ARROWS */
|
||||||
/* NB The 12 vertices required to draw 6 arrows in each cube
|
/* NB The 12 vertices required to draw 6 arrows in each cube
|
||||||
* are always defined (whether arrows are drawn or not). */
|
* are always defined (whether arrows are drawn or not). */
|
||||||
/* Therefore: if (arrows_nb > 0) is not required (next line) */
|
/* Therefore: if (arrows_nb > 0) is not required (next line) */
|
||||||
arrows_write_terminations (space_X, space_Y, space_Z);
|
/* arrows_write_terminations (space_X, space_Y, space_Z); */
|
||||||
|
|
||||||
/* Writing 100 by 100*/
|
/* volatile int remaining = arbitrary; */
|
||||||
volatile int remaining = arbitrary;
|
/* while (remaining) { */
|
||||||
while (remaining) {
|
/* for (int l = 0; l < 10; l++) { */
|
||||||
for (int l = 0; l < 10; l++) {
|
/* arrows_nb = set_arrow (arrows, arrows_nb, */
|
||||||
arrows_nb = set_arrow (arrows, arrows_nb,
|
/* rand() % arbitrary, // load / weight */
|
||||||
rand() % arbitrary, // load / weight
|
/* rand() % 6, // site, */
|
||||||
rand() % 6, // site,
|
/* rand() % space_X, // x */
|
||||||
rand() % space_X, // x
|
/* rand() % space_Y, // y */
|
||||||
rand() % space_Y, // y
|
/* rand() % space_Z); // z */
|
||||||
rand() % space_Z); // z
|
/* } */
|
||||||
}
|
/* remaining -= 10; */
|
||||||
remaining -= 100;
|
|
||||||
|
|
||||||
for (int i = 0; i < arrows_nb; i++) {
|
/* for (int i = 0; i < arrows_nb; i++) { */
|
||||||
weight = arrows[i].load;
|
/* weight = arrows[i].load; */
|
||||||
site = arrows[i].site;
|
/* site = arrows[i].site; */
|
||||||
x = arrows[i].x;
|
/* x = arrows[i].x; */
|
||||||
y = arrows[i].y;
|
/* y = arrows[i].y; */
|
||||||
z = arrows[i].z;
|
/* z = arrows[i].z; */
|
||||||
|
|
||||||
offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z);
|
/* offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z); */
|
||||||
arrow_offset = offset_after_grids + offset_up_to_this_cube_coords;
|
/* arrow_offset = offset_after_grids + offset_up_to_this_cube_coords; */
|
||||||
|
|
||||||
arrows_write_basis (arrow_offset);
|
/* arrows_write_basis (arrow_offset); */
|
||||||
|
|
||||||
switch(site){
|
/* switch(site){ */
|
||||||
case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, weight, site); break;
|
/* 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 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;
|
/* case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, weight, site); break; */
|
||||||
default: break;
|
/* default: break; */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
free(arrows);
|
/* free(arrows); */
|
||||||
arrows = NULL;
|
/* arrows = NULL; */
|
||||||
arrows_nb = 0;
|
/* arrows_nb = 0; */
|
||||||
if (TEST) printf("\nCreated %d arrows", arbitrary - remaining);
|
/* if (TEST) printf("\nCreated %d arrows", arbitrary - remaining); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
// ligne suivante inutile: < ce sont les sous-fonctions de set_arrow() qui appellent
|
/* show_buffers_states(space_X, space_Y, space_Z, arrows_nb, */
|
||||||
// show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1, 1);
|
/* offset_after_grids, buffer_vertex_size, */
|
||||||
|
/* buffer_lines_size_after_cubes, buffer_lines_size); */
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,89 @@
|
||||||
|
|
||||||
#include "../../include/base.h"
|
#include "../../include/base.h"
|
||||||
#include "../../include/graphics.h"
|
#include "../../include/graphics.h"
|
||||||
|
|
||||||
|
void write_space_ridges (long x, long y, long z)
|
||||||
|
{
|
||||||
|
float max = fmax(x, y); max = fmax(max, z);
|
||||||
|
|
||||||
|
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_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_vertex (+ x / max, + y / max, + z / max);
|
||||||
|
|
||||||
|
graphics_write_line ( 0, 1); graphics_write_line ( 7, 4);
|
||||||
|
graphics_write_line ( 0, 2); graphics_write_line ( 7, 5);
|
||||||
|
graphics_write_line ( 0, 3); graphics_write_line ( 7, 6);
|
||||||
|
|
||||||
|
graphics_write_line ( 1, 4); graphics_write_line ( 2, 4);
|
||||||
|
graphics_write_line ( 1, 5); graphics_write_line ( 3, 5);
|
||||||
|
graphics_write_line ( 2, 6); graphics_write_line ( 3, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_marks_along_space_ridges (long x, long y, long z)
|
||||||
|
{
|
||||||
|
float i, j, k, vx, vy, vz, max = fmax(x, y);
|
||||||
|
max = fmax(max, z);
|
||||||
|
// printf("\n");
|
||||||
|
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;
|
||||||
|
|
||||||
|
if ((i == 0 && j == 0) || (i == 0 && j == y) || (i == x && j == 0) || (i == x && j == y)
|
||||||
|
|| (i == 0 && k == 0) || (i == 0 && k == z) || (i == x && k == 0) || (i == x && k == z)
|
||||||
|
|| (j == 0 && k == 0) || (j == 0 && k == z) || (j == y && k == 0) || (j == y && k == z))
|
||||||
|
|
||||||
|
graphics_write_vertex (vx, vy, vz);
|
||||||
|
};
|
||||||
|
|
||||||
|
int buffer_lines_offset = 24;
|
||||||
|
|
||||||
|
graphics_write_line (buffer_lines_offset + 0, buffer_lines_offset + 2);
|
||||||
|
graphics_write_line (buffer_lines_offset + 1, buffer_lines_offset + 3);
|
||||||
|
|
||||||
|
graphics_write_line (buffer_lines_offset + 1, buffer_lines_offset + 0);
|
||||||
|
graphics_write_line (buffer_lines_offset + 2, buffer_lines_offset + 3);
|
||||||
|
|
||||||
|
graphics_write_line (buffer_lines_offset + 8, buffer_lines_offset + 9);
|
||||||
|
graphics_write_line (buffer_lines_offset + 10, buffer_lines_offset + 11);
|
||||||
|
|
||||||
|
graphics_write_line (buffer_lines_offset + 5, buffer_lines_offset + 13);
|
||||||
|
graphics_write_line (buffer_lines_offset + 6, buffer_lines_offset + 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Writes grid lines intersections to vertex and color buffers
|
* Writes grid lines intersections to vertex and color buffers
|
||||||
|
@ -47,7 +130,7 @@ void grid_write_intersections (long x, long y, long z)
|
||||||
vz = (2 * k / z - 1) * z / max;
|
vz = (2 * k / z - 1) * z / max;
|
||||||
|
|
||||||
graphics_write_vertex (vx, vy, vz);
|
graphics_write_vertex (vx, vy, vz);
|
||||||
graphics_write_color (0.64f,0.64f,0.64f);
|
// graphics_write_color (0.64f,0.64f,0.64f);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +141,20 @@ void grid_write_intersections (long x, long y, long z)
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void grid_write_ridges (long x,
|
void grid_write_marks (long x, long y, long z)
|
||||||
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),
|
long step_x = (z + 1) * (y + 1),
|
||||||
step_y = z + 1,
|
step_y = z + 1,
|
||||||
|
|
Loading…
Reference in New Issue