mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2025-12-16 05:57:58 +01:00
versiontexturecouleur
This commit is contained in:
parent
84c17810af
commit
ffca051a01
37
Makefile
37
Makefile
@ -6,17 +6,31 @@
|
|||||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
|
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
|
||||||
# Updated: 2024/01/14 21:30:03 by fgras-ca ### ########.fr #
|
# Updated: 2024/01/23 17:36:22 by fgras-ca ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
LOGO = @echo "🅹🅾🅷🅽 🅰🅽🅳 🅻🅰🅳🅴🅱🅴🆉🅴"
|
||||||
|
|
||||||
|
RST = \033[0m
|
||||||
|
GRAY = \033[0;90m
|
||||||
|
RED = \033[0;91m
|
||||||
|
GREEN = \033[0;92m
|
||||||
|
YELLOW = \033[0;93m
|
||||||
|
BLUE = \033[0;94m
|
||||||
|
MAGENTA = \033[0;95m
|
||||||
|
CYAN = \033[0;96m
|
||||||
|
WHITE = \033[0;97m
|
||||||
|
ORANGE = \033[38;5;214m
|
||||||
|
|
||||||
NAME = cub3d
|
NAME = cub3d
|
||||||
|
LIBFT = libft.a
|
||||||
|
|
||||||
SRC = main.c \
|
SRC = main.c \
|
||||||
./utils/ft_utils_gnl.c \
|
./utils/ft_utils_gnl.c \
|
||||||
./utils/ft_utils_split.c \
|
./utils/ft_utils_split.c \
|
||||||
./utils/ft_utils_str_1.c \
|
|
||||||
./utils/ft_utils_convert.c \
|
./utils/ft_utils_convert.c \
|
||||||
|
./utils/ft_utils_str_1.c \
|
||||||
./parsing/ft_map_check.c \
|
./parsing/ft_map_check.c \
|
||||||
./parsing/ft_read_map.c \
|
./parsing/ft_read_map.c \
|
||||||
./parsing/ft_map_dimensions.c \
|
./parsing/ft_map_dimensions.c \
|
||||||
@ -38,8 +52,13 @@ SRC = main.c \
|
|||||||
./window/ft_map.c \
|
./window/ft_map.c \
|
||||||
./draw/ft_load_textures.c \
|
./draw/ft_load_textures.c \
|
||||||
./window/ft_rescale.c \
|
./window/ft_rescale.c \
|
||||||
|
./window/ft_refresh_window.c \
|
||||||
|
./parsing/ft_find_map_start.c \
|
||||||
|
./parsing/ft_textures_and_colors.c \
|
||||||
|
|
||||||
|
SRC_DIR_LIBFT = libft/
|
||||||
|
|
||||||
|
SRC_LIBFT = $(addprefix $(SRC_DIR_LIBFT), $(LIBFT))
|
||||||
|
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
@ -47,16 +66,24 @@ FLAG = cc -Wall -Wextra -Werror -g
|
|||||||
|
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
|
||||||
$(FLAG) -Iinclude $(OBJ) -Llib -lmlx -lXext -lX11 -lm -o $(NAME)
|
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@echo "$(RED)Compilation cub3D... $(RST)"
|
||||||
|
@$(FLAG) -Iinclude $(OBJ) -Llib -lmlx -lXext -lX11 -lm -o $(NAME)
|
||||||
|
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./cub3d" for execute the program!!$(RST)"
|
||||||
|
$(LOGO)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@echo "$(RED)Deleating files objects... $(RST)"
|
||||||
$(RM) $(OBJ)
|
$(RM) $(OBJ)
|
||||||
|
@echo "$(GREEN)files deleted!! $(RST)"
|
||||||
|
$(LOGO)
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
|
@echo "$(RED)Delete program name... $(RST)"
|
||||||
$(RM) $(NAME)
|
$(RM) $(NAME)
|
||||||
|
@echo "$(GREEN)File program deleted!! $(RST)"
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
Désolé j'ai pas push avant j'ai du recommencer 2 fois il reste juste les fonctions du main et de draw/ft_2d_view.c a mettre a la norme ça a été plus compliqué que je le pensai pour tout mettre à la norme.
|
|
||||||
Une vrai galère, il me reste également a implémenter le personnage et les textures dans le .cub mais bon ça devrait aller plus vite maintenant
|
|
||||||
Ya par moment des problèmes de collision qu'il va falloir régler mais bon ça devrai pas être trop
|
|
||||||
Je serai là lundi aprés-midi à demain
|
|
||||||
103
cub3d.h
103
cub3d.h
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 23:09:44 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/16 16:50:38 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -38,7 +38,7 @@
|
|||||||
# define WIDTH 1780
|
# define WIDTH 1780
|
||||||
# define HEIGHT 720
|
# define HEIGHT 720
|
||||||
# define BOV 500
|
# define BOV 500
|
||||||
|
# define MAX_LINE_LENGTH 100000
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NORTH,
|
NORTH,
|
||||||
SOUTH,
|
SOUTH,
|
||||||
@ -116,6 +116,15 @@ typedef struct s_struture_windows
|
|||||||
int width;
|
int width;
|
||||||
} t_structure_windows;
|
} t_structure_windows;
|
||||||
|
|
||||||
|
typedef struct s_texture
|
||||||
|
{
|
||||||
|
char *north;
|
||||||
|
char *south;
|
||||||
|
char *west;
|
||||||
|
char *east;
|
||||||
|
unsigned int floor_color;
|
||||||
|
unsigned int ceil_color;
|
||||||
|
} t_texture;
|
||||||
typedef struct s_structure_main
|
typedef struct s_structure_main
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -126,6 +135,7 @@ typedef struct s_structure_main
|
|||||||
t_structure_img s_img;
|
t_structure_img s_img;
|
||||||
t_structure_map s_map;
|
t_structure_map s_map;
|
||||||
t_structure_player s_player;
|
t_structure_player s_player;
|
||||||
|
t_texture *t;
|
||||||
} t_structure_main;
|
} t_structure_main;
|
||||||
|
|
||||||
typedef struct s_res_params {
|
typedef struct s_res_params {
|
||||||
@ -259,19 +269,86 @@ typedef struct s_texture_data
|
|||||||
int endian;
|
int endian;
|
||||||
} t_texture_data;
|
} t_texture_data;
|
||||||
|
|
||||||
|
typedef struct s_init_params {
|
||||||
|
t_structure_main *w;
|
||||||
|
int tilesize;
|
||||||
|
int numrays;
|
||||||
|
float FOV;
|
||||||
|
float DR;
|
||||||
|
} t_init_params;
|
||||||
|
|
||||||
|
typedef struct s_ray_properties {
|
||||||
|
float disH;
|
||||||
|
float disV;
|
||||||
|
WallDirection hwalldir;
|
||||||
|
WallDirection vwalldir;
|
||||||
|
float hx;
|
||||||
|
float hy;
|
||||||
|
float vx;
|
||||||
|
float vy;
|
||||||
|
} t_ray_properties;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int tilesize;
|
||||||
|
int numrays;
|
||||||
|
float FOV;
|
||||||
|
float DR;
|
||||||
|
float ra;
|
||||||
|
} t_base_params;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float disH;
|
||||||
|
float disV;
|
||||||
|
float disT;
|
||||||
|
float hx;
|
||||||
|
float hy;
|
||||||
|
float vx;
|
||||||
|
float vy;
|
||||||
|
WallDirection hwalldir;
|
||||||
|
WallDirection vwalldir;
|
||||||
|
} t_ray_state;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
t_structure_main *w;
|
||||||
|
int r;
|
||||||
|
int color;
|
||||||
|
} t_ray_calc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
t_base_params base_params;
|
||||||
|
t_ray_state ray_state;
|
||||||
|
t_ray_calc ray_calc;
|
||||||
|
t_ray_params rayparams;
|
||||||
|
t_ray_calc_params hrayparams;
|
||||||
|
t_ray_calc_params vrayparams;
|
||||||
|
} t_drawrays2d_params;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int jkl;
|
||||||
|
int yui;
|
||||||
|
} t_state;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
t_structure_main *w;
|
||||||
|
t_state state;
|
||||||
|
} t_global_struct;
|
||||||
|
|
||||||
//ft_utils_split.c 5 / 5
|
//ft_utils_split.c 5 / 5
|
||||||
char **ft_split(char const *s, char c);
|
char **ft_split(char const *s, char c);
|
||||||
//ft_utils_gnl.c 4 / 5
|
//ft_utils_gnl.c 4 / 5
|
||||||
char *get_next_line(int fd);
|
char *get_next_line(int fd);
|
||||||
//ft_utils_str_1.c
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
char *ft_strdup(const char *src);
|
|
||||||
char *ft_strjoin(char *left_str, char *buff);
|
|
||||||
char *ft_strchr(const char *s, int c);
|
|
||||||
/*ft_key.c 3/5*/
|
/*ft_key.c 3/5*/
|
||||||
int *kill_prog(t_structure_main *w);
|
int *kill_prog(t_structure_main *w);
|
||||||
void move(int key, t_structure_main *w);
|
void move(int key, t_structure_main *w);
|
||||||
int deal_key(int key, t_structure_main *w);
|
int deal_key(int key, t_structure_main *w);
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
char *ft_strdup(const char *src);
|
||||||
|
char *ft_strjoin(char *left_str, char *buff);
|
||||||
|
char *ft_strchr(const char *s, int c);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memset(void *s, int c, size_t n);
|
||||||
/*collision*/
|
/*collision*/
|
||||||
void calculate_future_position(t_position_params *params);
|
void calculate_future_position(t_position_params *params);
|
||||||
int check_collision(t_structure_main *w, int future_px, int future_py);
|
int check_collision(t_structure_main *w, int future_px, int future_py);
|
||||||
@ -279,9 +356,8 @@ void calculate_future_position_right_left(t_position_params *params);
|
|||||||
//ft_utils_convert.c 1/5
|
//ft_utils_convert.c 1/5
|
||||||
char *ft_itoa(int nb);
|
char *ft_itoa(int nb);
|
||||||
/*parsing*/
|
/*parsing*/
|
||||||
char *read_map(const char* filename, int* length);
|
|
||||||
int is_map_closed(char* map, int width, int height);
|
int is_map_closed(char* map, int width, int height);
|
||||||
bool parse_map(const char* filename, t_structure_map *map_info);
|
bool parse_map(const char *map_content, int length, t_structure_map *map_info);
|
||||||
int check_borders(char *map, int maxWidth, int height);
|
int check_borders(char *map, int maxWidth, int height);
|
||||||
int check_interior(char *map, int maxWidth, int height);
|
int check_interior(char *map, int maxWidth, int height);
|
||||||
void exit_error(t_structure_main *w);
|
void exit_error(t_structure_main *w);
|
||||||
@ -290,6 +366,12 @@ void process_character(t_map_params *params, int *i);
|
|||||||
void get_map_dimensions(t_map_params *params);
|
void get_map_dimensions(t_map_params *params);
|
||||||
void fill_map_space(t_structure_map *map_info, int maxWidth, int height);
|
void fill_map_space(t_structure_map *map_info, int maxWidth, int height);
|
||||||
void copy_map_data(t_map_params *params);
|
void copy_map_data(t_map_params *params);
|
||||||
|
bool load_cub_file(const char *filename, t_texture *textures, t_structure_map *map_info);
|
||||||
|
bool parse_texture_line(const char *line, t_texture *textures);
|
||||||
|
bool handle_map(int fd, char **map_buffer, int *map_length);
|
||||||
|
bool parse_color_line(const char *line, unsigned int *color);
|
||||||
|
bool is_valid_texture(const char *line);
|
||||||
|
bool handle_textures(int fd, t_texture *textures);
|
||||||
/*textures*/
|
/*textures*/
|
||||||
void load_wall_textures(t_structure_main *w);
|
void load_wall_textures(t_structure_main *w);
|
||||||
void draw_texture(t_texture_params *tex_params);
|
void draw_texture(t_texture_params *tex_params);
|
||||||
@ -305,7 +387,7 @@ void draw_map(t_structure_main *w);
|
|||||||
void put_pixel_img(t_structure_main *w, int x, int y, int color);
|
void put_pixel_img(t_structure_main *w, int x, int y, int color);
|
||||||
void draw_square_raw(t_square_params *params);
|
void draw_square_raw(t_square_params *params);
|
||||||
void draw_line(t_line_params *params);
|
void draw_line(t_line_params *params);
|
||||||
void drawRays2D(t_structure_main *w);
|
void drawrays2d(t_structure_main *w);
|
||||||
//Ray
|
//Ray
|
||||||
void calculateverticalray(t_ray_calc_params *params);
|
void calculateverticalray(t_ray_calc_params *params);
|
||||||
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize);
|
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize);
|
||||||
@ -316,5 +398,6 @@ float dist(float ax, float ay, float bx, float by);
|
|||||||
void init_windows(t_structure_main *w);
|
void init_windows(t_structure_main *w);
|
||||||
void init_player(t_structure_main *w);
|
void init_player(t_structure_main *w);
|
||||||
void init_mlx_and_window(t_structure_main *w);
|
void init_mlx_and_window(t_structure_main *w);
|
||||||
|
void sleep_mouse(t_global_struct *global_struct);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -6,84 +6,89 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 23:34:45 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/17 21:47:17 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../cub3d.h"
|
#include "../cub3d.h"
|
||||||
|
|
||||||
void drawRays2D(t_structure_main *w)
|
float correctfisheye(float distance, float ra, float playerAngle)
|
||||||
{
|
{
|
||||||
int r;
|
float ca;
|
||||||
int color;
|
|
||||||
int tilesize;
|
|
||||||
int numrays;
|
|
||||||
float ra;
|
|
||||||
float disH;
|
|
||||||
float disV;
|
|
||||||
float disT;
|
|
||||||
float hx;
|
|
||||||
float hy;
|
|
||||||
float vx;
|
|
||||||
float vy;
|
|
||||||
float FOV;
|
|
||||||
float DR;
|
|
||||||
WallDirection hwalldir;
|
|
||||||
WallDirection vwalldir;
|
|
||||||
t_ray_params rayparams;
|
|
||||||
t_ray_calc_params hrayparams;
|
|
||||||
t_ray_calc_params vrayparams;
|
|
||||||
|
|
||||||
tilesize = w->s_map.mapS;
|
ca = playerAngle - ra;
|
||||||
numrays = NUMRAY;
|
if (ca < 0)
|
||||||
FOV = FOVIEW * (PI / 180);
|
ca += 2 * PI;
|
||||||
DR = FOV / numrays;
|
if (ca > 2 * PI)
|
||||||
|
ca -= 2 * PI;
|
||||||
|
return (distance * cos(ca));
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_base_params(t_base_params *params, t_structure_main *w)
|
||||||
|
{
|
||||||
|
params->tilesize = w->s_map.mapS;
|
||||||
|
params->numrays = NUMRAY;
|
||||||
|
params->FOV = FOVIEW * (PI / 180);
|
||||||
|
params->DR = params->FOV / params->numrays;
|
||||||
|
params->ra = w->s_player.pa - (params->FOV / 2);
|
||||||
|
printf("DEBUG: Initialisation des paramètres de base\n");
|
||||||
|
printf("DEBUG: tilesize (taille de la tuile) = %d\n", w->s_map.mapS);
|
||||||
|
printf("DEBUG: numrays (nombre de rayons) = %d\n", NUMRAY);
|
||||||
|
printf("DEBUG: FOV (champ de vision) = %f\n", FOVIEW * (PI / 180));
|
||||||
|
printf("DEBUG: DR (delta rayon) = %f\n", params->FOV / params->numrays);
|
||||||
|
printf("DEBUG: ra (rayon actuel) = %f\n", w->s_player.pa - (params->FOV / 2));
|
||||||
draw_background(w);
|
draw_background(w);
|
||||||
|
}
|
||||||
|
|
||||||
ra = w->s_player.pa - (FOV / 2);
|
void calculate_ray(t_base_params *base, t_ray_state *state,
|
||||||
r = 0;
|
t_ray_calc *calc, t_ray_params *rayparams)
|
||||||
while (r++ < numrays)
|
|
||||||
{
|
{
|
||||||
ra = fmod(ra + 2 * PI, 2 * PI);
|
if (state->disH < state->disV)
|
||||||
|
|
||||||
hrayparams.w = w;
|
|
||||||
hrayparams.ra = ra;
|
|
||||||
hrayparams.disRay = &disH;
|
|
||||||
hrayparams.rx = &hx;
|
|
||||||
hrayparams.ry = &hy;
|
|
||||||
hrayparams.wallDir = &hwalldir;
|
|
||||||
calculatehorizontalray(&hrayparams);
|
|
||||||
vrayparams.w = w;
|
|
||||||
vrayparams.ra = ra;
|
|
||||||
vrayparams.disRay = &disV;
|
|
||||||
vrayparams.rx = &vx;
|
|
||||||
vrayparams.ry = &vy;
|
|
||||||
vrayparams.wallDir = &vwalldir;
|
|
||||||
calculateverticalray(&vrayparams);
|
|
||||||
if (disH < disV)
|
|
||||||
{
|
{
|
||||||
disT = disH;
|
rayparams->disT = state->disH;
|
||||||
color = 0xFF0000;
|
calc->color = 0xFF0000;
|
||||||
rayparams.wallDir = hwalldir;
|
rayparams->wallDir = state->hwalldir;
|
||||||
rayparams.rx = hx;
|
rayparams->rx = state->hx;
|
||||||
rayparams.ry = hy;
|
rayparams->ry = state->hy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
disT = disV;
|
rayparams->disT = state->disV;
|
||||||
color = 0x00FF00;
|
calc->color = 0x00FF00;
|
||||||
rayparams.wallDir = vwalldir;
|
rayparams->wallDir = state->vwalldir;
|
||||||
rayparams.rx = vx;
|
rayparams->rx = state->vx;
|
||||||
rayparams.ry = vy;
|
rayparams->ry = state->vy;
|
||||||
}
|
}
|
||||||
disT = correctFisheye(disT, ra, w->s_player.pa);
|
rayparams->disT = correctfisheye(rayparams->disT,
|
||||||
rayparams.w = w;
|
base->ra, calc->w->s_player.pa);
|
||||||
rayparams.tileSize = tilesize;
|
rayparams->w = calc->w;
|
||||||
rayparams.r = r;
|
rayparams->tileSize = base->tilesize;
|
||||||
rayparams.disT = disT;
|
rayparams->r = calc->r;
|
||||||
rayparams.numRays = numrays;
|
rayparams->numRays = base->numrays;
|
||||||
rayparams.color = color;
|
rayparams->color = calc->color;
|
||||||
drawray(&rayparams);
|
}
|
||||||
ra += DR;
|
|
||||||
|
void drawrays2d(t_structure_main *w)
|
||||||
|
{
|
||||||
|
t_drawrays2d_params params;
|
||||||
|
|
||||||
|
init_base_params(¶ms.base_params, w);
|
||||||
|
params.ray_calc.w = w;
|
||||||
|
params.ray_calc.r = 0;
|
||||||
|
while (params.ray_calc.r++ < params.base_params.numrays)
|
||||||
|
{
|
||||||
|
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
||||||
|
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||||
|
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
||||||
|
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||||
|
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||||
|
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
||||||
|
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||||
|
calculatehorizontalray(¶ms.hrayparams);
|
||||||
|
calculateverticalray(¶ms.vrayparams);
|
||||||
|
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||||
|
¶ms.ray_calc, ¶ms.rayparams);
|
||||||
|
drawray(¶ms.rayparams);
|
||||||
|
params.base_params.ra += params.base_params.DR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 17:37:52 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/20 11:18:10 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ void draw_background(t_structure_main *w)
|
|||||||
sky_params.w = w;
|
sky_params.w = w;
|
||||||
sky_params.startHeight = 0;
|
sky_params.startHeight = 0;
|
||||||
sky_params.endHeight = w->s_win.height / 2;
|
sky_params.endHeight = w->s_win.height / 2;
|
||||||
sky_params.color = 0xB2FFFF;
|
sky_params.color = w->t->ceil_color;
|
||||||
sky_params.backgroundOffsetX = backgroundoffsetx;
|
sky_params.backgroundOffsetX = backgroundoffsetx;
|
||||||
draw_sky_ground(&sky_params);
|
draw_sky_ground(&sky_params);
|
||||||
ground_params.w = w;
|
ground_params.w = w;
|
||||||
ground_params.startHeight = w->s_win.height / 2;
|
ground_params.startHeight = w->s_win.height / 2;
|
||||||
ground_params.endHeight = w->s_win.height;
|
ground_params.endHeight = w->s_win.height;
|
||||||
ground_params.color = 0x280000;
|
ground_params.color = w->t->floor_color;
|
||||||
ground_params.backgroundOffsetX = backgroundoffsetx;
|
ground_params.backgroundOffsetX = backgroundoffsetx;
|
||||||
draw_sky_ground(&ground_params);
|
draw_sky_ground(&ground_params);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 20:56:42 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/20 11:12:22 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
|||||||
|
|
||||||
void load_wall_textures(t_structure_main *w)
|
void load_wall_textures(t_structure_main *w)
|
||||||
{
|
{
|
||||||
load_texture(w, "textures/NO.xpm", (void **)&w->s_img.north_texture);
|
load_texture(w, w->t->north, (void **)&w->s_img.north_texture);
|
||||||
load_texture(w, "textures/SO.xpm", (void **)&w->s_img.south_texture);
|
load_texture(w, w->t->south, (void **)&w->s_img.south_texture);
|
||||||
load_texture(w, "textures/WE.xpm", (void **)&w->s_img.west_texture);
|
load_texture(w, w->t->west, (void **)&w->s_img.west_texture);
|
||||||
load_texture(w, "textures/EA.xpm", (void **)&w->s_img.east_texture);
|
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_error(t_structure_main *w)
|
void exit_error(t_structure_main *w)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 21:26:16 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/20 11:05:59 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -60,6 +60,7 @@ void draw_texture(t_texture_params *params)
|
|||||||
|
|
||||||
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
||||||
{
|
{
|
||||||
|
void *texture = NULL;
|
||||||
if (wallDir == NORTH)
|
if (wallDir == NORTH)
|
||||||
return (w->s_img.north_texture);
|
return (w->s_img.north_texture);
|
||||||
else if (wallDir == SOUTH)
|
else if (wallDir == SOUTH)
|
||||||
@ -74,6 +75,10 @@ void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
|||||||
exit_error(w);
|
exit_error(w);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
if (texture == NULL)
|
||||||
|
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
||||||
|
else
|
||||||
|
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_texture_data get_texture_data(void *texture)
|
t_texture_data get_texture_data(void *texture)
|
||||||
@ -97,6 +102,7 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
|||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_data = get_texture_data(selected_texture);
|
texture_data = get_texture_data(selected_texture);
|
||||||
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
||||||
* (texture_data.bpp / 8);
|
* (texture_data.bpp / 8);
|
||||||
|
|||||||
97
main.c
97
main.c
@ -1,76 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/15 18:45:52 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2024/01/20 11:08:57 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub3d.h"
|
#include "cub3d.h"
|
||||||
|
|
||||||
float correctFisheye(float distance, float ra, float playerAngle) {
|
int setup_and_load_map(int argc, char **argv, t_structure_main *w, t_texture *textures)
|
||||||
float ca = playerAngle - ra;
|
|
||||||
if (ca < 0) ca += 2 * PI;
|
|
||||||
if (ca > 2 * PI) ca -= 2 * PI;
|
|
||||||
return distance * cos(ca);
|
|
||||||
}
|
|
||||||
|
|
||||||
int jkl = -1;
|
|
||||||
int yui = 0;
|
|
||||||
|
|
||||||
void test2(t_structure_main *w)
|
|
||||||
{
|
{
|
||||||
t_rescale_params params;
|
if (argc > 2)
|
||||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
|
||||||
w->s_img.buffer = mlx_new_image(w->s_win.mlx, w->s_win.width, w->s_win.height);
|
|
||||||
w->s_img.addr = mlx_get_data_addr(w->s_img.buffer, &(w->s_img.bpp), &(w->s_img.line_len), &(w->s_img.endian));
|
|
||||||
draw_map(w);
|
|
||||||
drawRays2D(w);
|
|
||||||
mlx_put_image_to_window(w->s_win.mlx, w->s_win.win, w->s_img.buffer, 0, 0);
|
|
||||||
int new_sprite_width = w->s_map.mapS;
|
|
||||||
int new_sprite_height = w->s_map.mapS;
|
|
||||||
int sprite_x = w->s_player.px - new_sprite_width / 2;
|
|
||||||
int sprite_y = w->s_player.py - new_sprite_height / 2;
|
|
||||||
params.original_img = w->s_img.roomadslam[jkl];
|
|
||||||
params.original_width = 112;
|
|
||||||
params.original_height = 112;
|
|
||||||
params.new_width = w->s_map.mapS;
|
|
||||||
params.new_height = w->s_map.mapS;
|
|
||||||
params.px = w->s_player.px - w->s_map.mapS / 2;
|
|
||||||
params.py = w->s_player.py - w->s_map.mapS / 2;
|
|
||||||
rescale_image(¶ms, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test(t_structure_main *w)
|
|
||||||
{
|
{
|
||||||
int x;
|
fprintf(stderr, "Usage: %s\n", argv[0]);
|
||||||
int y;
|
|
||||||
|
|
||||||
if (yui < 10)
|
|
||||||
{
|
|
||||||
usleep(1000);
|
|
||||||
yui++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yui = 0;
|
|
||||||
jkl++;
|
|
||||||
test2(w);
|
|
||||||
mlx_mouse_get_pos(w->s_win.mlx, w->s_win.win, &x, &y);
|
|
||||||
if ((x > 0 && x < w->s_win.height) && (y > 0 && y < w->s_win.width))
|
|
||||||
if (x != w->s_win.height/2)
|
|
||||||
{
|
|
||||||
if (x < w->s_win.height/2)
|
|
||||||
deal_key(65361,w);
|
|
||||||
else
|
|
||||||
deal_key(65363,w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (jkl == 10)
|
|
||||||
jkl = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int setup_and_load_map(int argc, char **argv, t_structure_main *w)
|
|
||||||
{
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Usage: %s <map_file>\n", argv[0]);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
parse_map("map.cub", &w->s_map);
|
if (!load_cub_file("map.cub", textures, &w->s_map))
|
||||||
if (!parse_map(argv[1], &w->s_map))
|
|
||||||
{
|
{
|
||||||
printf("Failed to load the map or map is not closed. Exiting...\n");
|
printf("Failed to load the map or map is not closed. Exiting...\n");
|
||||||
return (0);
|
return (0);
|
||||||
@ -86,11 +35,21 @@ int setup_and_load_map(int argc, char **argv, t_structure_main *w)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
t_structure_main w;
|
t_structure_main w;
|
||||||
|
t_global_struct global_struct;
|
||||||
|
|
||||||
if (!setup_and_load_map(argc, argv, &w))
|
w.t = malloc(sizeof(t_texture));
|
||||||
|
if (w.t == NULL)
|
||||||
|
{
|
||||||
|
// Gérer l'erreur d'allocation
|
||||||
|
}
|
||||||
|
ft_memset(w.t, 0, sizeof(t_texture));
|
||||||
|
global_struct.w = &w;
|
||||||
|
global_struct.state.jkl = -1;
|
||||||
|
global_struct.state.yui = 0;
|
||||||
|
if (!setup_and_load_map(argc, argv, &w, w.t))
|
||||||
return (1);
|
return (1);
|
||||||
init_windows(&w);
|
init_windows(&w);
|
||||||
mlx_loop_hook(w.s_win.mlx, (void *)test, &w);
|
mlx_loop_hook(w.s_win.mlx, (void *)sleep_mouse, &global_struct);
|
||||||
mlx_hook(w.s_win.win, 2, 1L << 0, deal_key, &w);
|
mlx_hook(w.s_win.win, 2, 1L << 0, deal_key, &w);
|
||||||
mlx_hook(w.s_win.win, 17, 0, (void *)kill_prog, &w);
|
mlx_hook(w.s_win.win, 17, 0, (void *)kill_prog, &w);
|
||||||
mlx_loop(w.s_win.mlx);
|
mlx_loop(w.s_win.mlx);
|
||||||
|
|||||||
7
map.cub
7
map.cub
@ -1,3 +1,10 @@
|
|||||||
|
NO textures/NO.xpm
|
||||||
|
SO textures/SO.xpm
|
||||||
|
WE textures/WE.xpm
|
||||||
|
EA textures/EA.xpm
|
||||||
|
F 80, 75, 61
|
||||||
|
C 165, 176, 196
|
||||||
|
|
||||||
1111111 11111111111111111111 11111111111 11111111111111111111111111111111111111111111111111111111111111
|
1111111 11111111111111111111 11111111111 11111111111111111111111111111111111111111111111111111111111111
|
||||||
111111000001110000000000000000001 10000000001 10000000000000000000000000000000001111111111111111111111111111
|
111111000001110000000000000000001 10000000001 10000000000000000000000000000000001111111111111111111111111111
|
||||||
1111100000000000000000000000000000001 10000000001 10000000000000000000000000000000000000000000000000000000000001
|
1111100000000000000000000000000000001 10000000001 10000000000000000000000000000000000000000000000000000000000001
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/15 20:04:23 by fgras-ca #+# #+# */
|
/* Created: 2024/01/15 20:04:23 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/21 11:54:07 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/20 11:14:36 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user