adding the correction helped by maiboyer and bgoulard

This commit is contained in:
Raphael 2024-11-18 16:27:02 +01:00
commit 761178fcae
6 changed files with 249 additions and 13 deletions

View file

@ -2,6 +2,7 @@ CompileFlags:
Add: Add:
- "-Werror -Wextra -Wall" - "-Werror -Wextra -Wall"
- "-I/opt/X11/include" - "-I/opt/X11/include"
- "-I/nix/store/h5wikn5ggl90bi4v939cf20aq03ca5s5-clang-16.0.6-lib/lib/clang/16/include/"
- "-I/home/raphael/Documents/42_cursus/circle4/Cub3D/includes" - "-I/home/raphael/Documents/42_cursus/circle4/Cub3D/includes"
- "-I/home/raphael/Documents/42_cursus/circle4/Cub3D/includes/include" - "-I/home/raphael/Documents/42_cursus/circle4/Cub3D/includes/include"
- "-I/Users/raphael/Documents/42_cursus/circle_4/Cub3D/includes" - "-I/Users/raphael/Documents/42_cursus/circle_4/Cub3D/includes"

3
.gitignore vendored
View file

@ -1,6 +1,9 @@
.direnv/ .direnv/
Cub3D Cub3D
build/ build/
.clangd
.clang*
to_do* to_do*
.cache/ .cache/
# Prerequisites # Prerequisites

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/11/18 14:28:55 by rparodi ### ########.fr # # Updated: 2024/11/18 14:54:37 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -42,19 +42,18 @@ MLXFLAGS = -L$(MLX_DIR) -lmlx -L/opt/X11/lib -lX11 -lXext -lXrender -lXrandr -lX
LDFLAGS += $(MLXFLAGS) LDFLAGS += $(MLXFLAGS)
SRC =\ SRC =\
raycast/frame_update.c \
mlx_layer/mlx_init.c \ mlx_layer/mlx_init.c \
parsing/blank_for_raph.c \
parsing/arguments.c \ parsing/arguments.c \
parsing/map.c \ parsing/map.c \
parsing/blank_for_raph.c \
raycast/frame_update.c \
sources/cleanups.c \
sources/error.c \
sources/main.c \ sources/main.c \
sources/cleanups.c \
sources/options.c \ sources/options.c \
sources/rgb_to_color.c \ sources/rgb_to_color.c \
sources/error.c \
sources/options_impl.c sources/options_impl.c
# raycast/rc_utils.c
# Objects # Objects
OBJDIRNAME = ./build OBJDIRNAME = ./build
@ -143,6 +142,17 @@ footer:
@printf "$(GOLD) '\"' '\"'$(END)\n" @printf "$(GOLD) '\"' '\"'$(END)\n"
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
clangd:
@echo -en \
"CompileFlags:\n" \
" Add:\n" \
" - \"-Wall -Wextra -Werror\"\n" \
" - \"-I/opt/X11/include\"\n" \
" - \"-I"$(shell pwd)"/includes\"\n" \
" - \"-I"$(shell pwd)"/includes/include\"\n" \
" - \"-xc\"\n" \
> .clangd
# Phony targets # Phony targets
.PHONY: all bonus clean fclean re .PHONY: all bonus clean fclean re

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */ /* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */
/* Updated: 2024/11/12 15:08:08 by rparodi ### ########.fr */ /* Updated: 2024/11/18 15:41:34 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,29 @@
#include "mlx_functions.h" #include "mlx_functions.h"
#include "raycast.h" #include "raycast.h"
double cub_convert_rad_to_deg(double degrees) /**
* @brief convert a angle in degrees to radian
*
* @param degrees the angle in degrees
* @return the angle in radian
*/
double cub_convert_deg_to_rad(double degrees)
{ {
return (degrees * (M_PI / 180.0)); return (degrees * (M_PI / 180.0));
} }
/**
* @brief Launches a ray for raycasting to determine the distance to the first wall.
*
* This function calculates the distance of a ray cast in a specified angle
* until it either hits a wall or reaches the maximum range.
*
* @param info A pointer to the `t_info` structure containing the map and other relevant data.
* @param angle The angle of the ray being cast, in radians.
*
* @return The distance from the starting position to the first wall hit.
* If no wall is hit within `MAX_RANGE`, the function returns `MAX_RANGE`.
*/
double rc_launch(t_info *info, double angle) double rc_launch(t_info *info, double angle)
{ {
double distance; double distance;
@ -33,11 +51,11 @@ double rc_launch(t_info *info, double angle)
rayon.y = 0; rayon.y = 0;
while (distance < MAX_RANGE) while (distance < MAX_RANGE)
{ {
rayon.x += direction.x * STEP_SIZE; rayon.x = direction.x * distance;
rayon.y += direction.y * STEP_SIZE; rayon.y = direction.y * distance;
distance += STEP_SIZE; if (info->map.map[info->map.fraw[(int)rayon.x][(int)rayon.y]] == WALL)
if (info->map.map(info->map.fraw[(int)rayon.x][(int)rayon.y]) == WALL)
return (distance); return (distance);
distance += STEP_SIZE;
} }
return (MAX_RANGE); return (MAX_RANGE);
} }
@ -61,7 +79,8 @@ void shelves_launch(t_info *info, double spacing, double focal, int width)
angle = 0; angle = 0;
while (x < width) while (x < width)
{ {
angle = info->player.view + atan((spacing / 2 - x * spacing / (width - 1)) / focal); angle = info->player.view + atan(\
(spacing / 2 - x * spacing / (width - 1)) / focal);
rc_launch(info, angle); rc_launch(info, angle);
x++; x++;
} }

154
textures/a.xpm Normal file
View file

@ -0,0 +1,154 @@
/* XPM */
static char *_cb59dce4f574e3bd6a1e2f025c0312agi1mGDihwOOx8j7A[] = {
/* columns rows colors chars-per-pixel */
"32 32 116 2 ",
" c #100F10",
". c #161515",
"X c #191717",
"o c #191718",
"O c #1E1C1C",
"+ c #211E1E",
"@ c #252222",
"# c #292626",
"$ c #2D2B2B",
"% c #322E2E",
"& c #3A2F2E",
"* c #36302F",
"= c #3C312E",
"- c #342F30",
"; c #353131",
": c #3A3434",
"> c #3D3836",
", c #3C3738",
"< c #3E3A3A",
"1 c #43332F",
"2 c #433534",
"3 c #4C3633",
"4 c #433A36",
"5 c #4C3937",
"6 c #433C3B",
"7 c #4B3D3B",
"8 c #503835",
"9 c #523D3C",
"0 c #46413E",
"q c #4B433D",
"w c #524433",
"e c #55443B",
"r c #453F41",
"t c #563D40",
"y c #474141",
"u c #4B4442",
"i c #4E4845",
"p c #4F4949",
"a c #544442",
"s c #584644",
"d c #534A42",
"f c #5A4A46",
"g c #554D4B",
"h c #5C4D4C",
"j c #545146",
"k c #56514C",
"l c #5B524D",
"z c #5D5552",
"x c #5F5A53",
"c c #614D46",
"v c #61534D",
"b c #625D4C",
"n c #625553",
"m c #635A53",
"M c #655B59",
"N c #695D5A",
"B c #636052",
"V c #696354",
"C c #6E6852",
"Z c #66615A",
"A c #6B625D",
"S c #6D695B",
"D c #70675F",
"F c #736A5D",
"G c #6C6360",
"H c #6B6463",
"J c #6F6563",
"K c #6D6865",
"L c #706763",
"P c #726766",
"I c #716A62",
"U c #726A63",
"Y c #756D63",
"T c #746A64",
"R c #786B66",
"E c #786D66",
"W c #716A68",
"Q c #746B69",
"! c #776E6C",
"~ c #7B6F69",
"^ c #796E6A",
"/ c #786E6C",
"( c #767161",
") c #7B7366",
"_ c #7C7367",
"` c #7E7A66",
"' c #767069",
"] c #79706B",
"[ c #7C716B",
"{ c #7F7868",
"} c #7F796C",
"| c #7E7572",
" . c #807D6D",
".. c #807776",
"X. c #837B70",
"o. c #847972",
"O. c #857C72",
"+. c #847B79",
"@. c #8A7F78",
"#. c #868172",
"$. c #898171",
"%. c #8C8673",
"&. c #8A8174",
"*. c #8D8870",
"=. c #8D867B",
"-. c #928B7C",
";. c #938C7D",
":. c #968F7F",
">. c #96907B",
",. c #98907F",
"<. c #8D8681",
"1. c #938C80",
"2. c #948C88",
"3. c #979081",
"4. c #999087",
"5. c #A29C81",
/* pixels */
"V : H + Z m % - $ $ ' ! # -.$ k g x $ $ 2 &.$ % % 2 >.g ; z $ A ",
"&.d % $ 1 F 5.@ X.1 f [ % % % : z Y % ; O.L ] # @ N a T ; % , :.",
"A ; $ 6 = C $ , % , ; a $ I %.% 7 % o + 1 Z = 1 O % $ < @ & v L ",
"O ; T # 3 X @ 2 l z % % % g p % $ % A l $ ; : M t % = f G % # # ",
"e ; ; 6 > k $ & $ % @ % % : 4 % 0 % > T 4 $ % a % @ % $ 9 N $ -.",
"J % / z ~ 3.k , , f Z k e 3 # % O.d % % % } 6 : ; I | l $ , $ l ",
"N 8 2 2 3 O.m 6 , % E % = % 5 L E S % % 7 N J k = > u [ & D $ R ",
"= % + # ; % 2 % $ 7 l $ % : % : > $ $ $ , 2 q 4 % % % , , 4 % * ",
"$ h Z A $ % % 7 % : : $ A z q ; ; : ] I % ; $ ; D N 0 $ | Z z p ",
"M l g X.< 7 7 W u < % ; n { m , > > i > ; j % m q d g O 7 g g $ ",
"6 , n @ $ z : 2 % m .d % 9 % , l > ; ; m M @ : % , x @ $ % $ ; ",
"L 4 $ ; I <.u ; # A P A $ % # x 0 , % # z X.x < $ m P 9 = _ < g ",
"A 7 , + @.M & 9 % ; $ : % > % ; # ; % : n N n ; k % $ % G H % u ",
"$ % O.; $ $ . ` l % # $ # $ =.I 7 <.2.A ; % $ $ 6 x : , V Y > 6 ",
"2 ] [ s $ 9 @ E { m A O ] f A ; l s +.@ F I $ | / O.% % 2 0 $ : ",
"% % f a % $ ; A E = % # 3 i > $ $ , ..+ O g ; ~ N $ : : % $ 4 k ",
"$.j , < & #.% 6 : $ ;.a % 2 % g *.; g ; c v , $ : 6 T ~ % u ; ( ",
"g Z # : O.L ] # 6 N a T # % , D p d % % = F ` ; Z = f [ , % $ u ",
"v % @ # 1 Z = 1 $ % $ ; 6 % v l A @ @ ; & j $ ; # $ ; a . I S : ",
"# $ g l $ $ , M t % = f G , ; $ ; # z , 2 6 # 7 L ~ ; 7 % u 6 ; ",
") % 0 z e , # a % ; % # 9 N $ -.n , < 6 > k $ & $ % $ # % < 4 $ ",
": : ; $ % } b d , I | l $ $ # l W % / z ~ 3.S ; * f #.S e 3 ; * ",
"0 6 % p s N J k = > J [ & D @ R N 8 3 9 3 O.m ; # % E % 2 % 9 A ",
"v $ $ $ , : 4 : % * ; % 6 4 % % % % O < % % 2 % % > D @ ; q % z ",
"# 2 ] z % , % # l N 0 # | +.4.p % q O.A $ r # a ; w = , A g m o ",
"( i 0 c 7 j % ] l 6 , % 2 G N % > J A o.# 7 a W Q A + n k [ % ",
"k M 9 @ S M # 2 $ 6 ] , # % % % % % n # # Q * 2 % d .d < 9 % ; ",
"u u # $ Z 1.Z % % m P 9 = _ @ A x % $ ; I <.L $ $ g P ~ % % y [ ",
"p $ % : u g a $ D % $ % G H % A y : ; % @.M 2 9 $ % # 3 @ f ; $ ",
"7 K z y % # ; % 6 ] 7 , V ,.d 6 % % O.% $ ; % B ; % y ; ; $ =.I ",
"J 7 g < u I $ M x O.% # 7 Z ; 1 9 ] [ s $ 2 # 6 { i q O ] f A , ",
"u ; .., ; A u ~ N $ ; $ + $ 1 l % % f a , % # A z % % $ 3 n 9 % "
};

49
textures/b.xpm Normal file
View file

@ -0,0 +1,49 @@
/* XPM */
static char *_947bb94b4e04fd3d8b6e97faaaaa774DMhsGHANfMg9UIKL[] = {
/* columns rows colors chars-per-pixel */
"32 32 11 1 ",
" c #422816",
". c #4E371C",
"X c #584529",
"o c #655131",
"O c #665232",
"+ c #655339",
"@ c #705C41",
"# c #756349",
"$ c #796442",
"% c #816D54",
"& c #948066",
/* pixels */
"##++XX#@###%@%%O@X++.X#@@XX+++++",
"#@o+X #%##@O+X@@++XX+++@+@@++#%",
"#%#OO.+XXo+%#&%##.X.X##%@@@++##O",
"oooXXXX. +@@OX#.X##+X+..+#@O@X++",
"+OX@O@%%##@XX++OooXXX.X+XXX+@OXX",
"$X#O@.X@XXX.+.XX..+XX+XX+@+X....",
"#+%%++X+@@@X++#+X..+@+#####%#$#@",
"+X+X...XX@#.+#X@@+.++#&%@@@#+.++",
"X+XXX+XXXX@#%.@##@@.@++++#X.X.@%",
".+XX..X+@@++..#@++...X.XXX+@+XX+",
"X+X@#%+X.X++#+X XX++++...++X+X+",
"X..++@.XXXXOO@@@&##%@@+...++.++X",
"+@+X...#@#%@+@@+@#+X@#++@X.+@#++",
"X.XXX++&+@++X+.X+++X+XX###@@@X+X",
" .#++###+%#@+X#oXX+@@#@+@##+##..",
".%@##XOX%#@.@@X..X.X@@+@@@@@XX++",
"#@#X.XXXX+++.XX@#+++X XXX#+X+X+&",
"X@#%+X@XX.XX++O##@+..X++@#@%%++@",
"##@##.@+XXXX.XX@XX+X..+XX@#%%#@X",
"..X##.+X+@XX++@++X++.+X++++X+++.",
"+#+.XX+XX#+%&#@@@#X XX@XX.XX# .+",
"XX+X.+%%%%@@XX++%+%&%#++.X+X@.XX",
"# ++@+@#+XX.+X##+X##+@++@+@@#%",
"##X+X+@oX@....XXXX+o+#@@@++ X#X@",
"%+@XX..XX.X#..@X+X++#+XX+.@X+X%@",
"+X.X.X+++#XX+XX@@@@#+++.+++@+%OX",
"XOX+@X+@+@@+++X+++X+@X+++@X@X+X ",
"@##&@#++++@+++@X+. ..++@@.X++X+%",
"@#@#X+@++X@+XXXX++@+@XXX.X+@@@@%",
"XXOXXX...+@@#@@X@@#@#@&...X@#@.X",
"XX@...+@%&#XX@XX++@ .@@#@@+@X.X+",
"%@.@%@@+++@o++++X+X+@++XXO@@@%#&"
};