From 50ff43445bd767dc23b1ec5a04da6a0771063cd8 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Thu, 25 Jan 2024 15:16:02 +0100 Subject: [PATCH] jeudi --- .vscode/settings.json | 5 ++- cub3d.h | 36 +++++++++++--------- draw/ft_3d_view.c | 78 +++++++++++++++++++++++++++++++++++++++++-- draw/ft_background.c | 15 ++++++++- move/ft_key.c | 10 +++++- move/ft_move.c | 77 +++++++++++++----------------------------- 6 files changed, 147 insertions(+), 74 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3e5eb95..f63800b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,5 +55,8 @@ "C_Cpp_Runner.useLeakSanitizer": false, "C_Cpp_Runner.showCompilationTime": false, "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false +"C_Cpp_Runner.msvcSecureNoWarnings": false, +"files.associations": { + "cmath": "c" +} } \ No newline at end of file diff --git a/cub3d.h b/cub3d.h index eab85b9..d6d5d96 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */ -/* Updated: 2024/01/23 21:07:38 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/25 14:56:20 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,9 +35,9 @@ # define FOVIEW 60 # define DISRAY 1000000 # define DOF 120 -# define WIDTH 1280 +# define WIDTH 1780 # define HEIGHT 720 -# define BOV 0 +# define BOV 500 # define MAX_LINE_LENGTH 100000 typedef enum { @@ -225,8 +225,24 @@ typedef struct s_line_deltas { t_line_params *params; } t_line_deltas; + + +typedef struct s_texture_params { + t_structure_main *w; + int startX; + int endX; + float lineOff; + float lineH; + WallDirection wallDir; + float rx; + float ry; + float disT; +} t_texture_params; + typedef struct s_ray_params { t_structure_main *w; + t_square_params sq; + t_texture_params texture; int r; int tileSize; float rx; @@ -243,18 +259,6 @@ typedef struct s_ray_params { int raywidth; } t_ray_params; -typedef struct s_texture_params { - t_structure_main *w; - int startX; - int endX; - float lineOff; - float lineH; - WallDirection wallDir; - float rx; - float ry; - float disT; -} t_texture_params; - typedef struct s_ray_calc_params { t_structure_main *w; float ra; @@ -384,6 +388,7 @@ void calculate_map(t_structure_map *map_info); void load_wall_textures(t_structure_main *w); void draw_texture(t_texture_params *tex_params); int get_texture_color(t_structure_main *w, WallDirection wallDir, int textureX, int textureY); +void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca); /*3D view*/ void drawray(t_ray_params *ray_params); void draw_background(t_structure_main *w); @@ -396,6 +401,7 @@ void put_pixel_img(t_structure_main *w, int x, int y, int color); void draw_square_raw(t_square_params *params); void draw_line(t_line_params *params); void drawrays2d(t_structure_main *w); +void draw_black_ground(t_ray_params *params); //Ray void calculateverticalray(t_ray_calc_params *params); void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize); diff --git a/draw/ft_3d_view.c b/draw/ft_3d_view.c index 91d3e41..45efe48 100644 --- a/draw/ft_3d_view.c +++ b/draw/ft_3d_view.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */ -/* Updated: 2024/01/23 20:46:34 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/25 14:58:34 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,9 @@ void drawray(t_ray_params *rayparams) { t_line_params lineparams; t_texture_params textureparams; + float olineh; + int deca; + int color; rayparams->start3DHeight = 0; rayparams->max3DHeight = rayparams->w->s_win.height @@ -49,6 +52,7 @@ void drawray(t_ray_params *rayparams) rayparams->lineH = rayparams->max3DHeight; } rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2); + olineh = (rayparams->w->s_map.mapS * rayparams->w->s_win.height) / rayparams->disT; rayparams->backgroundOffsetX = BOV; rayparams->raywidth = rayparams->w->s_win.width / rayparams->numRays; textureparams.startX = rayparams->r * rayparams->raywidth @@ -57,5 +61,75 @@ void drawray(t_ray_params *rayparams) init_texture_params(&textureparams, rayparams); init_line_params(&lineparams, rayparams); draw_line(&lineparams); - draw_texture(&textureparams); + if (olineh > rayparams->w->s_win.height) + deca = olineh - rayparams->w->s_win.height; + else + deca = 0; + //draw_black_ground(rayparams); + if (deca != 0) + draw_yolo(rayparams, &textureparams, deca); + else + draw_texture(&textureparams); +} + +void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca) +{ + int texturewidth; + int textureheight; + int i; + int y; + int x; + float perspectivefactor; + int texturex; + int color; + + texturewidth = tparams->w->s_img.texture_width; + textureheight = tparams->w->s_img.texture_height; + i = 0; + for (y = rparams->lineOff; y < rparams->lineOff + rparams->lineH; y++) { + // La variable perspectiveFactor permet de mapper la texture en tenant compte de la perspective + perspectivefactor = (float)(y - rparams->lineOff) / rparams->lineH; + int textureY = perspectivefactor * (textureheight ); + if (textureY >= textureheight) { + textureY = textureheight - 1; + } + + //for (int x = startX; x < endX; x++) { + x = tparams->startX; + switch (tparams->wallDir) { + case NORTH: + case SOUTH: + // Assurez-vous que rx est normalisé correctement pour le mappage de texture + texturex = (int)(tparams->rx * texturewidth / tparams->w->s_map.mapS) % texturewidth; + break; + case WEST: + case EAST: + // Assurez-vous que ry est normalisé correctement pour le mappage de texture + texturex = (int)(tparams->ry * texturewidth / tparams->w->s_map.mapS) % texturewidth; + break; + } + if (texturex >= texturewidth) { + texturex = texturewidth - 1; + } + //printf("%f %f\n",lineOff, lineOff/lineH); + + + color = get_texture_color(tparams->w, tparams->wallDir, texturex, y); + + + // BLOCK OK MEH + // float ww = ((720+merde)/lineH); + // //printf("%d %d %d\n", t ,td, merde); + // put_pixel_img(w, x, (int)(iii*ww)-merde/2, color); + // iii++; + + int a = tparams->lineOff - deca / 2; + int b = tparams->lineH + (deca /2); + int c = tparams->lineH; + double step = (b - a)/(double)(c - 1); + //printf("%d %d %d\n", t ,td, merde); + put_pixel_img(tparams->w, x, (int)(a + i * step), color); + i++; + //} + } } diff --git a/draw/ft_background.c b/draw/ft_background.c index 25d8151..2114b2e 100644 --- a/draw/ft_background.c +++ b/draw/ft_background.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */ -/* Updated: 2024/01/20 11:18:10 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/25 14:56:59 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,3 +45,16 @@ void draw_background(t_structure_main *w) ground_params.backgroundOffsetX = backgroundoffsetx; draw_sky_ground(&ground_params); } + +void draw_black_ground(t_ray_params *params) +{ + t_square_params square_params; + + square_params.w = params->w; + square_params.y = params->texture.startX; + square_params.x = params->lineOff; + square_params.yo = params->texture.startX + 1; + square_params.xo = params->lineOff + params->lineH ; + square_params.color = 0x000000; + draw_square_raw(&square_params); +} \ No newline at end of file diff --git a/move/ft_key.c b/move/ft_key.c index 3358d80..51921cd 100644 --- a/move/ft_key.c +++ b/move/ft_key.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:17:56 by fgras-ca #+# #+# */ -/* Updated: 2024/01/12 20:28:07 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/25 12:41:41 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,6 +77,14 @@ int deal_key(int key, t_structure_main *w) else if (key == 65362 || key == 65364 || key == 114 || key == 102) { } + else if (key == 101) //e door + { + printf("Touche 101\n"); + if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] == '1') + w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] = '2'; + else if (w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] == '2') + w->s_map.map[(int)((w->s_player.py + sin(w->s_player.pa) * 7)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + cos(w->s_player.pa) * 7)/w->s_map.mapS)] = '1'; + } else { handle_movement_keys(key, w); diff --git a/move/ft_move.c b/move/ft_move.c index 0041eff..b60e740 100644 --- a/move/ft_move.c +++ b/move/ft_move.c @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 14:08:25 by fgras-ca #+# #+# */ -/* Updated: 2024/01/11 20:35:09 by fgras-ca ### ########.fr */ +/* Updated: 2024/01/25 15:09:55 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,20 +18,12 @@ void move_forward(t_structure_main *w, int key) int future_px; int future_py; - if (key != 119) - return ; - params.future_px = &future_px; - params.future_py = &future_py; - params.pdx = w->s_player.pdx; - params.pdy = w->s_player.pdy; - params.collisionBuffer = COLBUF; - params.px = w->s_player.px; - params.py = w->s_player.py; - calculate_future_position(¶ms); - if (check_collision(w, future_px, future_py)) +if (key == 119 ) { - w->s_player.px += w->s_player.pdx; - w->s_player.py += w->s_player.pdy; + if (w->s_map.map[(int)((w->s_player.py)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + (cos(w->s_player.pa) * w->s_map.mapS))/w->s_map.mapS)]=='0') + w->s_player.px += cos(w->s_player.pa) * w->s_map.mapS; + if (w->s_map.map[(int)((w->s_player.py + (sin(w->s_player.pa) * w->s_map.mapS))/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px)/w->s_map.mapS)]=='0') + w->s_player.py += sin(w->s_player.pa) * w->s_map.mapS; } } @@ -41,20 +33,12 @@ void move_backward(t_structure_main *w, int key) int future_px; int future_py; - if (key != 115) - return ; - params.future_px = &future_px; - params.future_py = &future_py; - params.pdx = -w->s_player.pdx; - params.pdy = -w->s_player.pdy; - params.collisionBuffer = COLBUF; - params.px = w->s_player.px; - params.py = w->s_player.py; - calculate_future_position(¶ms); - if (check_collision(w, future_px, future_py)) + if (key == 115 ) { - w->s_player.px -= w->s_player.pdx; - w->s_player.py -= w->s_player.pdy; + if (w->s_map.map[(int)((w->s_player.py)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + (cos(w->s_player.pa + (PI)) * w->s_map.mapS))/w->s_map.mapS)]=='0') + w->s_player.px += cos(w->s_player.pa + (PI)) * w->s_map.mapS; + if (w->s_map.map[(int)((w->s_player.py + (sin(w->s_player.pa + (PI)) * w->s_map.mapS))/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px)/w->s_map.mapS)]=='0') + w->s_player.py += sin(w->s_player.pa + (PI)) * w->s_map.mapS; } } @@ -64,20 +48,12 @@ void move_right(t_structure_main *w, int key) int future_px; int future_py; - if (key != 100) - return ; - params.future_px = &future_px; - params.future_py = &future_py; - params.pa = w->s_player.pa; - params.collisionBuffer = COLBUF; - params.px = w->s_player.px; - params.py = w->s_player.py; - params.direction = 'd'; - calculate_future_position_right_left(¶ms); - if (check_collision(w, future_px, future_py)) - { - w->s_player.px = future_px; - w->s_player.py = future_py; + if (key == 100 ) + { + if (w->s_map.map[(int)((w->s_player.py)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + (cos(w->s_player.pa + (PI/2)) * w->s_map.mapS))/w->s_map.mapS)]=='0') + w->s_player.px += cos(w->s_player.pa + (PI/2)) * w->s_map.mapS; + if (w->s_map.map[(int)((w->s_player.py + (sin(w->s_player.pa + (PI/2)) * w->s_map.mapS))/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px)/w->s_map.mapS)]=='0') + w->s_player.py += sin(w->s_player.pa + (PI/2)) * w->s_map.mapS; } } @@ -87,23 +63,16 @@ void move_left(t_structure_main *w, int key) int future_px; int future_py; - if (key != 97) - return ; - params.future_px = &future_px; - params.future_py = &future_py; - params.pa = w->s_player.pa; - params.collisionBuffer = COLBUF; - params.px = w->s_player.px; - params.py = w->s_player.py; - params.direction = 'a'; - calculate_future_position_right_left(¶ms); - if (check_collision(w, future_px, future_py)) + if (key == 97) { - w->s_player.px = future_px; - w->s_player.py = future_py; + if (w->s_map.map[(int)((w->s_player.py)/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px + (cos(w->s_player.pa + (3*(PI/2))) * w->s_map.mapS))/w->s_map.mapS)]=='0') + w->s_player.px += cos(w->s_player.pa + (3*(PI/2))) * w->s_map.mapS; + if (w->s_map.map[(int)((w->s_player.py + (sin(w->s_player.pa + (3*(PI/2))) * w->s_map.mapS))/w->s_map.mapS) * w->s_map.mapX + (int)((w->s_player.px)/w->s_map.mapS)]=='0') + w->s_player.py += sin(w->s_player.pa + (3*(PI/2))) * w->s_map.mapS; } } + void move(int key, t_structure_main *w) { move_forward(w, key);