diff --git a/inc/cub3d.h b/inc/cub3d.h index b2f178e..37ec48b 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ -/* Updated: 2025/04/17 19:51:30 by qmennen ### ########.fr */ +/* Updated: 2025/04/17 20:08:39 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,6 @@ # include "screen.h" # include "keyboard.h" # include "hooks.h" -# include "line.h" # include "render.h" # include "player.h" diff --git a/inc/render.h b/inc/render.h index 5289531..97b320d 100644 --- a/inc/render.h +++ b/inc/render.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */ -/* Updated: 2025/04/17 17:59:35 by qmennen ### ########.fr */ +/* Updated: 2025/04/17 20:08:08 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ # include "cub3d.h" +int render_check_bounds(t_screen *screen, t_vec2 *point); void render_line(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color); void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color); void render_clear(t_screen *screen); diff --git a/src/render.c b/src/render/render.c similarity index 56% rename from src/render.c rename to src/render/render.c index 7046f0c..7af8960 100644 --- a/src/render.c +++ b/src/render/render.c @@ -6,62 +6,16 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */ -/* Updated: 2025/04/17 17:59:14 by qmennen ### ########.fr */ +/* Updated: 2025/04/17 20:08:46 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "render.h" #include "MLX42.h" -void render_clear(t_screen *screen) +int render_check_bounds(t_screen *screen, t_vec2 *point) { - int i; - - i = 0; - while (i++ < screen->width * screen->height) - mlx_put_pixel(screen->img, i % screen->width, i / screen->width, 0x212121FF); -} - -void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color) -{ - int i; - int size; - int x; - int y; - - i = 0; - size = 2 * radius + 1; - while (i <= size * size) - { - x = i % size - radius; - y = i / size - radius; - if (x * x + y * y <= radius * radius) - mlx_put_pixel(screen->img, (int) point.x + x, (int) point.y + y, color); - i++; - } -} - -void render_line(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) -{ - if ((start.x < 0 || start.x >= (int) screen->img->width - || start.y < 0 || start.y >= (int) screen->img->height) - && (end.x < 0 || end.x >= (int) screen->img->width - || end.y < 0 || end.y >= (int) screen->img->height)) - return ; - if (abs((int) end.y - (int) start.y) < abs((int) end.x - (int) start.x)) - { - if (start.x > end.x) - line_low(screen, end, start, color); - else - line_low(screen, start, end, color); - } - else - { - if (start.y > end.y) - line_high(screen, end, start, color); - else - line_high(screen, start, end, color); - } + return (point->x >= 0 && point->x < screen->width && point->y > 0 && point->y < screen->height); } void render_tile(t_screen *screen, int x, int y, t_tile tile) diff --git a/src/render/render_circle.c b/src/render/render_circle.c new file mode 100644 index 0000000..0df9ba2 --- /dev/null +++ b/src/render/render_circle.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render_circle.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/17 20:06:19 by qmennen #+# #+# */ +/* Updated: 2025/04/17 20:06:32 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "render.h" + +void render_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color) +{ + int i; + int size; + int x; + int y; + + i = 0; + size = 2 * radius + 1; + while (i <= size * size) + { + x = i % size - radius; + y = i / size - radius; + if (x * x + y * y <= radius * radius) + mlx_put_pixel(screen->img, (int) point.x + x, (int) point.y + y, color); + i++; + } +} diff --git a/inc/line.h b/src/render/render_clear.c similarity index 63% rename from inc/line.h rename to src/render/render_clear.c index b81631c..d6c7474 100644 --- a/inc/line.h +++ b/src/render/render_clear.c @@ -1,20 +1,23 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* line.h :+: :+: :+: */ +/* clear_screen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/17 17:49:09 by qmennen #+# #+# */ -/* Updated: 2025/04/17 17:59:09 by qmennen ### ########.fr */ +/* Created: 2025/04/17 20:05:51 by qmennen #+# #+# */ +/* Updated: 2025/04/17 20:06:00 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef LINE_H -# define LINE_H -# include "cub3d.h" +#include "render.h" -void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color); -void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color); +void render_clear(t_screen *screen) +{ + int i; + + i = 0; + while (i++ < screen->width * screen->height) + mlx_put_pixel(screen->img, i % screen->width, i / screen->width, 0x212121FF); +} -#endif diff --git a/src/line.c b/src/render/render_line.c similarity index 60% rename from src/line.c rename to src/render/render_line.c index 8fc7096..2ea8009 100644 --- a/src/line.c +++ b/src/render/render_line.c @@ -1,24 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* line.c :+: :+: :+: */ +/* render_line.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/17 17:49:01 by qmennen #+# #+# */ -/* Updated: 2025/04/17 20:04:01 by qmennen ### ########.fr */ +/* Created: 2025/04/17 20:06:40 by qmennen #+# #+# */ +/* Updated: 2025/04/17 20:08:17 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ -#include "line.h" -#include "MLX42.h" +#include "render.h" -static int check_bounds(t_screen *screen, t_vec2 *point) -{ - return (point->x >= 0 && point->x < screen->width && point->y > 0 && point->y < screen->height); -} - -void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) +static void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) { int delta; int yi; @@ -34,7 +28,7 @@ void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) current = start; while (current.x <= end.x) { - if (check_bounds(screen, ¤t)) + if (render_check_bounds(screen, ¤t)) mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color); if (delta > 0) { @@ -46,7 +40,7 @@ void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) } } -void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) +static void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) { int delta; int xi; @@ -62,7 +56,7 @@ void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) current = start; while (current.y <= end.y) { - if (check_bounds(screen, ¤t)) + if (render_check_bounds(screen, ¤t)) mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color); if (delta > 0) { @@ -74,3 +68,25 @@ void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) } } +void render_line(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color) +{ + if ((start.x < 0 || start.x >= (int) screen->img->width + || start.y < 0 || start.y >= (int) screen->img->height) + && (end.x < 0 || end.x >= (int) screen->img->width + || end.y < 0 || end.y >= (int) screen->img->height)) + return ; + if (abs((int) end.y - (int) start.y) < abs((int) end.x - (int) start.x)) + { + if (start.x > end.x) + line_low(screen, end, start, color); + else + line_low(screen, start, end, color); + } + else + { + if (start.y > end.y) + line_high(screen, end, start, color); + else + line_high(screen, start, end, color); + } +} diff --git a/src/errors.c b/src/util/errors.c similarity index 100% rename from src/errors.c rename to src/util/errors.c diff --git a/src/hooks.c b/src/util/hooks.c similarity index 100% rename from src/hooks.c rename to src/util/hooks.c diff --git a/src/keyboard.c b/src/util/keyboard.c similarity index 100% rename from src/keyboard.c rename to src/util/keyboard.c