WIP: Enfin du code clair et qui marche. (C'était si simple ?)

This commit is contained in:
Jean Sirmai 2023-10-12 08:34:22 +02:00
parent e509dfb6b2
commit 36ecfb7041
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 26 additions and 75 deletions

View File

@ -27,8 +27,9 @@
#include <stdbool.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);
void write_space_ridges (long offset_vertex, long offset_lines, long x, long y, long z);
void write_space_faces_grids (long offset_vertex, long offset_lines, long x, long y, long z);
/*
* Writes grid lines intersections to vertex and color buffers

View File

@ -872,7 +872,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
int rand(void);
void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min);
int arbitrary = 40;
int arbitrary = 13;
int space_X = 1 + rand() % arbitrary,
space_Y = 1 + rand() % arbitrary,
space_Z = 1 + rand() % arbitrary;
@ -888,17 +888,11 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void)
show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 0, 0);
write_space_ridges (space_X, space_Y, space_Z);
write_marks_along_space_ridges (space_X, space_Y, space_Z);
long offset_vertex = 0, offset_lines = 0;
write_space_ridges (offset_vertex, offset_lines, space_X, space_Y, space_Z);
/* GRID */
/* 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 % 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 > 0) grid_write_ridges (space_X, space_Y, space_Z); */
/* grid_write_marks (space_X, space_Y, space_Z); */
offset_vertex = 8, offset_lines = 12;
write_space_faces_grids (offset_vertex, offset_lines, space_X, space_Y, space_Z);
/* ARROWS */
/* NB The 12 vertices required to draw 6 arrows in each cube

View File

@ -25,7 +25,7 @@
#include "../../include/base.h"
#include "../../include/graphics.h"
void write_space_ridges (long x, long y, long z)
void write_space_ridges (long offset_vertex, long offset_lines, long x, long y, long z)
{
float max = fmax(x, y); max = fmax(max, z);
@ -50,74 +50,33 @@ void write_space_ridges (long x, long y, long z)
graphics_write_line ( 2, 6); graphics_write_line ( 3, 6);
}
void write_marks_along_space_ridges (long x, long y, long z)
void write_space_faces_grids (long offset_vertex, long offset_lines, long x, long y, long z)
{
float i, j, k, vx, vy, vz, max = fmax(x, y);
max = fmax(max, z);
for (i = 0; i <= x; i++)
for (j = 0; j <= y; j++)
for (k = 0; k <= z; k++){
for (i = 1; i < x; i++) {
vx = (2 * i / x - 1) * x / max;
vy = (2 * j / y - 1) * y / max;
vz = (2 * k / z - 1) * z / max;
vx = (2 * i / x - 1) * x / max; vy = - y / max; vz = - z / max;
graphics_write_vertex (vx, vy, vz);
if (
(i == 0 && j == 0 && k > 0 && k < z)
|| (i == 0 && j == y && k > 0 && k < z)
|| (i == x && j == 0 && k > 0 && k < z)
|| (i == x && j == y && k > 0 && k < z)
|| (i == 0 && k == 0 && j > 0 && j < y)
|| (i == 0 && k == z && j > 0 && j < y)
|| (i == x && k == 0 && j > 0 && j < y)
|| (i == x && k == z && j > 0 && j < y)
|| (j == 0 && k == 0 && i > 0 && i < x)
|| (j == 0 && k == z && i > 0 && i < x)
|| (j == y && k == 0 && i > 0 && i < x)
|| (j == y && k == z && i > 0 && i < x)
)
graphics_write_vertex (vx, vy, vz);
};
vx = (2 * i / x - 1) * x / max; vy = - y / max; vz = + z / max;
graphics_write_vertex (vx, vy, vz);
int vertex_offset = 8;
vx = (2 * i / x - 1) * x / max; vy = + y / max; vz = + z / max;
graphics_write_vertex (vx, vy, vz);
/* graphics_write_line (vertex_offset + 0, vertex_offset + 16); */
/* graphics_write_line (vertex_offset + 1, vertex_offset + 17); */
/* graphics_write_line (vertex_offset + 2, vertex_offset + 18); */
/* graphics_write_line (vertex_offset + 3, vertex_offset + 19); */
/* graphics_write_line (vertex_offset + 4, vertex_offset + 20); */
/* graphics_write_line (vertex_offset + 5, vertex_offset + 21); */
/* graphics_write_line (vertex_offset + 6, vertex_offset + 22); */
/* graphics_write_line (vertex_offset + 7, vertex_offset + 23); */
vx = (2 * i / x - 1) * x / max; vy = + y / max; vz = - z / max;
graphics_write_vertex (vx, vy, vz);
}
for (i = 0; i < x; i ++) {
// for (int i = 0; i <= y; i += 2) graphics_write_line (vertex_offset + 2 + i, vertex_offset + 2 + i + 1);
/* graphics_write_line (vertex_offset + 2, vertex_offset + 3); */
/* graphics_write_line (vertex_offset + 4, vertex_offset + 5); */
int ar = 4;
for (int i = 0; i < y * x; i += 2) graphics_write_line (vertex_offset + ar + i, vertex_offset + ar + i + 1);
/* graphics_write_line (vertex_offset + 8, vertex_offset + 9); */
/* graphics_write_line (vertex_offset + 10, vertex_offset + 11); */
/* graphics_write_line (vertex_offset + 12, vertex_offset + 13); */
/* graphics_write_line (vertex_offset + 14, vertex_offset + 15); */
/* graphics_write_line (vertex_offset + 18, vertex_offset + 19); */
/* graphics_write_line (vertex_offset + 20, vertex_offset + 21); */
/* graphics_write_line (vertex_offset + 0, vertex_offset + 6); */
/* graphics_write_line (vertex_offset + 1, vertex_offset + 7); */
/* graphics_write_line (vertex_offset + 8, vertex_offset + 10); */
/* graphics_write_line (vertex_offset + 9, vertex_offset + 11); */
/* graphics_write_line (vertex_offset + 12, vertex_offset + 14); */
/* graphics_write_line (vertex_offset + 13, vertex_offset + 15); */
/* graphics_write_line (vertex_offset + 16, vertex_offset + 22); */
/* graphics_write_line (vertex_offset + 17, vertex_offset + 23); */
graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
graphics_write_line (offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
graphics_write_line (offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
graphics_write_line (offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
}
}
@ -136,9 +95,6 @@ void write_marks_along_space_ridges (long x, long y, long z)