From 24ffed722387d6db88f78b528b4fa3f336f1fe99 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 12 Oct 2023 09:48:15 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20encore=20quelques=20petits=20r=C3=A9glag?= =?UTF-8?q?es...=20=C3=A7a=20y=20est=20presque.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/grid.h | 4 ++-- src/graphics/graphics.c | 8 ++++---- src/graphics/grid.c | 45 +++++++++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/include/grid.h b/include/grid.h index 843d2b5..05b982c 100644 --- a/include/grid.h +++ b/include/grid.h @@ -27,9 +27,9 @@ #include #include -void write_space_ridges (long offset_vertex, long offset_lines, long x, long y, long z); +void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z); -void write_space_faces_grids (long offset_vertex, long offset_lines, long x, long y, long z); +void write_space_faces_grids (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style); /* * Writes grid lines intersections to vertex and color buffers diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 3a85e53..1064e4b 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -888,11 +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); - long offset_vertex = 0, offset_lines = 0; - write_space_ridges (offset_vertex, offset_lines, space_X, space_Y, space_Z); + long offset_vertex = 0, offset_colors = 0, offset_lines = 0; + write_space_ridges (offset_vertex, offset_colors, offset_lines, 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); + offset_vertex = 8, offset_colors = 8, offset_lines = 12; + write_space_faces_grids (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, 1); /* ARROWS */ /* NB The 12 vertices required to draw 6 arrows in each cube diff --git a/src/graphics/grid.c b/src/graphics/grid.c index 83a67dc..f07fe68 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -25,7 +25,7 @@ #include "../../include/base.h" #include "../../include/graphics.h" -void write_space_ridges (long offset_vertex, long offset_lines, long x, long y, long z) +void write_space_ridges (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z) { float max = fmax(x, y); max = fmax(max, z); @@ -50,27 +50,33 @@ void write_space_ridges (long offset_vertex, long offset_lines, long x, long y, graphics_write_line ( 2, 6); graphics_write_line ( 3, 6); } -void write_space_faces_grids (long offset_vertex, long offset_lines, long x, long y, long z) +void write_space_faces_grids (long offset_vertex, long offset_colors, long offset_lines, long x, long y, long z, int style) { float i, max = fmax(x, y); max = fmax(max, z); - for (i = 1; i < x; i++) { + if (style) for (i = 1; i < x; i++) { graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, - z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, - y / max, z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, z / max); graphics_write_vertex ((2 * i / x - 1) * x / max, y / max, - z / max); + + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); } - /* for (i = 0; i < x; i ++) { */ + if (style) for (i = 0; i < x; i ++) { - /* 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); */ - /* } */ + 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); + } - offset_vertex += (x - 1) * 4; + if (style) offset_vertex += (x - 1) * 4; + if (style) offset_colors += (x - 1) * 4; for (i = 1; i < y; i++) { @@ -78,17 +84,24 @@ void write_space_faces_grids (long offset_vertex, long offset_lines, long x, lon graphics_write_vertex (- x / max, (2 * i / y - 1) * y / max, z / max); graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, z / max); graphics_write_vertex ( x / max, (2 * i / y - 1) * y / max, - z / max); + + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); } for (i = 0; i < y - 1; i ++) { - /* graphics_write_line (offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); */ + if (style) + 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); } - offset_vertex += (y - 1) * 4; + offset_vertex += (y - 2) * 4; + offset_colors += (y - 2) * 4; for (i = 1; i < z; i++) { @@ -96,13 +109,19 @@ void write_space_faces_grids (long offset_vertex, long offset_lines, long x, lon graphics_write_vertex (- x / max, y / max, (2 * i / z - 1) * z / max); graphics_write_vertex ( x / max, y / max, (2 * i / z - 1) * z / max); graphics_write_vertex ( x / max, - y / max, (2 * i / z - 1) * z / max); + + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); + graphics_write_color (0.5f, 0.5f, 0.5f); } for (i = 0; i <= z; i ++) { 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); */ + if (style) + 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); } }