WIP: nettoyage (suffisant pour l'instant) > d'abord dessiner des flèches 3D

This commit is contained in:
Jean Sirmai 2023-08-05 15:30:21 +02:00
parent c14ab5a5ee
commit 36baf07117
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 118 additions and 878 deletions

738
brouillon
View File

@ -1,738 +0,0 @@
/*
* 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 <unistd.h>
#include <stdbool.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <epoxy/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <glib-2.0/glib.h>
#include <math.h>
#include <errno.h>
#include "../../include/ui.h"
#include "../../include/graphics.h"
#include "../../include/buffers.h"
static long vertex_index = 0;
static long colors_index = 0;
static long lines_index = 0;
static long plans_index = 0;
#define S 0
#define S3 0
#define A3 0
#define L 0
#define V 0
#define C 0
#define P 0
static bool compute_space_2D(int size_x,
int size_y,
int size_z,
int pref_mark_unit_space,
int pref_style_lines_planes,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
float x = 0;
// for (int k = 0; k < size_x + 1; k++) <=> + 1
// car on passe du nombre de cases = (n)
// au nombre de séparations entre les cases + les deux bords = (n + 1)
if (S) printf("space_2D vertex ");
for (int k = 0; k < size_x; k++){ // barres verticales
//
x = ((size_x % 2) * (size_x / 2 - k)
+ (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2;
if (S) printf("[%1.1f] ", x);
*(vertex_origin + k * 6 + 0) = - x;
*(vertex_origin + k * 6 + 1) = 1.0f / size_x;
*(vertex_origin + k * 6 + 2) = 0.0f;
*(vertex_origin + k * 6 + 3) = - x;
*(vertex_origin + k * 6 + 4) = - 1.0f / size_x;
*(vertex_origin + k * 6 + 5) = 0.0f;
// fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f;
vertex_index += 6; if (V) printf(" => vertex_index = %3ld space 2D\n", vertex_index);
*(colors_origin + k * 6 + 0) = 1;
*(colors_origin + k * 6 + 1) = 0;
*(colors_origin + k * 6 + 2) = 0;
*(colors_origin + k * 6 + 3) = 1;
*(colors_origin + k * 6 + 4) = 1;
*(colors_origin + k * 6 + 5) = 0;
colors_index += 6;
*(lines_origin + k * 2 + 0) = k * 2 + 0;
*(lines_origin + k * 2 + 1) = k * 2 + 1;
lines_index += 2; if (L) printf(" => lines_index = %3ld space 2D\n", lines_index);
}
*(colors_origin + 0) = 0;
*(colors_origin + 1) = 0;
*(colors_origin + 2) = 0;
*(colors_origin + 3) = 1;
*(colors_origin + 4) = 1;
*(colors_origin + 5) = 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;
*(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_index += 12; if (C) printf(" => colors_index = %ld\n", colors_index);
*(lines_origin + lines_index + 0) = 0;
*(lines_origin + lines_index + 1) = size_x * 2 - 2; // barre horizontale du bas
*(lines_origin + lines_index + 2) = 1;
*(lines_origin + lines_index + 3) = size_x * 2 - 1; // barre horizontale du haut
lines_index += 4; if (L) printf("H=> lines_index = %3ld space 2D H\n", lines_index);
if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit
{
*(lines_origin + lines_index + 0) = 0;
*(lines_origin + lines_index + 1) = 3;
*(lines_origin + lines_index + 2) = 1;
*(lines_origin + lines_index + 3) = 2;
lines_index += 4; if (L) printf("X=> lines_index = %3ld space 2D X\n", lines_index);
}
if (pref_mark_unit_space == 2 || pref_mark_unit_space == 3) // diagonales to mark last space unit
{
*(lines_origin + lines_index + 0) = (size_x - 2) * 2 + 0;
*(lines_origin + lines_index + 1) = (size_x - 2) * 2 + 3;
*(lines_origin + lines_index + 2) = (size_x - 2) * 2 + 1;
*(lines_origin + lines_index + 3) = (size_x - 2) * 2 + 2;
lines_index +=4; if (L) printf("X=> lines_index = %3ld space 2D X\n", lines_index);
}
if (S) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x);
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) ", *(lines_origin + v), *(lines_origin + v + 1));
if (S) printf(" n = 4 + (%d x 2)\n", size_x + 2);
return 1;
}
#define A2 1
static int compute_arrow_2D(int size_x,
int size_y,
int size_z,
int weight,
int site,
int x,
int y,
int z,
int pref_style_lines_planes,
int pref_style_mix_colors,
GLfloat *vertex_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;
float center = (1.0f / size_x) * (2 * x - size_x + 2);
float tip = center + (2 * site - 1) * (1.0f / size_x - 0.01f);
float base = center + (2 * site - 1) * (0.1f / size_x);
float lat = 0.4f / size_x;
/* for (int i = 0; i < size_x; i++) */
/* for (int j = 0; j < size_y; j++) */
/* for (int k = 0; k < size_z; k++) */
/* { */
/* x = - ((size_x % 2) * (size_x / 2 - i) */
/* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* y = - ((size_x % 2) * (size_x / 2 - j) */
/* - (size_x % 2 - 1) * (j + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* z = - ((size_x % 2) * (size_x / 2 - k) */
/* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* } */
*(vertex_origin + vertex_index + 0) = tip;
*(vertex_origin + vertex_index + 1) = zero;
*(vertex_origin + vertex_index + 2) = zero;
*(vertex_origin + vertex_index + 3) = base;
*(vertex_origin + vertex_index + 4) = lat;
*(vertex_origin + vertex_index + 5) = zero;
*(vertex_origin + vertex_index + 6) = base;
*(vertex_origin + vertex_index + 7) = - lat;
*(vertex_origin + vertex_index + 8) = zero;
vertex_index += 9; if (V) printf(" => vertex_index = %3ld arrow_2D\n", vertex_index);
if (pref_style_lines_planes == 0) {
if (V) printf("0=> lines_index = %ld\n", lines_index);
*(lines_origin + lines_index + 0) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 1) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 2) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 3) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 4) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 5) = vertex_index / 3 - 1;
lines_index += 6; if (L) printf("|=> lines_index = %3ld arrow_2D\n", lines_index);
}
if (pref_style_lines_planes == 1) {
*(plans_origin + plans_index + 0) = vertex_index / 3 + 0;
*(plans_origin + plans_index + 1) = vertex_index / 3 + 1;
*(plans_origin + plans_index + 2) = vertex_index / 3 + 2;
*(plans_origin + plans_index + 3) = vertex_index / 3 + 0;
*(plans_origin + plans_index + 4) = vertex_index / 3 + 1;
*(plans_origin + plans_index + 5) = vertex_index / 3 + 2;
plans_index += 6; if (P) printf("|=> plans_index = %ld\n", plans_index);
}
return 0;
}
/* x = - ((size_x % 2) * (size_x / 2 - i) */
/* - (size_x % 2 - 1) * (i + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* y = - ((size_y % 2) * (size_y / 2 - j) */
/* - (size_y % 2 - 1) * (j + 0.5f - size_y / 2)) / size_y * 2 * EDGE; */
/* z = - ((size_z % 2) * (size_z / 2 - k) */
/* - (size_z % 2 - 1) * (k + 0.5f - size_z / 2)) / size_z * 2 * EDGE; */
static void draw_a_cube_at(long u, long v, long w,
GLuint *lines_origin,
long size_x,
long size_y,
long size_z,
bool diagonals){
long step_z = 1, step_y = size_z, step_x = size_y * size_z, x = u + 1, y = v + 1, z = w + 1;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * u; lines_index ++;
if (diagonals){
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * v + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * x; lines_index ++;
*(lines_origin + lines_index) = step_z * w + step_y * y + step_x * u; lines_index ++;
*(lines_origin + lines_index) = step_z * z + step_y * v + step_x * x; lines_index ++;
}
}
static bool compute_arrow_3D(long size_x,
long size_y,
long size_z,
int weight,
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 *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
float zero = 0.0f;
float center = (1.0f / size_x) * (2 * x - size_x + 2);
float tip = center + (2 * site - 1) * (1.0f / size_x);
float base = center + (2 * site - 1) * (0.1f / size_x);
*(vertex_origin + vertex_index + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f);
*(vertex_origin + vertex_index + 1) = zero;
*(vertex_origin + vertex_index + 2) = zero;
*(vertex_origin + vertex_index + 3) = base;
*(vertex_origin + vertex_index + 4) = 0.4f / size_x;
*(vertex_origin + vertex_index + 5) = 0.4f / size_x;
*(vertex_origin + vertex_index + 6) = base;
*(vertex_origin + vertex_index + 7) = 0.4f / size_x;
*(vertex_origin + vertex_index + 8) = - 0.4f / size_x;
*(vertex_origin + vertex_index + 9) = base;
*(vertex_origin + vertex_index + 10) = - 0.4f / size_x;
*(vertex_origin + vertex_index + 11) = - 0.4f / size_x;
*(vertex_origin + vertex_index + 12) = base;
*(vertex_origin + vertex_index + 13) = - 0.4f / size_x;
*(vertex_origin + vertex_index + 14) = 0.4f / size_x;
vertex_index += 15; if (V) printf(" => vertex_index = %3ld arrow_3D\n", vertex_index);
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) {
*(lines_origin + lines_index + 0) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 1) = vertex_index / 3 - 4;
*(lines_origin + lines_index + 2) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 3) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 4) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 5) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 6) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 7) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 8) = vertex_index / 3 - 4;
*(lines_origin + lines_index + 9) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 10) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 11) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 12) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 13) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 14) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 15) = vertex_index / 3 - 4;
lines_index += 16; if (L) printf("|=> lines_index = %3ld arrow_3D\n", lines_index);
}
if (pref_style_lines_planes == 1) {
*(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_index + 2) = size_x * 12 / 3 + 2;
*(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_index + 4) = size_x * 12 / 3 + 3;
*(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4;
*(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_index + 2) = size_x * 12 / 3 + 3;
*(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_index + 4) = size_x * 12 / 3 + 2;
*(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4;
plans_index += 12; if (P) printf("|=> plans_index = %3ld arrow_3D\n", plans_index);
}
return 1;
}
static bool draw_ridges_3D (long x, long y, long z,
long step_x, long step_y, long step_z,
GLuint *lines_origin)
{
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
*(lines_origin + lines_index) = step_z * 0 + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * 0 + step_x * (x - 1); lines_index ++;
// a diagonal test:
*(lines_origin + lines_index) = step_z * 0 + step_y * 0 + step_x * 0; lines_index ++;
*(lines_origin + lines_index) = step_z * (z - 1) + step_y * (y - 1) + step_x * (x - 1); lines_index ++;
// TO BE DEPRECATED ?
if (0) draw_a_cube_at (
1, 1, 1, lines_origin,
x + 1, y + 1, z + 1,
1); // shows the diagonals of each small cube
if (0) draw_a_cube_at (
x - 2, y - 2, z - 2, lines_origin,
x - 1, y - 1, z - 1,
1); // shows the diagonals of each small cube
return 0;
}
static bool draw_grids_3D (long x, long y, long z,
long step_x, long step_y, long step_z,
GLuint *lines_origin,
int pref_show_grid)
{
float calcul = 0;
if (! (pref_show_grid % 2))
for (int u = 0; u < y; u ++){
for (int w = 0; w < x; w ++){
calcul = step_x * w + step_y * u;
*(lines_origin + lines_index) = calcul; lines_index ++;
*(lines_origin + lines_index) = calcul + step_y - step_z; lines_index ++;
}
}
if (! (pref_show_grid % 3))
for (int u = 0; u < z; u ++){
for (int w = 0; w < x; w ++){
calcul = step_x * w + step_z * u;
*(lines_origin + lines_index) = calcul; lines_index ++;
*(lines_origin + lines_index) = calcul + step_x - step_y; lines_index ++;
}
}
if (! (pref_show_grid % 5))
for (int u = 0; u < z; u ++){
for (int w = 0; w < y; w ++){
calcul = step_y * w + step_z * u;
*(lines_origin + lines_index) = calcul; lines_index ++;
*(lines_origin + lines_index) = calcul + step_x * (x - 1); lines_index ++;
}
}
return 0;
}
static bool grids_intersections (long x, long y, long z,
int pref_style_mix_colors,
GLfloat *vertex_origin,
GLfloat *colors_origin)
{
float i, j, k, vx, vy, vz, max = fmax(x, y); max = fmax(max, z) + 1;
if (P) printf("max(%ld,%ld,%ld) = %f; size_x / max = %6.3f; size_y / max = %6.3f; size_z / max = %6.3f\n",\
x, y, z, max, x / max, y / max, z / max);
for (i = 0; i < x; i++){
for (j = 0; j < y; j++){
for (k = 0; k < z; k++){
//printf("vertex_origin = %ld\n", vertex_origin);
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_origin + vertex_index + 0) = vx;
*(vertex_origin + vertex_index + 1) = vy;
*(vertex_origin + vertex_index + 2) = vz;
vertex_index += 3; // if (V) printf(" => vertex_index = %3d\n", vertex_index);
*(colors_origin + colors_index + 0) = 3 * vx / 2;
*(colors_origin + colors_index + 1) = 3 * vy / 2;
*(colors_origin + colors_index + 2) = 3 * vz / 2;
colors_index += 3; // if (C) printf(" => colors_index = %3d\n", colors_index);23.
if (P) printf("(%1.0f*%1.0f*%1.0f)<>[%6.3f %6.3f %6.3f] ", i, j, k, vx, vy, vz);
}
if (P) printf(" ");
}
if (P) printf("\n");
};
return 1;
}
static void show_user_choices(long width_X,
long height_Y,
long depth_Z,
GLuint *arrows,
int model_arrows_nb,
int pref_mark_unit_space,
int pref_style_lines_planes,
int pref_style_mix_colors,
int pref_show_grid)
{
printf("model + user constraints : space size x,y,z = %ld,%ld,%ld ", width_X, height_Y, depth_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 ");
if (pref_mark_unit_space == 2) printf("last unit_space marked ");
if (pref_mark_unit_space == 3) printf("first and last units space marked ");
if (! pref_style_lines_planes) printf("no style_lines_planes ");
if (pref_style_lines_planes > 0) printf("style_lines_planes = %d ", pref_style_lines_planes);
if (! pref_style_mix_colors) printf("no style_mix_colors ");
if (pref_style_mix_colors > 0) printf("style_mix_colors = %d ", pref_style_mix_colors);
if (pref_show_grid == 1) printf("pref_show_grid = %d <> show no grid ", pref_show_grid);
if (pref_show_grid == 0) printf("pref_show_grid = %d <> show all grids ", pref_show_grid);
if (pref_show_grid == 2) printf("pref_show_grid = %d <> show grid xy ", pref_show_grid);
if (pref_show_grid == 3) printf("pref_show_grid = %d <> show grid xz ", pref_show_grid);
if (pref_show_grid == 5) printf("pref_show_grid = %d <> show grid yz ", pref_show_grid);
if (pref_show_grid == 6) printf("pref_show_grid = %d <> show grids xy & xz ", pref_show_grid);
if (pref_show_grid == 10) printf("pref_show_grid = %d <> show grids xy & yz ", pref_show_grid);
if (pref_show_grid == 15) printf("pref_show_grid = %d <> show grids xz & yz ", pref_show_grid);
if (model_arrows_nb == 0) printf("\n");
if (model_arrows_nb > 0) printf("[n] load site x y z ---- < arrows array >\
------------------------------------------------------------\n");
// DEPRECATED arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 }
if (model_arrows_nb > 0) for (int i = 0; i < model_arrows_nb; i++)
printf("[%2d] = %2d, %2d, %2d, %2d, %2d \n",\
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
}
bool compute_space_and_arrows(long width_X, long height_Y, long depth_Z,
GLuint *arrows, int model_arrows_nb,
int pref_mark_unit_space,
int pref_style_lines_planes,
int pref_style_mix_colors,
int pref_show_grid,
GLfloat *vertex_origin,
GLfloat *colors_origin,
GLuint *lines_origin,
GLuint *plans_origin)
{
show_user_choices(width_X, height_Y, depth_Z, arrows, model_arrows_nb,
pref_mark_unit_space, pref_style_lines_planes,
pref_style_mix_colors, pref_show_grid);
grids_intersections(width_X, height_Y, depth_Z,
pref_style_mix_colors,
vertex_origin, colors_origin);
long step_z = 1, step_y = depth_Z, step_x = height_Y * depth_Z;
draw_grids_3D (width_X, height_Y, depth_Z, step_x, step_y, step_z, lines_origin, pref_show_grid);
draw_ridges_3D (width_X, height_Y, depth_Z, step_x, step_y, step_z, lines_origin);
for (int i = 0; i < model_arrows_nb; i++)
compute_arrow_3D ( long step_z = 1, step_y = depth_Z, step_x = height_Y * depth_Z;
draw_grids_3D (width_X, height_Y, depth_Z, step_x, step_y, step_z, lines_origin, pref_show_grid);
draw_ridges_3D (width_X, height_Y, depth_Z, step_x, step_y, step_z, lines_origin);
*(arrows + i * 5 + 0), // weight (load)
*(arrows + i * 5 + 1), // site
*(arrows + i * 5 + 2), // x
*(arrows + i * 5 + 3), // y
*(arrows + i * 5 + 4), // z
pref_style_lines_planes,
pref_style_mix_colors,
vertex_origin,
colors_origin,
lines_origin,
plans_origin);
return 0;
}

View File

@ -41,20 +41,13 @@
#include "../../include/graphics.h" #include "../../include/graphics.h"
#include "../../include/buffers.h" #include "../../include/buffers.h"
static long vertex_buffer_size = 0; static long vertex_index = 0;
static long colors_buffer_size = 0; static long colors_index = 0;
static long lines_index = 0; static long lines_index = 0;
static long plans_buffer_size = 0; static long plans_index = 0;
#define S 0
#define S3 0
#define A3 0
#define L 0
#define V 0 #define V 0
#define C 0
#define P 0
static bool compute_space_2D(int size_x, static bool compute_space_2D(int size_x,
int size_y, int size_y,
@ -75,13 +68,13 @@ static bool compute_space_2D(int size_x,
// car on passe du nombre de cases = (n) // car on passe du nombre de cases = (n)
// au nombre de séparations entre les cases + les deux bords = (n + 1) // au nombre de séparations entre les cases + les deux bords = (n + 1)
if (S) printf("space_2D vertex "); if (V) printf("space_2D vertex ");
for (int k = 0; k < size_x; k++){ // barres verticales for (int k = 0; k < size_x; k++){ // barres verticales
// //
x = ((size_x % 2) * (size_x / 2 - k) x = ((size_x % 2) * (size_x / 2 - k)
+ (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2; + (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2;
if (S) printf("[%1.1f] ", x); if (V) printf("[%1.1f] ", x);
*(vertex_origin + k * 6 + 0) = - x; *(vertex_origin + k * 6 + 0) = - x;
*(vertex_origin + k * 6 + 1) = 1.0f / size_x; *(vertex_origin + k * 6 + 1) = 1.0f / size_x;
@ -93,7 +86,7 @@ static bool compute_space_2D(int size_x,
// fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f; // fun > if (k == size_x - 1) *(vertex_origin + k * 6 + 5) = 0.1f;
vertex_buffer_size += 6; if (V) printf(" => vertex_buffer_size = %3ld space 2D\n", vertex_buffer_size); vertex_index += 6; if (V) printf(" => vertex_index = %3ld space 2D\n", vertex_index);
*(colors_origin + k * 6 + 0) = 1; *(colors_origin + k * 6 + 0) = 1;
*(colors_origin + k * 6 + 1) = 0; *(colors_origin + k * 6 + 1) = 0;
@ -103,12 +96,12 @@ static bool compute_space_2D(int size_x,
*(colors_origin + k * 6 + 4) = 1; *(colors_origin + k * 6 + 4) = 1;
*(colors_origin + k * 6 + 5) = 0; *(colors_origin + k * 6 + 5) = 0;
colors_buffer_size += 6; colors_index += 6;
*(lines_origin + k * 2 + 0) = k * 2 + 0; *(lines_origin + k * 2 + 0) = k * 2 + 0;
*(lines_origin + k * 2 + 1) = k * 2 + 1; *(lines_origin + k * 2 + 1) = k * 2 + 1;
lines_index += 2; if (L) printf(" => lines_index = %3ld space 2D\n", lines_index); lines_index += 2; if (V) printf(" => lines_index = %3ld space 2D\n", lines_index);
} }
*(colors_origin + 0) = 0; *(colors_origin + 0) = 0;
@ -127,7 +120,7 @@ static bool compute_space_2D(int size_x,
*(colors_origin + (size_x - 1) * 6 + 4) = 0; *(colors_origin + (size_x - 1) * 6 + 4) = 0;
*(colors_origin + (size_x - 1) * 6 + 5) = 0; *(colors_origin + (size_x - 1) * 6 + 5) = 0;
colors_buffer_size += 12; if (C) printf(" => colors_buffer_size = %ld\n", colors_buffer_size); colors_index += 12; if (V) printf(" => colors_index = %ld\n", colors_index);
*(lines_origin + lines_index + 0) = 0; *(lines_origin + lines_index + 0) = 0;
*(lines_origin + lines_index + 1) = size_x * 2 - 2; // barre horizontale du bas *(lines_origin + lines_index + 1) = size_x * 2 - 2; // barre horizontale du bas
@ -135,7 +128,7 @@ static bool compute_space_2D(int size_x,
*(lines_origin + lines_index + 2) = 1; *(lines_origin + lines_index + 2) = 1;
*(lines_origin + lines_index + 3) = size_x * 2 - 1; // barre horizontale du haut *(lines_origin + lines_index + 3) = size_x * 2 - 1; // barre horizontale du haut
lines_index += 4; if (L) printf("H=> lines_index = %3ld space 2D H\n", lines_index); lines_index += 4; if (V) printf("H=> lines_index = %3ld space 2D H\n", lines_index);
if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit if (pref_mark_unit_space == 1 || pref_mark_unit_space == 3) // diagonales to mark first space unit
{ {
@ -145,7 +138,7 @@ static bool compute_space_2D(int size_x,
*(lines_origin + lines_index + 2) = 1; *(lines_origin + lines_index + 2) = 1;
*(lines_origin + lines_index + 3) = 2; *(lines_origin + lines_index + 3) = 2;
lines_index += 4; if (L) printf("X=> lines_index = %3ld space 2D X\n", lines_index); lines_index += 4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index);
} }
@ -157,20 +150,19 @@ static bool compute_space_2D(int size_x,
*(lines_origin + lines_index + 2) = (size_x - 2) * 2 + 1; *(lines_origin + lines_index + 2) = (size_x - 2) * 2 + 1;
*(lines_origin + lines_index + 3) = (size_x - 2) * 2 + 2; *(lines_origin + lines_index + 3) = (size_x - 2) * 2 + 2;
lines_index +=4; if (L) printf("X=> lines_index = %3ld space 2D X\n", lines_index); lines_index +=4; if (V) printf("X=> lines_index = %3ld space 2D X\n", lines_index);
} }
if (S) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x); if (V) printf(" n = %d x 2 côté = [%1.1f]\n", size_x + 1, 2.0f / size_x);
if (S) printf("space_2D lines_origin (%d - size_x(0)) x (%d - size_x(1)) ", 0, 1); if (V) 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++) for (int v = 0; v < size_x + 2; v++)
if (S) printf("(%d-%d) ", *(lines_origin + v), *(lines_origin + v + 1)); if (V) printf("(%d-%d) ", *(lines_origin + v), *(lines_origin + v + 1));
if (S) printf(" n = 4 + (%d x 2)\n", size_x + 2); if (V) printf(" n = 4 + (%d x 2)\n", size_x + 2);
return 1; return 1;
} }
#define A2 1
static int compute_arrow_2D(int size_x, static int compute_arrow_2D(int size_x,
int size_y, int size_y,
int size_z, int size_z,
@ -209,47 +201,47 @@ static int compute_arrow_2D(int size_x,
/* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */ /* - (size_x % 2 - 1) * (k + 0.5f - size_x / 2)) / size_x * 2 * EDGE; */
/* } */ /* } */
*(vertex_origin + vertex_buffer_size + 0) = tip; *(vertex_origin + vertex_index + 0) = tip;
*(vertex_origin + vertex_buffer_size + 1) = zero; *(vertex_origin + vertex_index + 1) = zero;
*(vertex_origin + vertex_buffer_size + 2) = zero; *(vertex_origin + vertex_index + 2) = zero;
*(vertex_origin + vertex_buffer_size + 3) = base; *(vertex_origin + vertex_index + 3) = base;
*(vertex_origin + vertex_buffer_size + 4) = lat; *(vertex_origin + vertex_index + 4) = lat;
*(vertex_origin + vertex_buffer_size + 5) = zero; *(vertex_origin + vertex_index + 5) = zero;
*(vertex_origin + vertex_buffer_size + 6) = base; *(vertex_origin + vertex_index + 6) = base;
*(vertex_origin + vertex_buffer_size + 7) = - lat; *(vertex_origin + vertex_index + 7) = - lat;
*(vertex_origin + vertex_buffer_size + 8) = zero; *(vertex_origin + vertex_index + 8) = zero;
vertex_buffer_size += 9; if (V) printf(" => vertex_buffer_size = %3ld arrow_2D\n", vertex_buffer_size); vertex_index += 9; if (V) printf(" => vertex_index = %3ld arrow_2D\n", vertex_index);
if (pref_style_lines_planes == 0) { if (pref_style_lines_planes == 0) {
if (V) printf("0=> lines_index = %ld\n", lines_index); if (V) printf("0=> lines_index = %ld\n", lines_index);
*(lines_origin + lines_index + 0) = vertex_buffer_size / 3 - 3; *(lines_origin + lines_index + 0) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 1) = vertex_buffer_size / 3 - 2; *(lines_origin + lines_index + 1) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 2) = vertex_buffer_size / 3 - 3; *(lines_origin + lines_index + 2) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 3) = vertex_buffer_size / 3 - 1; *(lines_origin + lines_index + 3) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 4) = vertex_buffer_size / 3 - 2; *(lines_origin + lines_index + 4) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 5) = vertex_buffer_size / 3 - 1; *(lines_origin + lines_index + 5) = vertex_index / 3 - 1;
lines_index += 6; if (L) printf("|=> lines_index = %3ld arrow_2D\n", lines_index); lines_index += 6; if (V) printf("|=> lines_index = %3ld arrow_2D\n", lines_index);
} }
if (pref_style_lines_planes == 1) { if (pref_style_lines_planes == 1) {
*(plans_origin + plans_buffer_size + 0) = vertex_buffer_size / 3 + 0; *(plans_origin + plans_index + 0) = vertex_index / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = vertex_buffer_size / 3 + 1; *(plans_origin + plans_index + 1) = vertex_index / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = vertex_buffer_size / 3 + 2; *(plans_origin + plans_index + 2) = vertex_index / 3 + 2;
*(plans_origin + plans_buffer_size + 3) = vertex_buffer_size / 3 + 0; *(plans_origin + plans_index + 3) = vertex_index / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = vertex_buffer_size / 3 + 1; *(plans_origin + plans_index + 4) = vertex_index / 3 + 1;
*(plans_origin + plans_buffer_size + 5) = vertex_buffer_size / 3 + 2; *(plans_origin + plans_index + 5) = vertex_index / 3 + 2;
plans_buffer_size += 6; if (P) printf("|=> plans_buffer_size = %ld\n", plans_buffer_size); plans_index += 6; if (V) printf("|=> plans_index = %ld\n", plans_index);
} }
return 0; return 0;
} }
@ -285,79 +277,79 @@ static bool compute_arrow_3D(long size_x,
float tip = center + (2 * site - 1) * (1.0f / size_x); float tip = center + (2 * site - 1) * (1.0f / size_x);
float base = center + (2 * site - 1) * (0.1f / size_x); float base = center + (2 * site - 1) * (0.1f / size_x);
*(vertex_origin + vertex_buffer_size + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f); *(vertex_origin + vertex_index + 0) = center + (2 * site - 1) * (1.0f / size_x - 0.01f);
*(vertex_origin + vertex_buffer_size + 1) = zero; *(vertex_origin + vertex_index + 1) = zero;
*(vertex_origin + vertex_buffer_size + 2) = zero; *(vertex_origin + vertex_index + 2) = zero;
*(vertex_origin + vertex_buffer_size + 3) = base; *(vertex_origin + vertex_index + 3) = base;
*(vertex_origin + vertex_buffer_size + 4) = 0.4f / size_x; *(vertex_origin + vertex_index + 4) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 5) = 0.4f / size_x; *(vertex_origin + vertex_index + 5) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 6) = base; *(vertex_origin + vertex_index + 6) = base;
*(vertex_origin + vertex_buffer_size + 7) = 0.4f / size_x; *(vertex_origin + vertex_index + 7) = 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 8) = - 0.4f / size_x; *(vertex_origin + vertex_index + 8) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 9) = base; *(vertex_origin + vertex_index + 9) = base;
*(vertex_origin + vertex_buffer_size + 10) = - 0.4f / size_x; *(vertex_origin + vertex_index + 10) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 11) = - 0.4f / size_x; *(vertex_origin + vertex_index + 11) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 12) = base; *(vertex_origin + vertex_index + 12) = base;
*(vertex_origin + vertex_buffer_size + 13) = - 0.4f / size_x; *(vertex_origin + vertex_index + 13) = - 0.4f / size_x;
*(vertex_origin + vertex_buffer_size + 14) = 0.4f / size_x; *(vertex_origin + vertex_index + 14) = 0.4f / size_x;
vertex_buffer_size += 15; if (V) printf(" => vertex_buffer_size = %3ld arrow_3D\n", vertex_buffer_size); vertex_index += 15; if (V) printf(" => vertex_index = %3ld arrow_3D\n", vertex_index);
if (A3) printf("center = %f tip = %f base = %f\n",\ if (V) printf("center = %f tip = %f base = %f\n",\
center, tip, base); // size_x * 12=%d igap=%d center, tip, base); // size_x * 12=%d igap=%d
if (pref_style_lines_planes == 0) { if (pref_style_lines_planes == 0) {
*(lines_origin + lines_index + 0) = vertex_buffer_size / 3 - 5; *(lines_origin + lines_index + 0) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 1) = vertex_buffer_size / 3 - 4; *(lines_origin + lines_index + 1) = vertex_index / 3 - 4;
*(lines_origin + lines_index + 2) = vertex_buffer_size / 3 - 5; *(lines_origin + lines_index + 2) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 3) = vertex_buffer_size / 3 - 3; *(lines_origin + lines_index + 3) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 4) = vertex_buffer_size / 3 - 5; *(lines_origin + lines_index + 4) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 5) = vertex_buffer_size / 3 - 2; *(lines_origin + lines_index + 5) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 6) = vertex_buffer_size / 3 - 5; *(lines_origin + lines_index + 6) = vertex_index / 3 - 5;
*(lines_origin + lines_index + 7) = vertex_buffer_size / 3 - 1; *(lines_origin + lines_index + 7) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 8) = vertex_buffer_size / 3 - 4; *(lines_origin + lines_index + 8) = vertex_index / 3 - 4;
*(lines_origin + lines_index + 9) = vertex_buffer_size / 3 - 3; *(lines_origin + lines_index + 9) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 10) = vertex_buffer_size / 3 - 3; *(lines_origin + lines_index + 10) = vertex_index / 3 - 3;
*(lines_origin + lines_index + 11) = vertex_buffer_size / 3 - 2; *(lines_origin + lines_index + 11) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 12) = vertex_buffer_size / 3 - 2; *(lines_origin + lines_index + 12) = vertex_index / 3 - 2;
*(lines_origin + lines_index + 13) = vertex_buffer_size / 3 - 1; *(lines_origin + lines_index + 13) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 14) = vertex_buffer_size / 3 - 1; *(lines_origin + lines_index + 14) = vertex_index / 3 - 1;
*(lines_origin + lines_index + 15) = vertex_buffer_size / 3 - 4; *(lines_origin + lines_index + 15) = vertex_index / 3 - 4;
lines_index += 16; if (L) printf("|=> lines_index = %3ld arrow_3D\n", lines_index); lines_index += 16; if (V) printf("|=> lines_index = %3ld arrow_3D\n", lines_index);
} }
if (pref_style_lines_planes == 1) { if (pref_style_lines_planes == 1) {
*(plans_origin + plans_buffer_size + 0) = size_x * 12 / 3 + 0; *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = size_x * 12 / 3 + 1; *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = size_x * 12 / 3 + 2; *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 2;
*(plans_origin + plans_buffer_size + 3) = size_x * 12 / 3 + 0; *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = size_x * 12 / 3 + 3; *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 3;
*(plans_origin + plans_buffer_size + 5) = size_x * 12 / 3 + 4; *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4;
*(plans_origin + plans_buffer_size + 0) = size_x * 12 / 3 + 0; *(plans_origin + plans_index + 0) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 1) = size_x * 12 / 3 + 1; *(plans_origin + plans_index + 1) = size_x * 12 / 3 + 1;
*(plans_origin + plans_buffer_size + 2) = size_x * 12 / 3 + 3; *(plans_origin + plans_index + 2) = size_x * 12 / 3 + 3;
*(plans_origin + plans_buffer_size + 3) = size_x * 12 / 3 + 0; *(plans_origin + plans_index + 3) = size_x * 12 / 3 + 0;
*(plans_origin + plans_buffer_size + 4) = size_x * 12 / 3 + 2; *(plans_origin + plans_index + 4) = size_x * 12 / 3 + 2;
*(plans_origin + plans_buffer_size + 5) = size_x * 12 / 3 + 4; *(plans_origin + plans_index + 5) = size_x * 12 / 3 + 4;
plans_buffer_size += 12; if (P) printf("|=> plans_buffer_size = %3ld arrow_3D\n", plans_buffer_size); plans_index += 12; if (V) printf("|=> plans_index = %3ld arrow_3D\n", plans_index);
} }
return 1; return 1;
@ -504,41 +496,28 @@ static bool grids_intersections (long x, long y, long z,
GLfloat *colors_origin) GLfloat *colors_origin)
{ {
// long vertex_index = vertex_buffer_size; float i, j, k, vx, vy, vz, max = fmax(x, y);
// long colors_index = colors_buffer_size; // à virer, bien sûr ! max = fmax(max, z) + 1;
float i, j, k, vx, vy, vz, max = fmax(x, y); max = fmax(max, z) + 1; for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
if (P) printf("max(%ld,%ld,%ld) = %f; size_x / max = %6.3f; size_y / max = %6.3f; size_z / max = %6.3f\n",\
x, y, z, max, x / max, y / max, z / max);
for (i = 0; i < x; i++){
for (j = 0; j < y; j++){
for (k = 0; k < z; k++){ for (k = 0; k < z; k++){
//printf("vertex_origin = %ld\n", vertex_origin);
vx = (2 * i / (x - 1) - 1) * x / max; vx = (2 * i / (x - 1) - 1) * x / max;
vy = (2 * j / (y - 1) - 1) * y / max; vy = (2 * j / (y - 1) - 1) * y / max;
vz = (2 * k / (z - 1) - 1) * z / max; vz = (2 * k / (z - 1) - 1) * z / max;
*(vertex_origin + vertex_buffer_size + 0) = vx; *(vertex_origin + vertex_index + 0) = vx;
*(vertex_origin + vertex_buffer_size + 1) = vy; *(vertex_origin + vertex_index + 1) = vy;
*(vertex_origin + vertex_buffer_size + 2) = vz; *(vertex_origin + vertex_index + 2) = vz;
vertex_buffer_size += 3; // if (V) printf(" => vertex_buffer_size = %3d\n", vertex_buffer_size); vertex_index += 3;
*(colors_origin + colors_buffer_size + 0) = 3 * vx / 2; *(colors_origin + colors_index + 0) = 3 * vx / 2;
*(colors_origin + colors_buffer_size + 1) = 3 * vy / 2; *(colors_origin + colors_index + 1) = 3 * vy / 2;
*(colors_origin + colors_buffer_size + 2) = 3 * vz / 2; *(colors_origin + colors_index + 2) = 3 * vz / 2;
colors_buffer_size += 3; // if (C) printf(" => colors_buffer_size = %3d\n", colors_buffer_size);23. colors_index += 3;
if (P) printf("(%1.0f*%1.0f*%1.0f)<>[%6.3f %6.3f %6.3f] ", i, j, k, vx, vy, vz);
}
if (P) printf(" ");
}
if (P) printf("\n");
}; };
return 1; return 1;
@ -562,7 +541,7 @@ static bool draw_grids_3D (long x, long y, long z,
{ {
float calcul = 0; float calcul = 0;
if (! (pref_show_grid % 2)) if (pref_show_grid % 2 == 0)
for (int u = 0; u < y; u ++){ for (int u = 0; u < y; u ++){
for (int w = 0; w < x; w ++){ for (int w = 0; w < x; w ++){
calcul = step_x * w + step_y * u; calcul = step_x * w + step_y * u;
@ -571,7 +550,7 @@ static bool draw_grids_3D (long x, long y, long z,
} }
} }
if (! (pref_show_grid % 3)) if (pref_show_grid % 3 == 0)
for (int u = 0; u < z; u ++){ for (int u = 0; u < z; u ++){
for (int w = 0; w < x; w ++){ for (int w = 0; w < x; w ++){
calcul = step_x * w + step_z * u; calcul = step_x * w + step_z * u;
@ -580,7 +559,7 @@ static bool draw_grids_3D (long x, long y, long z,
} }
} }
if (! (pref_show_grid % 5)) if (pref_show_grid % 5 == 0)
for (int u = 0; u < z; u ++){ for (int u = 0; u < z; u ++){
for (int w = 0; w < y; w ++){ for (int w = 0; w < y; w ++){
calcul = step_y * w + step_z * u; calcul = step_y * w + step_z * u;
@ -688,10 +667,10 @@ static void show_user_choices(long model_size_x,
if (pref_show_grid == 6) printf("pref_show_grid = %d <> show grids xy & xz ", pref_show_grid); if (pref_show_grid == 6) printf("pref_show_grid = %d <> show grids xy & xz ", pref_show_grid);
if (pref_show_grid == 10) printf("pref_show_grid = %d <> show grids xy & yz ", pref_show_grid); if (pref_show_grid == 10) printf("pref_show_grid = %d <> show grids xy & yz ", pref_show_grid);
if (pref_show_grid == 15) printf("pref_show_grid = %d <> show grids xz & yz ", pref_show_grid); if (pref_show_grid == 15) printf("pref_show_grid = %d <> show grids xz & yz ", pref_show_grid);
if (model_arrows_nb == 0) printf("\n"); if (1) printf("\n");
if (model_arrows_nb > 0) printf("[n] load site x y z ---- < arrows array >\ if (model_arrows_nb > 0) printf("[ n] load site x y z ---- < arrows array >\
------------------------------------------------------------\n"); ------------------------------------------------------------\n");
// arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 } // (DEPRECATED) arrows = { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 }
for (int i = 0; i < model_arrows_nb; i++) for (int i = 0; i < model_arrows_nb; i++)
printf("[%2d] = %2d, %2d, %2d, %2d, %2d \n",\ printf("[%2d] = %2d, %2d, %2d, %2d, %2d \n",\
i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4)); i, *(arrows + i * 5 + 0), *(arrows + i * 5 + 1), *(arrows + i * 5 + 2), *(arrows + i * 5 + 3), *(arrows + i * 5 + 4));
@ -719,18 +698,17 @@ bool compute_space_and_arrows(long model_size_x, long model_size_y, long model_s
step_y = model_size_z + 1, step_y = model_size_z + 1,
step_x = (model_size_z + 1) * (model_size_y + 1); step_x = (model_size_z + 1) * (model_size_y + 1);
grids_intersections (model_size_x + 1, model_size_y + 1, model_size_z + 1, pref_style_mix_colors, vertex_origin, colors_origin);
// long step_z = 1, step_y = depth_Z, step_x = height_Y * depth_Z; draw_grids_3D (model_size_x + 1, model_size_y + 1, model_size_z + 1, step_x, step_y, step_z, lines_origin, pref_show_grid);
grids_intersections (model_size_x + 1, model_size_y + 1, model_size_z + 1, pref_style_mix_colors,vertex_origin,colors_origin); if (pref_show_grid != 0) draw_ridges_3D (model_size_x + 1, model_size_y + 1, model_size_z + 1, step_x, step_y, step_z, lines_origin);
if (! pref_show_grid) draw_grids_3D (model_size_x + 1, model_size_y + 1, model_size_z + 1, step_x, step_y, step_z, lines_origin, pref_show_grid);
else draw_ridges_3D (model_size_x + 1, model_size_y + 1, model_size_z + 1, step_x, step_y, step_z, lines_origin);
if (pref_test_diagonal) diagonal_test (model_size_x + 1, model_size_y + 1, model_size_z + 1, lines_origin); if (pref_test_diagonal) diagonal_test (model_size_x + 1, model_size_y + 1, model_size_z + 1, lines_origin);
return 0;
}
// OLD ARROWS (DEPRECATED) // OLD ARROWS (DEPRECATED)
/* old_arrows (model_arrows_nb, model_size_x, model_size_y, model_size_z, arrows, */ /* old_arrows (model_arrows_nb, model_size_x, model_size_y, model_size_z, arrows, */
/* pref_style_lines_planes, pref_style_mix_colors, */ /* pref_style_lines_planes, pref_style_mix_colors, */
/* vertex_origin, colors_origin, lines_origin, plans_origin); */ /* vertex_origin, colors_origin, lines_origin, plans_origin); */
return 0;
}

View File

@ -565,9 +565,9 @@ GLuint arrows[] = {
static void get_model_data_and_user_preferences(){ static void get_model_data_and_user_preferences(){
model_space_size_x = 2; // 0 < model_space_size_x model_space_size_x = 4; // 0 < model_space_size_x
model_space_size_y = 3; // 0 < model_space_size_y model_space_size_y = 3; // 0 < model_space_size_y
model_space_size_z = 4; // 0 < model_space_size_z model_space_size_z = 2; // 0 < model_space_size_z
// XXX ONLY space drawed, no arrows // XXX ONLY space drawed, no arrows
model_arrows_nb = 1; // assert : l'emplacement des flèches est contraint model_arrows_nb = 1; // assert : l'emplacement des flèches est contraint
@ -579,7 +579,7 @@ static void get_model_data_and_user_preferences(){
pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both pref_mark_unit_space = 0; // 0 = no marks, 1 = 1st, 2 = last, 3 = both
pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix pref_style_lines_planes = 0; // 0 = arrows as lines, 1 = as planes, 2 = mix
pref_style_mix_colors = 0; // TODO pref_style_mix_colors = 0; // TODO
pref_show_grid = 1; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc pref_show_grid = 0; // 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
pref_test_diagonal = 1; pref_test_diagonal = 1;
} }
@ -616,9 +616,9 @@ static void compute_buffers_sizes(int model_space_size_x,
buffer_plans_size = 0; buffer_plans_size = 0;
long grids_lines = long grids_lines =
(! (pref_show_grid % 2)) * (model_space_size_x + 1) * (model_space_size_y + 1) (pref_show_grid % 2 == 0) * (model_space_size_x + 1) * (model_space_size_y + 1)
+ (! (pref_show_grid % 3)) * (model_space_size_x + 1) * (model_space_size_z + 1) + (pref_show_grid % 3 == 0) * (model_space_size_x + 1) * (model_space_size_z + 1)
+ (! (pref_show_grid % 5)) * (model_space_size_y + 1) * (model_space_size_z + 1); + (pref_show_grid % 5 == 0) * (model_space_size_y + 1) * (model_space_size_z + 1);
buffer_lines_size = grids_lines * 2; buffer_lines_size = grids_lines * 2;
// if (model_arrows_nb > 0) buffer_lines_size += model_arrows_nb * 16 // DEPRECATED // if (model_arrows_nb > 0) buffer_lines_size += model_arrows_nb * 16 // DEPRECATED