From a714e8110d30e74039ab45ab643451957b525913 Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Thu, 17 Oct 2024 12:28:34 +0200 Subject: [PATCH 1/9] temp --- utils2.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 utils2.c diff --git a/utils2.c b/utils2.c new file mode 100644 index 0000000..6e3d3b3 --- /dev/null +++ b/utils2.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: greg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 01:57:03 by greg #+# #+# */ +/* Updated: 2024/10/17 12:28:01 by greg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +// #include "algo.h" +void ft_init_texture() +{ + if (ray.side == 0 && ray.raydirx < 0) + direction = 0; + if (ray.side == 0 && ray.raydirx >= 0) + direction = 1; + if (ray.side == 1 && ray.raydiry < 0) + direction = 2; + if (ray.side == 1 && ray.raydiry >= 0) + direction = 3; + if (ray.side == 0) + t.wallx = ray.posy + ray.perpwalldist \ + * ray.raydiry; + else + t.wallx = ray.posx + ray.perpwalldist \ + * ray.raydirx; + t.wallx -= floor((t.wallx)); +} + +texture[0].addr = (int *)mlx_get_data_addr(texture[0].img, &bpp, + texture[0].line_length, &endian); + + +void load_textures() +{ + g_tex.tex_width = 64; + g_tex.tex_height = 64; + + g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &g_tex.tex_width, &g_tex.tex_height); +} \ No newline at end of file From bc2d42d9417d70fbb7778b68ab23232bc67e8ee8 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 16:32:01 +0200 Subject: [PATCH 2/9] add texture --- Makefile | 2 +- algo.c | 29 +++++++++++---------- algo.h | 33 +++++++++++++++--------- render.c | 76 ++++++++++++++++++++++++++++++++++++++++++-------------- utils.c | 4 +-- utils2.c | 76 ++++++++++++++++++++++++++++++-------------------------- 6 files changed, 138 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index 4ef9264..ad84bcb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME = cub3d CPP = gcc $(FLAGS) LIBRARIES_DIR = Libft Minilibx LIBRARIES_A = Libft/libft.a Minilibx/libmlx.a -CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx $(FLAGS_1) +CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx $(FLAGS_1) -g CPP_2 = $(CPP) $(FLAGS_2) SHARED = -lX11 -lXext -lm C_FILES = $(wildcard **.c) diff --git a/algo.c b/algo.c index 08bdf5c..f042a1b 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:38:31 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:20:19 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; +t_tex g_tex; +t_ray g_ray; // TODO manage image format error better @@ -39,24 +41,25 @@ void draw_screen(void) mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); } -void load_textures(t_tex *tex) +void load_textures() { - int width; - int height; + g_tex.tex_width = 64; + g_tex.tex_height = 64; - tex->tex_north = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &width, &height); - tex->tex_south = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &width, &height); - tex->tex_east = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &width, &height); - tex->tex_west = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &width, &height); + g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &g_tex.tex_width, &g_tex.tex_height); + g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &g_tex.tex_width, &g_tex.tex_height); } int main(int argc, char *argv[]) { g_mlx = mlx_init(); + load_textures(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); diff --git a/algo.h b/algo.h index 55be665..03dafc2 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/15 16:57:48 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 15:17:36 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,20 +40,29 @@ # define SCREEN_HEIGHT 480 // px # define FOV 0.66 // ? TODO unit +typedef struct s_tex +{ + void *textures[4]; + void *current_tex; + int tex_height; + int tex_width; + int tex_dir; +} t_tex; + +typedef struct s_ray +{ + // pos player on map (cases) + t_point_double dir; + bool side; + double wallx; +} t_ray; + extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; - -typedef struct s_tex -{ - void *tex_north; - void *tex_south; - void *tex_east; - void *tex_west; - void *current_tex; - -} t_tex; +extern t_tex g_tex; +extern t_ray g_ray; /// @brief Write an error message on stderr. /// diff --git a/render.c b/render.c index 6279fd5..26633f1 100644 --- a/render.c +++ b/render.c @@ -3,17 +3,18 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/15 16:55:02 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:28:20 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" +#include static void calculate_perpwalldist3(int x, - t_point_double *raydir, t_point_double *deltadist) + t_point_double *deltadist) { const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; t_point_double plane; @@ -21,14 +22,14 @@ static void calculate_perpwalldist3(int x, vector_from_rotation(&dir, g_map.player.rot, 1); vector_from_rotation(&plane, g_map.player.rot + PI / 2, 1); - raydir->x = dir.x + plane.x * ray_direction; - raydir->y = dir.y + plane.y * ray_direction; + g_ray.dir.x = dir.x + plane.x * ray_direction; + g_ray.dir.y = dir.y + plane.y * ray_direction; deltadist->x = 1e30; - if (raydir->x != 0) - deltadist->x = fabs(1 / raydir->x); + if (g_ray.dir.x != 0) + deltadist->x = fabs(1 / g_ray.dir.x); deltadist->y = 1e30; - if (raydir->y != 0) - deltadist->y = fabs(1 / raydir->y); + if (g_ray.dir.y != 0) + deltadist->y = fabs(1 / g_ray.dir.y); } static void calculate_perpwalldist2(int x, @@ -38,10 +39,10 @@ static void calculate_perpwalldist2(int x, { const int map_x = (int)g_map.player.pos.x; const int map_y = (int)g_map.player.pos.y; - t_point_double raydir; + // t_point_double raydir; - calculate_perpwalldist3(x, &raydir, deltadist); - if (raydir.x < 0) + calculate_perpwalldist3(x, deltadist); + if (g_ray.dir.x < 0) { step->x = -1; sidedist->x = (g_map.player.pos.x - map_x) * deltadist->x; @@ -51,7 +52,7 @@ static void calculate_perpwalldist2(int x, step->x = 1; sidedist->x = (map_x + 1.0 - g_map.player.pos.x) * deltadist->x; } - if (raydir.y < 0) + if (g_ray.dir.y < 0) { step->y = -1; sidedist->y = (g_map.player.pos.y - map_y) * deltadist->y; @@ -71,7 +72,7 @@ static void calculate_perpwalldist2(int x, static double calculate_perpwalldist(int x) { t_point_int map_pos; - bool side; + // bool side; t_point_double sidedist; t_point_double deltadist; t_point_int step; @@ -85,18 +86,37 @@ static double calculate_perpwalldist(int x) { sidedist.x += deltadist.x; map_pos.x += step.x; - side = false; + g_ray.side = false; continue ; } sidedist.y += deltadist.y; map_pos.y += step.y; - side = true; + g_ray.side = true; } - if (!side) + if (!g_ray.side) return (sidedist.x - deltadist.x); return (sidedist.y - deltadist.y); } +static void ft_init_texture(const double perpwalldist) +{ + if (g_ray.side == 0 && g_ray.dir.x < 0) + g_tex.tex_dir = 0; + if (g_ray.side == 0 && g_ray.dir.x >= 0) + g_tex.tex_dir = 1; + if (g_ray.side == 1 && g_ray.dir.y < 0) + g_tex.tex_dir = 2; + if (g_ray.side == 1 && g_ray.dir.y >= 0) + g_tex.tex_dir = 3; + if (g_ray.side == 0) + g_ray.wallx = g_player.pos.y + perpwalldist \ + * g_ray.dir.y; + else + g_ray.wallx = g_player.pos.x + perpwalldist \ + * g_ray.dir.x; + g_ray.wallx -= floor((g_ray.wallx)); +} + /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. @@ -107,7 +127,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) int draw_start; int draw_end; int y; + int tex_y; + int tex_x; + int bpp; + int size_line; + int endian; + u_int32_t color; + ft_init_texture(perpwalldist); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; if (draw_start < 0) draw_start = 0; @@ -120,7 +147,18 @@ static void draw_vertical_line(int x, u_int32_t *img_data) if (y < draw_start) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) - img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + { + tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; + tex_x = (int)(g_ray.wallx * g_tex.tex_width); + if (g_ray.side == 0 && g_ray.dir.x > 0) + tex_x = g_tex.tex_width - tex_x - 1; + if (g_ray.side == 1 && g_ray.dir.y < 0) + tex_x = g_tex.tex_height - tex_x - 1; + u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); + color = texture_data[tex_y * g_tex.tex_width + tex_x]; + img_data[y * SCREEN_WIDTH + x] = color; + // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; + } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; y++; @@ -138,4 +176,4 @@ int render(u_int32_t *img_data) x++; } return (0); -} +} \ No newline at end of file diff --git a/utils.c b/utils.c index 48e0c16..283a990 100644 --- a/utils.c +++ b/utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 12:38:40 by mcolonna #+# #+# */ -/* Updated: 2024/10/16 18:01:25 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 13:43:50 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/utils2.c b/utils2.c index 6e3d3b3..dc81ffa 100644 --- a/utils2.c +++ b/utils2.c @@ -3,48 +3,54 @@ /* ::: :::::::: */ /* utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 12:28:01 by greg ### ########.fr */ +/* Updated: 2024/10/17 14:58:33 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ // #include "algo.h" -void ft_init_texture() -{ - if (ray.side == 0 && ray.raydirx < 0) - direction = 0; - if (ray.side == 0 && ray.raydirx >= 0) - direction = 1; - if (ray.side == 1 && ray.raydiry < 0) - direction = 2; - if (ray.side == 1 && ray.raydiry >= 0) - direction = 3; - if (ray.side == 0) - t.wallx = ray.posy + ray.perpwalldist \ - * ray.raydiry; - else - t.wallx = ray.posx + ray.perpwalldist \ - * ray.raydirx; - t.wallx -= floor((t.wallx)); -} -texture[0].addr = (int *)mlx_get_data_addr(texture[0].img, &bpp, - texture[0].line_length, &endian); +// void ft_init_texture(const double perpwalldist) +// { +// if (g_ray.side == 0 && g_ray.dir.x < 0) +// g_tex.tex_dir = 0; +// if (g_ray.side == 0 && g_ray.dir.x >= 0) +// g_tex.tex_dir = 1; +// if (g_ray.side == 1 && g_ray.dir.y < 0) +// g_tex.tex_dir = 2; +// if (g_ray.side == 1 && g_ray.dir.y >= 0) +// g_tex.tex_dir = 3; +// if (g_ray.side == 0) +// g_ray.wallx = g_player.pos.y + perpwalldist +// * g_ray.dir.y; +// else +// g_ray.wallx = g_player.pos.x + perpwalldist +// * g_ray.dir.x; +// g_ray.wallx -= floor((g_ray.wallx)); +// } + +// void *tex_ptr = (int *)mlx_get_data_addr(texture[0].img, &bpp, +// g_tex, &endian); -void load_textures() -{ - g_tex.tex_width = 64; - g_tex.tex_height = 64; +// tex_y = ((y - draw_start) * texture_height) / line_height; - g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &g_tex.tex_width, &g_tex.tex_height); -} \ No newline at end of file +// tex_x = (int)(wall_x * (double)texture_width); +// if ((!side && raydir.x > 0) || (side && raydir.y < 0)) +// { +// tex_x = texture_width - tex_x - 1; +// } + +// u_int32_t color = textures[direction][tex_y * texture_width + tex_x]; + + + // else if (y < draw_end) + // { + // tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; + // tex_x = (int)(g_ray.wallx * g_tex.tex_width); + // u_int32_t *texture_data = (u_int32_t *)g_tex.textures[g_tex.tex_dir]; + // u_int32_t color = texture_data[tex_y * g_tex.tex_width + tex_x]; + // img_data[y * SCREEN_WIDTH + x] = color; + // } \ No newline at end of file From e74045d3189fa6935f7cb21423f325420e199869 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 16:59:35 +0200 Subject: [PATCH 3/9] fix: leak --- algo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algo.c b/algo.c index 24e3964..d60b6cd 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:35:28 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 16:59:16 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,7 @@ void draw_screen(void) } render(img_data); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); + mlx_destroy_image(g_mlx, img_ptr); } void load_textures() From dee20e3897fee371afeb7f31a2867df37e82e8d8 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 17:06:31 +0200 Subject: [PATCH 4/9] mini correction --- render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/render.c b/render.c index 26633f1..b1e3958 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 16:28:20 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 16:56:10 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -153,9 +153,9 @@ static void draw_vertical_line(int x, u_int32_t *img_data) if (g_ray.side == 0 && g_ray.dir.x > 0) tex_x = g_tex.tex_width - tex_x - 1; if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_height - tex_x - 1; + tex_x = g_tex.tex_width - tex_x - 1; u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_y * g_tex.tex_width + tex_x]; + color = texture_data[tex_x * g_tex.tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; } From fab7758283d833d67d93e06cdd6e0bbb46df8028 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Thu, 17 Oct 2024 18:04:40 +0200 Subject: [PATCH 5/9] manque render mur pas fixe --- render.c | 9 ++++----- testmaps/good_directions.cub | 2 +- utils2.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/render.c b/render.c index b1e3958..cbcbc5c 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 16:56:10 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 18:02:06 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -148,16 +148,15 @@ static void draw_vertical_line(int x, u_int32_t *img_data) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; - tex_x = (int)(g_ray.wallx * g_tex.tex_width); + tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * g_tex.tex_height) / line_height; + tex_x = (int)(g_ray.wallx * (double)g_tex.tex_width); if (g_ray.side == 0 && g_ray.dir.x > 0) tex_x = g_tex.tex_width - tex_x - 1; if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_width - tex_x - 1; + tex_x = g_tex.tex_height - tex_x - 1; u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); color = texture_data[tex_x * g_tex.tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; - // img_data[y * SCREEN_WIDTH + x] = COLOR_WALL; } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; diff --git a/testmaps/good_directions.cub b/testmaps/good_directions.cub index 0701362..d27f00d 100644 --- a/testmaps/good_directions.cub +++ b/testmaps/good_directions.cub @@ -4,7 +4,7 @@ NO theimageforthenorthwall C 0,2,67 SO SOUTH!!!!!!1 WE weeeee - 111 +111111111 111110111 10000N001 111110111 diff --git a/utils2.c b/utils2.c index dc81ffa..9a323a8 100644 --- a/utils2.c +++ b/utils2.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 14:58:33 by grobledo ### ########.fr */ +/* Updated: 2024/10/17 17:39:18 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ From ff7ba8760db7ce1b8e9a6648d03a5f413371aeec Mon Sep 17 00:00:00 2001 From: ReverseSky Date: Fri, 18 Oct 2024 02:03:07 +0200 Subject: [PATCH 6/9] textures fixed --- render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/render.c b/render.c index cbcbc5c..adfc5f4 100644 --- a/render.c +++ b/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ +/* By: greg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/17 18:02:06 by grobledo ### ########.fr */ +/* Updated: 2024/10/18 02:02:32 by greg ### ########.fr */ /* */ /* ************************************************************************** */ @@ -109,10 +109,10 @@ static void ft_init_texture(const double perpwalldist) if (g_ray.side == 1 && g_ray.dir.y >= 0) g_tex.tex_dir = 3; if (g_ray.side == 0) - g_ray.wallx = g_player.pos.y + perpwalldist \ + g_ray.wallx = g_map.player.pos.y + perpwalldist \ * g_ray.dir.y; else - g_ray.wallx = g_player.pos.x + perpwalldist \ + g_ray.wallx = g_map.player.pos.x + perpwalldist \ * g_ray.dir.x; g_ray.wallx -= floor((g_ray.wallx)); } From 50c4e563032a70c92692b2e5cdc076e087eaf9f6 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 22 Oct 2024 15:59:58 +0200 Subject: [PATCH 7/9] removed g_ray and g_tex --- algo.c | 44 +++++++++---------- algo.h | 9 ++-- render.c | 100 +++++++++++++++++++++--------------------- testmaps/good_big.cub | 2 +- 4 files changed, 77 insertions(+), 78 deletions(-) diff --git a/algo.c b/algo.c index d60b6cd..95bcf92 100644 --- a/algo.c +++ b/algo.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:59:16 by mcolonna ### ########.fr */ +/* Updated: 2024/10/22 15:48:47 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,35 @@ void *g_mlx = NULL; void *g_win = NULL; t_map g_map; t_player g_player; -t_tex g_tex; -t_ray g_ray; +// t_tex g_tex; // TODO manage image format error better -void draw_screen(void) +static void load_textures(t_tex *tex) +{ + tex->tex_width = 64; + tex->tex_height = 64; + + tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + &tex->tex_width, &tex->tex_height); + tex->textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + &tex->tex_width, &tex->tex_height); +} + +void draw_screen() { int bpp; int size_line; int endian; void *img_ptr; u_int32_t *img_data; + t_tex tex; + load_textures(&tex); img_ptr = mlx_new_image(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT); img_data = (u_int32_t *) mlx_get_data_addr(img_ptr, &bpp, &size_line, &endian); @@ -38,26 +54,11 @@ void draw_screen(void) printf("image format error\n"); exit(1); } - render(img_data); + render(img_data, &tex); mlx_put_image_to_window(g_mlx, g_win, img_ptr, 0, 0); mlx_destroy_image(g_mlx, img_ptr); } -void load_textures() -{ - g_tex.tex_width = 64; - g_tex.tex_height = 64; - - g_tex.textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", - &g_tex.tex_width, &g_tex.tex_height); - g_tex.textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", - &g_tex.tex_width, &g_tex.tex_height); -} - static void loop(void) { move(); @@ -80,7 +81,6 @@ int main(int argc, char *argv[]) { g_mlx = mlx_init(); input_init(); - load_textures(); if (argc != 2) { printf("Syntax: %s \n", argv[0]); diff --git a/algo.h b/algo.h index 0700d7a..270937f 100644 --- a/algo.h +++ b/algo.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcolonna +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/17 16:34:32 by mcolonna ### ########.fr */ +/* Updated: 2024/10/22 15:48:21 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,8 +62,7 @@ extern void *g_mlx; extern void *g_win; extern t_player g_player; extern t_map g_map; -extern t_tex g_tex; -extern t_ray g_ray; +// extern t_tex g_tex; /// @brief Write an error message on stderr. /// @@ -72,7 +71,7 @@ void write_err(const char *str, ...); void vector_from_rotation(t_point_double *vec, double angle, double norm); -int render(u_int32_t *img_data); +int render(u_int32_t *img_data, t_tex *tex); void draw_screen(void); diff --git a/render.c b/render.c index adfc5f4..27bb911 100644 --- a/render.c +++ b/render.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* render.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: greg +#+ +:+ +#+ */ +/* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/18 02:02:32 by greg ### ########.fr */ +/* Updated: 2024/10/22 15:50:27 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ #include static void calculate_perpwalldist3(int x, - t_point_double *deltadist) + t_point_double *deltadist, + t_ray *ray) { const double ray_direction = 2 * x / (double)SCREEN_WIDTH - 1; t_point_double plane; @@ -22,27 +23,27 @@ static void calculate_perpwalldist3(int x, vector_from_rotation(&dir, g_map.player.rot, 1); vector_from_rotation(&plane, g_map.player.rot + PI / 2, 1); - g_ray.dir.x = dir.x + plane.x * ray_direction; - g_ray.dir.y = dir.y + plane.y * ray_direction; + ray->dir.x = dir.x + plane.x * ray_direction; + ray->dir.y = dir.y + plane.y * ray_direction; deltadist->x = 1e30; - if (g_ray.dir.x != 0) - deltadist->x = fabs(1 / g_ray.dir.x); + if (ray->dir.x != 0) + deltadist->x = fabs(1 / ray->dir.x); deltadist->y = 1e30; - if (g_ray.dir.y != 0) - deltadist->y = fabs(1 / g_ray.dir.y); + if (ray->dir.y != 0) + deltadist->y = fabs(1 / ray->dir.y); } static void calculate_perpwalldist2(int x, t_point_double *sidedist, t_point_double *deltadist, - t_point_int *step) + t_point_int *step, + t_ray *ray) { const int map_x = (int)g_map.player.pos.x; const int map_y = (int)g_map.player.pos.y; - // t_point_double raydir; - calculate_perpwalldist3(x, deltadist); - if (g_ray.dir.x < 0) + calculate_perpwalldist3(x, deltadist, ray); + if (ray->dir.x < 0) { step->x = -1; sidedist->x = (g_map.player.pos.x - map_x) * deltadist->x; @@ -52,7 +53,7 @@ static void calculate_perpwalldist2(int x, step->x = 1; sidedist->x = (map_x + 1.0 - g_map.player.pos.x) * deltadist->x; } - if (g_ray.dir.y < 0) + if (ray->dir.y < 0) { step->y = -1; sidedist->y = (g_map.player.pos.y - map_y) * deltadist->y; @@ -69,60 +70,59 @@ static void calculate_perpwalldist2(int x, /// /// @param x Ray direction x between 0 and 1. /// @return Result. -static double calculate_perpwalldist(int x) +static double calculate_perpwalldist(int x, t_ray *ray) { t_point_int map_pos; - // bool side; t_point_double sidedist; t_point_double deltadist; t_point_int step; map_pos.x = (int)g_map.player.pos.x; map_pos.y = (int)g_map.player.pos.y; - calculate_perpwalldist2(x, &sidedist, &deltadist, &step); + calculate_perpwalldist2(x, &sidedist, &deltadist, &step, ray); while (map_get_case(&g_map, map_pos.x, map_pos.y)->wall == EMPTY) { if (sidedist.x < sidedist.y) { sidedist.x += deltadist.x; map_pos.x += step.x; - g_ray.side = false; + ray->side = false; continue ; } sidedist.y += deltadist.y; map_pos.y += step.y; - g_ray.side = true; + ray->side = true; } - if (!g_ray.side) + if (!ray->side) return (sidedist.x - deltadist.x); return (sidedist.y - deltadist.y); } -static void ft_init_texture(const double perpwalldist) +static void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) { - if (g_ray.side == 0 && g_ray.dir.x < 0) - g_tex.tex_dir = 0; - if (g_ray.side == 0 && g_ray.dir.x >= 0) - g_tex.tex_dir = 1; - if (g_ray.side == 1 && g_ray.dir.y < 0) - g_tex.tex_dir = 2; - if (g_ray.side == 1 && g_ray.dir.y >= 0) - g_tex.tex_dir = 3; - if (g_ray.side == 0) - g_ray.wallx = g_map.player.pos.y + perpwalldist \ - * g_ray.dir.y; + if (ray->side == 0 && ray->dir.x < 0) + tex->tex_dir = 0; + if (ray->side == 0 && ray->dir.x >= 0) + tex->tex_dir = 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_dir = 2; + if (ray->side == 1 && ray->dir.y >= 0) + tex->tex_dir = 3; + if (ray->side == 0) + ray->wallx = g_map.player.pos.y + perpwalldist \ + * ray->dir.y; else - g_ray.wallx = g_map.player.pos.x + perpwalldist \ - * g_ray.dir.x; - g_ray.wallx -= floor((g_ray.wallx)); + ray->wallx = g_map.player.pos.x + perpwalldist \ + * ray->dir.x; + ray->wallx -= floor((ray->wallx)); } /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. -static void draw_vertical_line(int x, u_int32_t *img_data) +static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *tex) { - const double perpwalldist = calculate_perpwalldist(x); + const double perpwalldist = calculate_perpwalldist(x, ray); const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); int draw_start; int draw_end; @@ -134,7 +134,7 @@ static void draw_vertical_line(int x, u_int32_t *img_data) int endian; u_int32_t color; - ft_init_texture(perpwalldist); + ft_init_texture(perpwalldist, ray, tex); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; if (draw_start < 0) draw_start = 0; @@ -148,14 +148,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * g_tex.tex_height) / line_height; - tex_x = (int)(g_ray.wallx * (double)g_tex.tex_width); - if (g_ray.side == 0 && g_ray.dir.x > 0) - tex_x = g_tex.tex_width - tex_x - 1; - if (g_ray.side == 1 && g_ray.dir.y < 0) - tex_x = g_tex.tex_height - tex_x - 1; - u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(g_tex.textures[g_tex.tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_x * g_tex.tex_width + tex_y]; + tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * tex->tex_height) / line_height; + tex_x = (int)(ray->wallx * (double)tex->tex_width); + if (ray->side == 0 && ray->dir.x > 0) + tex_x = tex->tex_width - tex_x - 1; + if (ray->side == 1 && ray->dir.y < 0) + tex_x = tex->tex_height - tex_x - 1; + u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &bpp, &size_line, &endian); + color = texture_data[tex_x * tex->tex_width + tex_y]; img_data[y * SCREEN_WIDTH + x] = color; } else @@ -164,14 +164,14 @@ static void draw_vertical_line(int x, u_int32_t *img_data) } } -int render(u_int32_t *img_data) +int render(u_int32_t *img_data, t_tex *tex) { - int x; - + int x; + t_ray ray; x = 0; while (x < SCREEN_WIDTH) { - draw_vertical_line(x, img_data); + draw_vertical_line(x, img_data, &ray, tex); x++; } return (0); diff --git a/testmaps/good_big.cub b/testmaps/good_big.cub index c118d77..fbf802a 100644 --- a/testmaps/good_big.cub +++ b/testmaps/good_big.cub @@ -6,7 +6,7 @@ SO SOUTH!!!!!!1 WE weeeee 111111111 100000001 -100000001 +100010001 100000001 1000N0001 100000001 From 8e650871e75fda1e5cbdb20425221ca9a92332b6 Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 13:52:11 +0100 Subject: [PATCH 8/9] norme --- algo.c | 10 +++++----- algo.h | 11 ++++++++++- render.c | 46 +++++++-------------------------------------- render2.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ utils2.c | 56 ------------------------------------------------------- 5 files changed, 73 insertions(+), 101 deletions(-) create mode 100644 render2.c delete mode 100644 utils2.c diff --git a/algo.c b/algo.c index 95bcf92..51f24f0 100644 --- a/algo.c +++ b/algo.c @@ -6,12 +6,13 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/22 15:48:47 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:37:04 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" #include "input.h" +#include void *g_mlx = NULL; void *g_win = NULL; @@ -25,18 +26,17 @@ static void load_textures(t_tex *tex) { tex->tex_width = 64; tex->tex_height = 64; - tex->textures[0] = mlx_xpm_file_to_image(g_mlx, "textures/north.xpm", &tex->tex_width, &tex->tex_height); tex->textures[1] = mlx_xpm_file_to_image(g_mlx, "textures/south.xpm", &tex->tex_width, &tex->tex_height); - tex->textures[2]= mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", + tex->textures[2] = mlx_xpm_file_to_image(g_mlx, "textures/east.xpm", &tex->tex_width, &tex->tex_height); - tex->textures[3]= mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", + tex->textures[3] = mlx_xpm_file_to_image(g_mlx, "textures/west.xpm", &tex->tex_width, &tex->tex_height); } -void draw_screen() +void draw_screen(void) { int bpp; int size_line; diff --git a/algo.h b/algo.h index 270937f..32839ac 100644 --- a/algo.h +++ b/algo.h @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */ -/* Updated: 2024/10/22 15:48:21 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:27:27 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,11 @@ typedef struct s_tex int tex_height; int tex_width; int tex_dir; + int tex_x; + int tex_y; + int bpp; + int size_line; + int endian; } t_tex; typedef struct s_ray @@ -77,4 +82,8 @@ void draw_screen(void); void move(void); +void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex); + +void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, + int y, u_int32_t *img_data); #endif diff --git a/render.c b/render.c index 27bb911..15985c7 100644 --- a/render.c +++ b/render.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 14:55:05 by greg #+# #+# */ -/* Updated: 2024/10/22 15:50:27 by grobledo ### ########.fr */ +/* Updated: 2024/10/24 14:27:52 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,41 +98,17 @@ static double calculate_perpwalldist(int x, t_ray *ray) return (sidedist.y - deltadist.y); } -static void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) -{ - if (ray->side == 0 && ray->dir.x < 0) - tex->tex_dir = 0; - if (ray->side == 0 && ray->dir.x >= 0) - tex->tex_dir = 1; - if (ray->side == 1 && ray->dir.y < 0) - tex->tex_dir = 2; - if (ray->side == 1 && ray->dir.y >= 0) - tex->tex_dir = 3; - if (ray->side == 0) - ray->wallx = g_map.player.pos.y + perpwalldist \ - * ray->dir.y; - else - ray->wallx = g_map.player.pos.x + perpwalldist \ - * ray->dir.x; - ray->wallx -= floor((ray->wallx)); -} - /// @brief Draw a vertical line according to the ray direction x. /// /// @param x Ray direction x between 0 and 1. -static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *tex) +static void draw_vertical_line(int x, u_int32_t *img_data, + t_ray *ray, t_tex *tex) { const double perpwalldist = calculate_perpwalldist(x, ray); const int line_height = (int)(SCREEN_HEIGHT / perpwalldist); int draw_start; int draw_end; int y; - int tex_y; - int tex_x; - int bpp; - int size_line; - int endian; - u_int32_t color; ft_init_texture(perpwalldist, ray, tex); draw_start = -line_height / 2 + SCREEN_HEIGHT / 2; @@ -142,25 +118,16 @@ static void draw_vertical_line(int x, u_int32_t *img_data, t_ray *ray, t_tex *te if (draw_end >= SCREEN_HEIGHT) draw_end = SCREEN_HEIGHT - 1; y = 0; - while (y < SCREEN_HEIGHT) + while (y++ < SCREEN_HEIGHT) { if (y < draw_start) img_data[y * SCREEN_WIDTH + x] = COLOR_CEILING; else if (y < draw_end) { - tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) * tex->tex_height) / line_height; - tex_x = (int)(ray->wallx * (double)tex->tex_width); - if (ray->side == 0 && ray->dir.x > 0) - tex_x = tex->tex_width - tex_x - 1; - if (ray->side == 1 && ray->dir.y < 0) - tex_x = tex->tex_height - tex_x - 1; - u_int32_t *texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &bpp, &size_line, &endian); - color = texture_data[tex_x * tex->tex_width + tex_y]; - img_data[y * SCREEN_WIDTH + x] = color; + draw_wall(tex, ray, line_height, x, y, img_data); } else img_data[y * SCREEN_WIDTH + x] = COLOR_FLOOR; - y++; } } @@ -168,6 +135,7 @@ int render(u_int32_t *img_data, t_tex *tex) { int x; t_ray ray; + x = 0; while (x < SCREEN_WIDTH) { @@ -175,4 +143,4 @@ int render(u_int32_t *img_data, t_tex *tex) x++; } return (0); -} \ No newline at end of file +} diff --git a/render2.c b/render2.c new file mode 100644 index 0000000..f6df898 --- /dev/null +++ b/render2.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* render2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: grobledo +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ +/* Updated: 2024/10/24 14:27:37 by grobledo ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "algo.h" + +void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) +{ + if (ray->side == 0 && ray->dir.x < 0) + tex->tex_dir = 0; + if (ray->side == 0 && ray->dir.x >= 0) + tex->tex_dir = 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_dir = 2; + if (ray->side == 1 && ray->dir.y >= 0) + tex->tex_dir = 3; + if (ray->side == 0) + ray->wallx = g_map.player.pos.y + perpwalldist \ + * ray->dir.y; + else + ray->wallx = g_map.player.pos.x + perpwalldist \ + * ray->dir.x; + ray->wallx -= floor((ray->wallx)); +} + +void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, + int y, u_int32_t *img_data) +{ + u_int32_t color; + u_int32_t *texture_data; + + tex->tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ + * tex->tex_height) / line_height; + tex->tex_x = (int)(ray->wallx * (double)tex->tex_width); + if (ray->side == 0 && ray->dir.x > 0) + tex->tex_x = tex->tex_width - tex->tex_x - 1; + if (ray->side == 1 && ray->dir.y < 0) + tex->tex_x = tex->tex_height - tex->tex_x - 1; + texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], + &tex->bpp, &tex->size_line, &tex->endian); + color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; + img_data[y * SCREEN_WIDTH + x] = color; +} \ No newline at end of file diff --git a/utils2.c b/utils2.c deleted file mode 100644 index 9a323a8..0000000 --- a/utils2.c +++ /dev/null @@ -1,56 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils2.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: grobledo +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/10/17 01:57:03 by greg #+# #+# */ -/* Updated: 2024/10/17 17:39:18 by grobledo ### ########.fr */ -/* */ -/* ************************************************************************** */ - -// #include "algo.h" - -// void ft_init_texture(const double perpwalldist) -// { -// if (g_ray.side == 0 && g_ray.dir.x < 0) -// g_tex.tex_dir = 0; -// if (g_ray.side == 0 && g_ray.dir.x >= 0) -// g_tex.tex_dir = 1; -// if (g_ray.side == 1 && g_ray.dir.y < 0) -// g_tex.tex_dir = 2; -// if (g_ray.side == 1 && g_ray.dir.y >= 0) -// g_tex.tex_dir = 3; -// if (g_ray.side == 0) -// g_ray.wallx = g_player.pos.y + perpwalldist -// * g_ray.dir.y; -// else -// g_ray.wallx = g_player.pos.x + perpwalldist -// * g_ray.dir.x; -// g_ray.wallx -= floor((g_ray.wallx)); -// } - -// void *tex_ptr = (int *)mlx_get_data_addr(texture[0].img, &bpp, -// g_tex, &endian); - - -// tex_y = ((y - draw_start) * texture_height) / line_height; - -// tex_x = (int)(wall_x * (double)texture_width); -// if ((!side && raydir.x > 0) || (side && raydir.y < 0)) -// { -// tex_x = texture_width - tex_x - 1; -// } - -// u_int32_t color = textures[direction][tex_y * texture_width + tex_x]; - - - // else if (y < draw_end) - // { - // tex_y = ((y - draw_start) * g_tex.tex_height) / line_height; - // tex_x = (int)(g_ray.wallx * g_tex.tex_width); - // u_int32_t *texture_data = (u_int32_t *)g_tex.textures[g_tex.tex_dir]; - // u_int32_t color = texture_data[tex_y * g_tex.tex_width + tex_x]; - // img_data[y * SCREEN_WIDTH + x] = color; - // } \ No newline at end of file From b593057cd55bacdd488efd06dbbf535d269d644b Mon Sep 17 00:00:00 2001 From: Gregory Robledo Date: Tue, 29 Oct 2024 14:23:48 +0100 Subject: [PATCH 9/9] repush --- algo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/algo.c b/algo.c index 51f24f0..52271f0 100644 --- a/algo.c +++ b/algo.c @@ -6,7 +6,7 @@ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/01 16:24:58 by grobledo #+# #+# */ -/* Updated: 2024/10/24 14:37:04 by grobledo ### ########.fr */ +/* Updated: 2024/10/29 14:23:34 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,6 +77,8 @@ static int loop_hook(void *param) return (0); } + + int main(int argc, char *argv[]) { g_mlx = mlx_init();