Organizational stuff
This commit is contained in:
parent
5d19de8673
commit
5db6f3e138
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 12:22:29 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 "screen.h"
|
||||||
# include "keyboard.h"
|
# include "keyboard.h"
|
||||||
# include "hooks.h"
|
# include "hooks.h"
|
||||||
# include "line.h"
|
|
||||||
# include "render.h"
|
# include "render.h"
|
||||||
# include "player.h"
|
# include "player.h"
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 16:28:16 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"
|
# 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_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_circle(t_screen *screen, t_vec2 point, int radius, unsigned int color);
|
||||||
void render_clear(t_screen *screen);
|
void render_clear(t_screen *screen);
|
||||||
|
|||||||
@ -6,62 +6,16 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 16:28:10 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 "render.h"
|
||||||
#include "MLX42.h"
|
#include "MLX42.h"
|
||||||
|
|
||||||
void render_clear(t_screen *screen)
|
int render_check_bounds(t_screen *screen, t_vec2 *point)
|
||||||
{
|
{
|
||||||
int i;
|
return (point->x >= 0 && point->x < screen->width && point->y > 0 && point->y < screen->height);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_tile(t_screen *screen, int x, int y, t_tile tile)
|
void render_tile(t_screen *screen, int x, int y, t_tile tile)
|
||||||
32
src/render/render_circle.c
Normal file
32
src/render/render_circle.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* render_circle.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,20 +1,23 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* line.h :+: :+: :+: */
|
/* clear_screen.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 17:49:09 by qmennen #+# #+# */
|
/* Created: 2025/04/17 20:05:51 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/04/17 17:59:09 by qmennen ### ########.fr */
|
/* Updated: 2025/04/17 20:06:00 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef LINE_H
|
#include "render.h"
|
||||||
# define LINE_H
|
|
||||||
# include "cub3d.h"
|
|
||||||
|
|
||||||
void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color);
|
void render_clear(t_screen *screen)
|
||||||
void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color);
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i++ < screen->width * screen->height)
|
||||||
|
mlx_put_pixel(screen->img, i % screen->width, i / screen->width, 0x212121FF);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,24 +1,18 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* line.c :+: :+: :+: */
|
/* render_line.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 17:49:01 by qmennen #+# #+# */
|
/* Created: 2025/04/17 20:06:40 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/04/17 20:04:01 by qmennen ### ########.fr */
|
/* Updated: 2025/04/17 20:08:17 by qmennen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "line.h"
|
#include "render.h"
|
||||||
#include "MLX42.h"
|
|
||||||
|
|
||||||
static int check_bounds(t_screen *screen, t_vec2 *point)
|
static void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
int delta;
|
int delta;
|
||||||
int yi;
|
int yi;
|
||||||
@ -34,7 +28,7 @@ void line_low(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
|||||||
current = start;
|
current = start;
|
||||||
while (current.x <= end.x)
|
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);
|
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||||
if (delta > 0)
|
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 delta;
|
||||||
int xi;
|
int xi;
|
||||||
@ -62,7 +56,7 @@ void line_high(t_screen *screen, t_vec2 start, t_vec2 end, unsigned int color)
|
|||||||
current = start;
|
current = start;
|
||||||
while (current.y <= end.y)
|
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);
|
mlx_put_pixel(screen->img, (int)current.x, (int)current.y, color);
|
||||||
if (delta > 0)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user