diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | inc/cub3d.h | 79 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 83 | ||||
-rw-r--r-- | src/ft_raycasting.c | 23 |
4 files changed, 110 insertions, 79 deletions
@@ -15,6 +15,7 @@ MLX_DIR = minilibx/ #--------------------------------- Files --------------------------------------# #==============================================================================# INCS = cub3d.h +INCS += cub3d_structs.h #------------------------------------------------------------------------------# SRCS_NAME = main.c SRCS_NAME += ft_init_lists.c @@ -41,6 +42,7 @@ SRCS_NAME += ft_init_winlx.c SRCS_NAME += ft_drawmap.c SRCS_NAME += ft_print_list.c SRCS_NAME += ft_rgb_to_hex.c +SRCS_NAME += ft_raycasting.c #------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #------------------------------------------------------------------------------# @@ -90,7 +92,7 @@ endif #==============================================================================# #--------------------------------- Rules --------------------------------------# #==============================================================================# -${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS} +${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}%.h @${MKDIR} ${OBJS_DIR} ifeq (${OS}, Darwin) ${CC} -c ${CFLAGS} ${CDEFS} -I${LFT_DIR}${INCS_DIR} -I${MLX_DIR} -I${INCS_DIR} -o $@ $< diff --git a/inc/cub3d.h b/inc/cub3d.h index ceba8cd..777360b 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -16,6 +16,7 @@ #include <stddef.h> #include <stdint.h> +#include <cub3d_structs.h> # ifndef FT_W_KEY # define FT_W_KEY 13 @@ -42,84 +43,6 @@ # define FT_SCR_SIZE "1920x1080" # endif -typedef struct s_win -{ - void *wlx; - void *winptr; - uint8_t inited; - uint16_t x_max_size; - uint16_t y_max_size; - uint16_t x_size; - uint16_t y_size; -} t_win; - -typedef struct s_img -{ - void *img; - char *ptr; - int bpp; - int sizeline; - int endian; -} t_img; - -typedef struct s_rgb -{ - int16_t r; - int16_t g; - int16_t b; -} t_rgb; - -/* -** view_side: -** 1: North -** 2: East -** 3: South -** 4: West -*/ - -typedef struct s_player -{ - float pos_x; - float pos_y; - float view_side; -} t_player; - -typedef struct s_ray -{ - double x_ray_position; - double y_ray_position; - double x_ray_direction; - double y_ray_direction; - double x_side_distance; - double y_side_distance; - double x_delta_distance; - double y_delta_distance; - int hitX; - int hitY; - int hits[150]; -} t_ray; - -typedef struct s_cub -{ - char *no_tex_path; - char *so_tex_path; - char *ea_tex_path; - char *we_tex_path; - char *sprite_path; - char *mapl; - char **map; - size_t map_w; - size_t map_h; - size_t line_chk; - size_t map_start; - uint8_t isspawn; - uint8_t scale; - struct s_win *wlist; - struct s_player *plist; - struct s_img img; - struct s_rgb f_rgb; - struct s_rgb c_rgb; -} t_cub; /* ** ret vals: diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h new file mode 100644 index 0000000..1a45860 --- /dev/null +++ b/inc/cub3d_structs.h @@ -0,0 +1,83 @@ +#ifndef CUB3D_STRUCTS_H +#define CUB3D_STRUCTS_H + +typedef struct s_win +{ + void *wlx; + void *winptr; + uint8_t inited; + uint16_t x_max_size; + uint16_t y_max_size; + uint16_t x_size; + uint16_t y_size; +} t_win; + +typedef struct s_img +{ + void *img; + char *ptr; + int bpp; + int sizeline; + int endian; +} t_img; + +typedef struct s_rgb +{ + int16_t r; + int16_t g; + int16_t b; +} t_rgb; + +/* +** player view_side: +** 1: North +** 2: East +** 3: South +** 4: West +*/ + +typedef struct s_player +{ + float pos_x; + float pos_y; + float view_side; +} t_player; + +typedef struct s_ray +{ + double x_ray_position; + double y_ray_position; + double x_ray_direction; + double y_ray_direction; + double x_side_distance; + double y_side_distance; + double x_delta_distance; + double y_delta_distance; + int hitX; + int hitY; + int hits[150]; +} t_ray; + +typedef struct s_cub +{ + char *no_tex_path; + char *so_tex_path; + char *ea_tex_path; + char *we_tex_path; + char *sprite_path; + char *mapl; + char **map; + size_t map_w; + size_t map_h; + size_t line_chk; + size_t map_start; + uint8_t isspawn; + uint8_t scale; + struct s_win *wlist; + struct s_player *plist; + struct s_img img; + struct s_rgb f_rgb; + struct s_rgb c_rgb; +} t_cub; + +#endif diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c new file mode 100644 index 0000000..1f81840 --- /dev/null +++ b/src/ft_raycasting.c @@ -0,0 +1,23 @@ +#include <cub3d.h> +#include <stdint.h> + +static void +ft_initray(t_cub *clist, uint16_t i) +{ + (void)clist; + (void)i; +} + +void +ft_castray(t_cub *clist) +{ + uint16_t i; + + i = 0; + while (i < clist->wlist->size_y) + { + ft_initray(clist. i); + p_s->line + i++; + } +} |