gem-graph-client/src/grid.c

163 lines
6.4 KiB
C
Raw Normal View History

/*
* Gem-graph
*
* Desc: OpenGL grid functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <time.h>
2024-06-29 17:15:01 +02:00
#include "../include/base.h"
//#include "../include/ui.h"
#include "../include/graphics.h"
int draw_space_ridges_vertex (const int stack_id,
long offset_vertex,
long x,
long y,
long z)
{
GLfloat max = fmax(x, y); max = fmax(max, z);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex + y / max, - z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, + z / max);
graphics_draw_vertex (stack_id, offset_vertex + x / max, + y / max, + z / max);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f);
return 8;
}
int draw_space_ridges_lines (const int stack_id)
{
graphics_draw_line (stack_id, 0, 1); graphics_draw_line (stack_id, 7, 4);
graphics_draw_line (stack_id, 0, 2); graphics_draw_line (stack_id, 7, 5);
graphics_draw_line (stack_id, 0, 3); graphics_draw_line (stack_id, 7, 6);
graphics_draw_line (stack_id, 1, 4); graphics_draw_line (stack_id, 2, 4);
graphics_draw_line (stack_id, 1, 5); graphics_draw_line (stack_id, 3, 5);
graphics_draw_line (stack_id, 2, 6); graphics_draw_line (stack_id, 3, 6);
return 12;
}
long draw_grids_on_space_faces_vertex (const int stack_id,
long x,
long y,
long z)
{
float i, max = fmax(x, y); max = fmax(max, z);
for (i = 1; i < x; i++) {
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, - z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, z / max);
graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, - z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
/* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */
for (i = 1; i < y; i++) {
graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, - z / max);
graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, z / max);
graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, z / max);
graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, - z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
/* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */
for (i = 1; i < z; i++) {
graphics_draw_vertex (stack_id, - x / max, - y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, - x / max, y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, x / max, y / max, (2 * i / z - 1) * z / max);
graphics_draw_vertex (stack_id, x / max, - y / max, (2 * i / z - 1) * z / max);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f);
}
return (x + y + z - 3) * 3;
}
long draw_grids_on_space_faces_lines (const int stack_id,
long offset_vertex,
long x,
long y,
long z)
{
offset_vertex = offset_vertex / 3;
for (int i = 0; i < x - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
}
offset_vertex += (x - 1) * 4;
for (int i = 0; i < y - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
}
offset_vertex += (y - 1) * 4;
for (int i = 0; i < z - 1; i ++) {
graphics_draw_line (stack_id, offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1);
graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0);
}
return (x + y + z - 3) * 4;
}