WIP: drawing space ONLY with indexes in GLuint instead of bytes since space is wide

This commit is contained in:
Jean Sirmai 2023-07-25 18:29:36 +02:00
parent 9b1c6bc773
commit 0ebfe61511
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 277 additions and 279 deletions

View File

@ -26,11 +26,11 @@
#include <stdbool.h>
#include <GL/glu.h>
bool compute_space_and_arrows(int model_space_size_x,
int model_space_size_y,
int model_space_size_z,
bool compute_space_and_arrows(long model_space_size_x,
long model_space_size_y,
long model_space_size_z,
GLubyte *arrows,
GLuint *arrows,
int model_arrows_nb,
int pref_mark_unit_space,
@ -39,8 +39,8 @@ bool compute_space_and_arrows(int model_space_size_x,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin);
GLuint *line_origin,
GLuint *plan_origin);

View File

@ -44,10 +44,10 @@
#include "../../include/graphics.h"
#include "../../include/buffers.h"
int vertex_ndx = 0;
int colors_ndx = 0;
int lines_ndx = 0;
int plans_ndx = 0;
static long vertex_buffer_size = 0;
static long colors_buffer_size = 0;
static long lines_buffer_size = 0;
static long plans_buffer_size = 0;
#define EDGE 0.999999
@ -70,9 +70,9 @@ static bool compute_space_2D(int size_x,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin)
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
float x = 0;
@ -98,78 +98,78 @@ static bool compute_space_2D(int size_x,
// fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f;
vertex_ndx += 6; if (V) printf(" => vertex_ndx = %3d space 2D\n", vertex_ndx);
vertex_buffer_size += 6; if (V) printf(" => vertex_buffer_size = %3ld space 2D\n", vertex_buffer_size);
*(color_origin + k * 6 + 0) = 1;
*(color_origin + k * 6 + 1) = 0;
*(color_origin + k * 6 + 2) = 0;
*(colors_origin + k * 6 + 0) = 1;
*(colors_origin + k * 6 + 1) = 0;
*(colors_origin + k * 6 + 2) = 0;
*(color_origin + k * 6 + 3) = 1;
*(color_origin + k * 6 + 4) = 1;
*(color_origin + k * 6 + 5) = 0;
*(colors_origin + k * 6 + 3) = 1;
*(colors_origin + k * 6 + 4) = 1;
*(colors_origin + k * 6 + 5) = 0;
colors_ndx += 6;
colors_buffer_size += 6;
*(line_origin + k * 2 + 0) = k * 2 + 0;
*(line_origin + k * 2 + 1) = k * 2 + 1;
*(lines_origin + k * 2 + 0) = k * 2 + 0;
*(lines_origin + k * 2 + 1) = k * 2 + 1;
lines_ndx += 2; if (L) printf(" => lines_ndx = %3d space 2D\n", lines_ndx);
lines_buffer_size += 2; if (L) printf(" => lines_buffer_size = %3ld space 2D\n", lines_buffer_size);
}
*(color_origin + 0) = 0;
*(color_origin + 1) = 0;
*(color_origin + 2) = 0;
*(colors_origin + 0) = 0;
*(colors_origin + 1) = 0;
*(colors_origin + 2) = 0;
*(color_origin + 3) = 1;
*(color_origin + 4) = 1;
*(color_origin + 5) = 1;
*(colors_origin + 3) = 1;
*(colors_origin + 4) = 1;
*(colors_origin + 5) = 1;
*(color_origin + (size_x - 1) * 6 + 0) = 1;
*(color_origin + (size_x - 1) * 6 + 1) = 1;
*(color_origin + (size_x - 1) * 6 + 2) = 1;
*(colors_origin + (size_x - 1) * 6 + 0) = 1;
*(colors_origin + (size_x - 1) * 6 + 1) = 1;
*(colors_origin + (size_x - 1) * 6 + 2) = 1;
*(color_origin + (size_x - 1) * 6 + 3) = 0;
*(color_origin + (size_x - 1) * 6 + 4) = 0;
*(color_origin + (size_x - 1) * 6 + 5) = 0;
*(colors_origin + (size_x - 1) * 6 + 3) = 0;
*(colors_origin + (size_x - 1) * 6 + 4) = 0;
*(colors_origin + (size_x - 1) * 6 + 5) = 0;
colors_ndx += 12; if (C) printf(" => colors_ndx = %d\n", colors_ndx);
colors_buffer_size += 12; if (C) printf(" => colors_buffer_size = %ld\n", colors_buffer_size);
*(line_origin + lines_ndx + 0) = 0;
*(line_origin + lines_ndx + 1) = size_x * 2 - 2; // barre horizontale du bas
*(lines_origin + lines_buffer_size + 0) = 0;
*(lines_origin + lines_buffer_size + 1) = size_x * 2 - 2; // barre horizontale du bas
*(line_origin + lines_ndx + 2) = 1;
*(line_origin + lines_ndx + 3) = size_x * 2 - 1; // barre horizontale du haut
*(lines_origin + lines_buffer_size + 2) = 1;
*(lines_origin + lines_buffer_size + 3) = size_x * 2 - 1; // barre horizontale du haut
lines_ndx += 4; if (L) printf("H=> lines_ndx = %3d space 2D H\n", lines_ndx);
lines_buffer_size += 4; if (L) printf("H=> lines_buffer_size = %3ld space 2D H\n", lines_buffer_size);
if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit
{
*(line_origin + lines_ndx + 0) = 0;
*(line_origin + lines_ndx + 1) = 3;
*(lines_origin + lines_buffer_size + 0) = 0;
*(lines_origin + lines_buffer_size + 1) = 3;
*(line_origin + lines_ndx + 2) = 1;
*(line_origin + lines_ndx + 3) = 2;
*(lines_origin + lines_buffer_size + 2) = 1;
*(lines_origin + lines_buffer_size + 3) = 2;
lines_ndx += 4; if (L) printf("X=> lines_ndx = %3d space 2D X\n", lines_ndx);
lines_buffer_size += 4; if (L) printf("X=> lines_buffer_size = %3ld space 2D X\n", lines_buffer_size);
}
if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit
{
*(line_origin + lines_ndx + 0) = (size_x - 2) * 2 + 0;
*(line_origin + lines_ndx + 1) = (size_x - 2) * 2 + 3;
*(lines_origin + lines_buffer_size + 0) = (size_x - 2) * 2 + 0;
*(lines_origin + lines_buffer_size + 1) = (size_x - 2) * 2 + 3;
*(line_origin + lines_ndx + 2) = (size_x - 2) * 2 + 1;
*(line_origin + lines_ndx + 3) = (size_x - 2) * 2 + 2;
*(lines_origin + lines_buffer_size + 2) = (size_x - 2) * 2 + 1;
*(lines_origin + lines_buffer_size + 3) = (size_x - 2) * 2 + 2;
lines_ndx +=4; if (L) printf("X=> lines_ndx = %3d space 2D X\n", lines_ndx);
lines_buffer_size +=4; if (L) printf("X=> lines_buffer_size = %3ld space 2D X\n", lines_buffer_size);
}
if (S) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x);
if (S) printf("space_2D line_origin (%d - size_x(0)) x (%d - size_x(1)) ", 0, 1);
if (S) printf("space_2D lines_origin (%d - size_x(0)) x (%d - size_x(1)) ", 0, 1);
for (int v = 0; v < size_x + 2; v++)
if (S) printf("(%d-%d) ", *(line_origin + v), *(line_origin + v + 1));
if (S) printf("(%d-%d) ", *(lines_origin + v), *(lines_origin + v + 1));
if (S) printf(" n = 4 + (%d x 2)\n", size_x + 2);
return 1;
@ -190,9 +190,9 @@ static int compute_arrow_2D(int size_x,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin)
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
printf("compute_arrow_2D load = %d site = %d x = %d\n", weight, site, x);
float zero = 0.0f;
@ -214,47 +214,47 @@ static int compute_arrow_2D(int size_x,
/* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* } */
*(vertex_origin + vertex_ndx + 0) = tip;
*(vertex_origin + vertex_ndx + 1) = zero;
*(vertex_origin + vertex_ndx + 2) = zero;
*(vertex_origin + vertex_buffer_size + 0) = tip;
*(vertex_origin + vertex_buffer_size + 1) = zero;
*(vertex_origin + vertex_buffer_size + 2) = zero;
*(vertex_origin + vertex_ndx + 3) = base;
*(vertex_origin + vertex_ndx + 4) = lat;
*(vertex_origin + vertex_ndx + 5) = zero;
*(vertex_origin + vertex_buffer_size + 3) = base;
*(vertex_origin + vertex_buffer_size + 4) = lat;
*(vertex_origin + vertex_buffer_size + 5) = zero;
*(vertex_origin + vertex_ndx + 6) = base;
*(vertex_origin + vertex_ndx + 7) = - lat;
*(vertex_origin + vertex_ndx + 8) = zero;
*(vertex_origin + vertex_buffer_size + 6) = base;
*(vertex_origin + vertex_buffer_size + 7) = - lat;
*(vertex_origin + vertex_buffer_size + 8) = zero;
vertex_ndx += 9; if (V) printf(" => vertex_ndx = %3d arrow_2D\n", vertex_ndx);
vertex_buffer_size += 9; if (V) printf(" => vertex_buffer_size = %3ld arrow_2D\n", vertex_buffer_size);
if (pref_style_lines_planes == 0) {
if (V) printf("0=> lines_ndx = %d\n", lines_ndx);
if (V) printf("0=> lines_buffer_size = %ld\n", lines_buffer_size);
*(line_origin + lines_ndx + 0) = vertex_ndx / 3 - 3;
*(line_origin + lines_ndx + 1) = vertex_ndx / 3 - 2;
*(lines_origin + lines_buffer_size + 0) = vertex_buffer_size / 3 - 3;
*(lines_origin + lines_buffer_size + 1) = vertex_buffer_size / 3 - 2;
*(line_origin + lines_ndx + 2) = vertex_ndx / 3 - 3;
*(line_origin + lines_ndx + 3) = vertex_ndx / 3 - 1;
*(lines_origin + lines_buffer_size + 2) = vertex_buffer_size / 3 - 3;
*(lines_origin + lines_buffer_size + 3) = vertex_buffer_size / 3 - 1;
*(line_origin + lines_ndx + 4) = vertex_ndx / 3 - 2;
*(line_origin + lines_ndx + 5) = vertex_ndx / 3 - 1;
*(lines_origin + lines_buffer_size + 4) = vertex_buffer_size / 3 - 2;
*(lines_origin + lines_buffer_size + 5) = vertex_buffer_size / 3 - 1;
lines_ndx += 6; if (L) printf("|=> lines_ndx = %3d arrow_2D\n", lines_ndx);
lines_buffer_size += 6; if (L) printf("|=> lines_buffer_size = %3ld arrow_2D\n", lines_buffer_size);
}
if (pref_style_lines_planes == 1) {
*(plan_origin + plans_ndx + 0) = vertex_ndx / 3 + 0;
*(plan_origin + plans_ndx + 1) = vertex_ndx / 3 + 1;
*(plan_origin + plans_ndx + 2) = vertex_ndx / 3 + 2;
*(plans_origin + plans_buffer_size + 0) = vertex_buffer_size / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = vertex_buffer_size / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = vertex_buffer_size / 3 + 2;
*(plan_origin + plans_ndx + 3) = vertex_ndx / 3 + 0;
*(plan_origin + plans_ndx + 4) = vertex_ndx / 3 + 1;
*(plan_origin + plans_ndx + 5) = vertex_ndx / 3 + 2;
*(plans_origin + plans_buffer_size + 3) = vertex_buffer_size / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = vertex_buffer_size / 3 + 1;
*(plans_origin + plans_buffer_size + 5) = vertex_buffer_size / 3 + 2;
plans_ndx += 6; if (P) printf("|=> plans_ndx = %d\n", plans_ndx);
plans_buffer_size += 6; if (P) printf("|=> plans_buffer_size = %ld\n", plans_buffer_size);
}
return 0;
}
@ -290,51 +290,51 @@ static int compute_arrow_2D(int size_x,
#define CORRC 1.3
#define CORRC 3
#define P 0
static bool compute_space_3D (int x,
int y,
int z,
static bool compute_space_3D (long x,
long y,
long z,
int pref_mark_unit_space,
int pref_style_lines_planes,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin)
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
int maximum = 0, c = 0; // TODO max = math.max(max, x);
for (c = 0; c < x; c++) if (c > maximum) maximum = c;
for (c = 0; c < y; c++) if (c > maximum) maximum = c;
for (c = 0; c < z; c++) if (c > maximum) maximum = c;
long maximum = fmax(x, y);
maximum = fmax(maximum, z);
float i, j, k, vx, vy, vz, max = maximum * CORRC;
printf("max(%d,%d,%d) = %d; size_x / max = %6.3f; size_y / max = %6.3f; size_z / max = %6.3f\n",\
x - 1, y - 1, z - 1, maximum, (x - 1) / max, (y - 1) / max, (z - 1) / max);
printf("max(%ld,%ld,%ld) = %ld; size_x / max = %6.3f; size_y / max = %6.3f; size_z / max = %6.3f\n",\
x, y, z, maximum, x / max, y / max, z / max);
for (i = 0; i < x; i++){
for (j = 0; j < y; j++){
for (k = 0; k < z; k++){
vx = (2 * i / (x - 1) - 1) * (x - 1) / max;
vy = (2 * j / (y - 1) - 1) * (y - 1) / max;
vz = (2 * k / (z - 1) - 1) * (z - 1) / max;
//printf("vertex_origin = %ld\n", vertex_origin);
*(vertex_origin + vertex_ndx + 0) = vx;
*(vertex_origin + vertex_ndx + 1) = vy;
*(vertex_origin + vertex_ndx + 2) = vz;
vx = (2 * i / (x - 1) - 1) * x / max;
vy = (2 * j / (y - 1) - 1) * y / max;
vz = (2 * k / (z - 1) - 1) * z / max;
vertex_ndx += 3; // if (V) printf(" => vertex_ndx = %3d\n", vertex_ndx);
*(vertex_origin + vertex_buffer_size + 0) = vx;
*(vertex_origin + vertex_buffer_size + 1) = vy;
*(vertex_origin + vertex_buffer_size + 2) = vz;
*(color_origin + colors_ndx + 0) = vx;
*(color_origin + colors_ndx + 1) = 3 * vy / 2;
*(color_origin + colors_ndx + 2) = 3 * vz / 2;
vertex_buffer_size += 3; // if (V) printf(" => vertex_buffer_size = %3d\n", vertex_buffer_size);
colors_ndx += 3; // if (C) printf(" => colors_ndx = %3d\n", colors_ndx);23.
*(colors_origin + colors_buffer_size + 0) = 3 * vx / 2;
*(colors_origin + colors_buffer_size + 1) = 3 * vy / 2;
*(colors_origin + colors_buffer_size + 2) = 3 * vz / 2;
colors_buffer_size += 3; // if (C) printf(" => colors_buffer_size = %3d\n", colors_buffer_size);23.
if (P) printf("(%1.0f*%1.0f*%1.0f)<>[%6.3f %6.3f %6.3f] ", i, j, k, vx, vy, vz);
}
@ -343,92 +343,105 @@ static bool compute_space_3D (int x,
if (P) printf("\n");
};
int step_z = 1, step_y = z, step_x = y * z;//(y - 1) * (z - 1);
long step_z = 1, step_y = z, step_x = y * z;//y * z;
/* for (int u = 0; u < y; u ++){ */
/* for (int w = 0; w < z; w ++){ */
/* *(line_origin + lines_ndx) = w + z * u; lines_ndx += 1; */
/* *(line_origin + lines_ndx) = x * y * z - y * z + w + z * u; lines_ndx += 1; */
/* *(lines_origin + lines_buffer_size) = w + z * u; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = x * y * z - y * z + w + z * u; lines_buffer_size += 1; */
/* } */
/* } */
/* for (int u = 0; u < y; u ++){ */
/* for (int w = 0; w < x; w ++){ */
/* *(line_origin + lines_ndx) = z * y * w + z * u; lines_ndx += 1; */
/* *(line_origin + lines_ndx) = z * y * w + z - 1 + z * u; lines_ndx += 1; */
/* *(lines_origin + lines_buffer_size) = z * y * w + z * u; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = z * y * w + z - 1 + z * u; lines_buffer_size += 1; */
/* } */
/* } */
/* for (int u = 0; u < x; u ++){ */
/* for (int w = 0; w < z; w ++){ */
/* *(line_origin + lines_ndx) = z * y * u + w; lines_ndx += 1; */
/* *(line_origin + lines_ndx) = z * y * u + z * y - z + w; lines_ndx += 1; */
/* *(lines_origin + lines_buffer_size) = z * y * u + w; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = z * y * u + z * y - z + w; lines_buffer_size += 1; */
/* } */
/* } */
*(line_origin + lines_ndx) = step_z * 0 + step_y * 0 + step_x * 0; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 0 + step_y * 0 + step_x * (x - 1); lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * 0 + step_x * 0; lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * 0 + step_x * (x - 1); lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * 0 + step_y * 0 + step_x * 0; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 0 + step_y * (y - 1) + step_x * 0; lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * 0 + step_x * 0; lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * (y - 1) + step_x * 0; lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * 0 + step_y * 0 + step_x * 0; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * 0 + step_x * 0; lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * 0 + step_x * 0; lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * 0 + step_x * 0; lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 0 + step_y * (y - 1) + step_x * (x - 1); lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * 0 + step_y * (y - 1) + step_x * (x - 1); lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * (y - 1) + step_x * 0; lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * (y - 1) + step_x * 0; lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * (z - 1) + step_y * 0 + step_x * (x - 1); lines_ndx += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_buffer_size += 1;
*(lines_origin + lines_buffer_size) = step_z * (z - 1) + step_y * 0 + step_x * (x - 1); lines_buffer_size += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 3; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 3; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 4; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 3; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 4; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 4; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 4; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 1 + step_y * 2 + step_x * 4; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 3; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 2 + step_y * 2 + step_x * 4; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
*(line_origin + lines_ndx) = step_z * 2 + step_y * 3 + step_x * 3; lines_ndx += 1;
*(line_origin + lines_ndx) = step_z * 1 + step_y * 3 + step_x * 3; lines_ndx += 1;
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 4; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 2 + step_y * 2 + step_x * 3; lines_buffer_size += 1; */
/* *(lines_origin + lines_buffer_size) = step_z * 1 + step_y * 3 + step_x * 4; lines_buffer_size += 1; */
//if (S3) printf("space 3D buffer_lines (from-to) ");
printf("nb lines / nb vertex = %d/%d ", lines_ndx / 2, vertex_ndx / 3);
for (int v = 0; v < lines_ndx / 2; v ++) {
printf("nb lines / nb vertex = %ld/%ld ", lines_buffer_size / 2, vertex_buffer_size / 3);
for (int v = 0; v < lines_buffer_size / 2; v ++) {
if (S3) printf("(%d-%d) ",\
*(line_origin + 2 * v), *(line_origin + 2 * v + 1));
*(lines_origin + 2 * v), *(lines_origin + 2 * v + 1));
}
if (S3) printf(" \n");
@ -466,23 +479,23 @@ static bool compute_space_3D (int x,
static bool compute_arrow_3D(int size_x,
int size_y,
int size_z,
static bool compute_arrow_3D(long size_x,
long size_y,
long size_z,
int weight,
int site,
int x,
int y,
int z,
int site, // North, South, East, West, Zenith, nAdir (NSEWZA)
long x,
long y,
long z,
int pref_style_lines_planes,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin)
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
float zero = 0.0f;
@ -490,97 +503,97 @@ static bool compute_space_3D (int x,
float tip = center + (2 * site - 1) * (1.0f / size_x);
float base = center + (2 * site - 1) * (0.1f / size_x);
*(vertex_origin + vertex_ndx + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f);
*(vertex_origin + vertex_ndx + 1) = zero;
*(vertex_origin + vertex_ndx + 2) = zero;
*(vertex_origin + vertex_buffer_size + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f);
*(vertex_origin + vertex_buffer_size + 1) = zero;
*(vertex_origin + vertex_buffer_size + 2) = zero;
*(vertex_origin + vertex_ndx + 3) = base;
*(vertex_origin + vertex_ndx + 4) = 0.4f / size_x;
*(vertex_origin + vertex_ndx + 5) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 3) = base;
*(vertex_origin + vertex_buffer_size + 4) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 5) = 0.4f / size_x;
*(vertex_origin + vertex_ndx + 6) = base;
*(vertex_origin + vertex_ndx + 7) = 0.4f / size_x;
*(vertex_origin + vertex_ndx + 8) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 6) = base;
*(vertex_origin + vertex_buffer_size + 7) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 8) = - 0.4f / size_x;
*(vertex_origin + vertex_ndx + 9) = base;
*(vertex_origin + vertex_ndx + 10) = - 0.4f / size_x;
*(vertex_origin + vertex_ndx + 11) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 9) = base;
*(vertex_origin + vertex_buffer_size + 10) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 11) = - 0.4f / size_x;
*(vertex_origin + vertex_ndx + 12) = base;
*(vertex_origin + vertex_ndx + 13) = - 0.4f / size_x;
*(vertex_origin + vertex_ndx + 14) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 12) = base;
*(vertex_origin + vertex_buffer_size + 13) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 14) = 0.4f / size_x;
vertex_ndx += 15; if (V) printf(" => vertex_ndx = %3d arrow_3D\n", vertex_ndx);
vertex_buffer_size += 15; if (V) printf(" => vertex_buffer_size = %3ld arrow_3D\n", vertex_buffer_size);
if (A3) printf("center = %f tip = %f base = %f\n",\
center, tip, base); // size_x * 12=%d igap=%d
if (pref_style_lines_planes == 0) {
*(line_origin + lines_ndx + 0) = vertex_ndx / 3 - 5;
*(line_origin + lines_ndx + 1) = vertex_ndx / 3 - 4;
*(lines_origin + lines_buffer_size + 0) = vertex_buffer_size / 3 - 5;
*(lines_origin + lines_buffer_size + 1) = vertex_buffer_size / 3 - 4;
*(line_origin + lines_ndx + 2) = vertex_ndx / 3 - 5;
*(line_origin + lines_ndx + 3) = vertex_ndx / 3 - 3;
*(lines_origin + lines_buffer_size + 2) = vertex_buffer_size / 3 - 5;
*(lines_origin + lines_buffer_size + 3) = vertex_buffer_size / 3 - 3;
*(line_origin + lines_ndx + 4) = vertex_ndx / 3 - 5;
*(line_origin + lines_ndx + 5) = vertex_ndx / 3 - 2;
*(lines_origin + lines_buffer_size + 4) = vertex_buffer_size / 3 - 5;
*(lines_origin + lines_buffer_size + 5) = vertex_buffer_size / 3 - 2;
*(line_origin + lines_ndx + 6) = vertex_ndx / 3 - 5;
*(line_origin + lines_ndx + 7) = vertex_ndx / 3 - 1;
*(lines_origin + lines_buffer_size + 6) = vertex_buffer_size / 3 - 5;
*(lines_origin + lines_buffer_size + 7) = vertex_buffer_size / 3 - 1;
*(line_origin + lines_ndx + 8) = vertex_ndx / 3 - 4;
*(line_origin + lines_ndx + 9) = vertex_ndx / 3 - 3;
*(lines_origin + lines_buffer_size + 8) = vertex_buffer_size / 3 - 4;
*(lines_origin + lines_buffer_size + 9) = vertex_buffer_size / 3 - 3;
*(line_origin + lines_ndx + 10) = vertex_ndx / 3 - 3;
*(line_origin + lines_ndx + 11) = vertex_ndx / 3 - 2;
*(lines_origin + lines_buffer_size + 10) = vertex_buffer_size / 3 - 3;
*(lines_origin + lines_buffer_size + 11) = vertex_buffer_size / 3 - 2;
*(line_origin + lines_ndx + 12) = vertex_ndx / 3 - 2;
*(line_origin + lines_ndx + 13) = vertex_ndx / 3 - 1;
*(lines_origin + lines_buffer_size + 12) = vertex_buffer_size / 3 - 2;
*(lines_origin + lines_buffer_size + 13) = vertex_buffer_size / 3 - 1;
*(line_origin + lines_ndx + 14) = vertex_ndx / 3 - 1;
*(line_origin + lines_ndx + 15) = vertex_ndx / 3 - 4;
*(lines_origin + lines_buffer_size + 14) = vertex_buffer_size / 3 - 1;
*(lines_origin + lines_buffer_size + 15) = vertex_buffer_size / 3 - 4;
lines_ndx += 16; if (L) printf("|=> lines_ndx = %3d arrow_3D\n", lines_ndx);
lines_buffer_size += 16; if (L) printf("|=> lines_buffer_size = %3ld arrow_3D\n", lines_buffer_size);
}
if (pref_style_lines_planes == 1) {
*(plan_origin + plans_ndx + 0) = size_x * 12 / 3 + 0;
*(plan_origin + plans_ndx + 1) = size_x * 12 / 3 + 1;
*(plan_origin + plans_ndx + 2) = size_x * 12 / 3 + 2;
*(plans_origin + plans_buffer_size + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = size_x * 12 / 3 + 2;
*(plan_origin + plans_ndx + 3) = size_x * 12 / 3 + 0;
*(plan_origin + plans_ndx + 4) = size_x * 12 / 3 + 3;
*(plan_origin + plans_ndx + 5) = size_x * 12 / 3 + 4;
*(plans_origin + plans_buffer_size + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = size_x * 12 / 3 + 3;
*(plans_origin + plans_buffer_size + 5) = size_x * 12 / 3 + 4;
*(plan_origin + plans_ndx + 0) = size_x * 12 / 3 + 0;
*(plan_origin + plans_ndx + 1) = size_x * 12 / 3 + 1;
*(plan_origin + plans_ndx + 2) = size_x * 12 / 3 + 3;
*(plans_origin + plans_buffer_size + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = size_x * 12 / 3 + 3;
*(plan_origin + plans_ndx + 3) = size_x * 12 / 3 + 0;
*(plan_origin + plans_ndx + 4) = size_x * 12 / 3 + 2;
*(plan_origin + plans_ndx + 5) = size_x * 12 / 3 + 4;
*(plans_origin + plans_buffer_size + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = size_x * 12 / 3 + 2;
*(plans_origin + plans_buffer_size + 5) = size_x * 12 / 3 + 4;
plans_ndx += 12; if (P) printf("|=> plans_ndx = %3d arrow_3D\n", plans_ndx);
plans_buffer_size += 12; if (P) printf("|=> plans_buffer_size = %3ld arrow_3D\n", plans_buffer_size);
}
return 1;
}
static void show_user_choices(int model_size_x,
int model_size_y,
int model_size_z,
static void show_user_choices(long model_size_x,
long model_size_y,
long model_size_z,
GLubyte *arrows,
GLuint *arrows,
int model_arrows_nb,
int pref_mark_unit_space,
int pref_style_lines_planes,
int pref_style_mix_colors)
{
printf("model + user constraints : space size x,y,z = %d,%d,%d ", model_size_x, model_size_y, model_size_z);
printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", model_size_x, model_size_y, model_size_z);
if (model_arrows_nb > 0) printf("[%d] arrows ", model_arrows_nb);
if (pref_mark_unit_space == 0) printf("no unit_space marks ");
if (pref_mark_unit_space == 1) printf("first unit space marked ");
@ -600,11 +613,11 @@ static void show_user_choices(int model_size_x,
bool compute_space_and_arrows(int model_size_x,
int model_size_y,
int model_size_z,
bool compute_space_and_arrows(long model_size_x,
long model_size_y,
long model_size_z,
GLubyte *arrows,
GLuint *arrows,
int model_arrows_nb,
int pref_mark_unit_space,
@ -612,9 +625,9 @@ bool compute_space_and_arrows(int model_size_x,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *color_origin,
GLubyte *line_origin,
GLubyte *plan_origin)
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
if (SA) show_user_choices(model_size_x,
@ -628,18 +641,18 @@ bool compute_space_and_arrows(int model_size_x,
pref_style_lines_planes,
pref_style_mix_colors);
compute_space_3D (model_size_x + 1,
model_size_y + 1,
model_size_z + 1,
compute_space_3D (model_size_x,
model_size_y,
model_size_z,
pref_mark_unit_space,
pref_style_lines_planes,
pref_style_mix_colors,
vertex_origin,
color_origin,
line_origin,
plan_origin);
colors_origin,
lines_origin,
plans_origin);
for (int i = 0; i < model_arrows_nb; i++)
compute_arrow_3D (model_size_x,
@ -656,9 +669,9 @@ bool compute_space_and_arrows(int model_size_x,
pref_style_mix_colors,
vertex_origin,
color_origin,
line_origin,
plan_origin);
colors_origin,
lines_origin,
plans_origin);
return 0;
}
@ -666,3 +679,4 @@ bool compute_space_and_arrows(int model_size_x,

View File

@ -55,8 +55,8 @@ int model_arrows_nb = 0;
GLfloat *buffer_vertex_origin = NULL;
GLfloat *buffer_colors_origin = NULL;
GLubyte *buffer_lines_origin = NULL;
GLubyte *buffer_plans_origin = NULL;
GLuint *buffer_lines_origin = NULL;
GLuint *buffer_plans_origin = NULL;
//int pref_3D_xor_2D_space = 0; // default view == 0 == 3D
//int pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D
@ -522,7 +522,7 @@ bool graphics_init_shaders(const void *gl_area)
GLubyte arrows[] = {
GLuint arrows[] = {
1, 0, 0, 0, 0,
1, 1, 0, 0, 0,
1, 0, 1, 0, 0,
@ -539,9 +539,11 @@ GLubyte arrows[] = {
static void get_model_data_and_user_preferences(){
model_space_size_x = 7; // 0 < model_space_size_x
model_space_size_x = 50; // 0 < model_space_size_x
model_space_size_y = 5; // 0 < model_space_size_y
model_space_size_z = 4; // 0 < model_space_size_z
model_space_size_z = 5; // 0 < model_space_size_z
//
// XXX ONLY space drawed, no arrows
model_arrows_nb = 0; // assert : l'emplacement des flèches est contraint
// par model_space_size_x, y, z et le nombre de sites
@ -573,7 +575,7 @@ static void get_model_data_and_user_preferences(){
#define S 0
#define S 1
static void compute_buffers_sizes(int model_space_size_x,
int model_space_size_y,
int model_space_size_z,
@ -584,52 +586,32 @@ static void compute_buffers_sizes(int model_space_size_x,
int pref_style_lines_planes,
int pref_style_mix_colors)
{
// XXX ONLY space and no arrows
buffer_vertex_size = (model_space_size_x + 1)
* (model_space_size_y + 1)
* (model_space_size_z + 1)
* 3
+ model_space_size_x * 3
+ model_space_size_y * 3
+ model_space_size_z * 3
- 3;
* 3; // 3 numbers per vertex, one vertex per intersection
buffer_colors_size = buffer_vertex_size;
buffer_colors_size = (model_space_size_x + 1)
* (model_space_size_y + 1)
* (model_space_size_z + 1)
* 3
+ model_space_size_x * 3
+ model_space_size_y * 3
+ model_space_size_z * 3
- 3;
buffer_plans_size = 0;
buffer_lines_size = (model_space_size_x + 1) * 2
+ (model_space_size_y + 1) * 2
+ (model_space_size_z + 1) * 2;
buffer_lines_size = (model_space_size_x + 1)
* (model_space_size_y + 1)
* (model_space_size_z + 1)
* 3
- model_space_size_x
- model_space_size_y
- model_space_size_z
+ 3
+ 20; // je suis en 2D
// pourquoi est-ce possible ?
buffer_lines_size += 8 * pref_mark_unit_space; // 8 because 4 diagonal lines
// buffer_vertex_size += model_arrows_nb * 9; // je suis en 2D
buffer_vertex_size += model_arrows_nb * 15;
buffer_colors_size += model_arrows_nb * 15;
buffer_plans_size += 0;
// buffer_lines_size += model_arrows_nb * 6; // je suis en 2D
buffer_lines_size += model_arrows_nb * 16;
// XXX drawing matrix lines ONLY
// one line per intersection between dimension
buffer_lines_size = ((model_space_size_x+1) * (model_space_size_y+1))
+ ((model_space_size_x+1) * (model_space_size_z+1))
+ ((model_space_size_y+1) * (model_space_size_z+1));
if (S) printf("allocated buffers sizes :%4d/3 = %3d vertices, %4d/3 = %3d colors,\
%4d/2 = %3d lines, %4d/3 = %3d plans.\n",\
buffer_vertex_size, buffer_vertex_size / 3, buffer_colors_size, buffer_colors_size / 3,
buffer_lines_size, buffer_lines_size / 2, buffer_plans_size, buffer_plans_size / 3);
%4d/2 = %3d lines, %4d/3 = %3d plans.\n",
buffer_vertex_size,
buffer_vertex_size / 3,
buffer_colors_size,
buffer_colors_size / 3,
buffer_lines_size,
buffer_lines_size / 2,
buffer_plans_size,
buffer_plans_size / 3);
}
@ -661,8 +643,8 @@ void graphics_init_buffers(const void *gl_area)
buffer_vertex_origin = g_malloc0(buffer_vertex_size * sizeof(GLfloat) * 2);
buffer_colors_origin = g_malloc0(buffer_colors_size * sizeof(GLfloat) * 2);
buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLubyte) * 2);
buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLubyte) * 2);
buffer_lines_origin = g_malloc0(buffer_lines_size * 2 * sizeof(GLuint) * 2);
buffer_plans_origin = g_malloc0(buffer_plans_size * 3 * sizeof(GLuint) * 2);
compute_space_and_arrows (model_space_size_x,
model_space_size_y,
@ -759,10 +741,10 @@ void graphics_draw(const void *gl_area)
glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_DEPTH_TEST);
glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_BYTE, buffer_lines_origin);
glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_BYTE, buffer_plans_origin);
glDrawElements(GL_LINES, buffer_lines_size, GL_UNSIGNED_INT, buffer_lines_origin);
glDrawElements(GL_TRIANGLES, buffer_plans_size, GL_UNSIGNED_INT, buffer_plans_origin);
/* We finished using the buffers and program */
glDisableVertexAttribArray(0);
@ -774,3 +756,5 @@ void graphics_draw(const void *gl_area)
}