From da01f1737b2f6c748a8b667ccd2e3d0e314724ba Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 21 Feb 2020 19:47:21 +0100 Subject: on est la --- inc/cub3d_structs.h | 3 +++ src/main.c | 13 ------------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index f5c295c..7731563 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -49,11 +49,14 @@ typedef struct s_rgb typedef struct s_sprite { + int32_t s_x; + int32_t s_y; int32_t s_h; int32_t s_w; int32_t s_start_x; int32_t s_start_y; int32_t s_tex_y; + double sprite_dist; } t_sprite; typedef struct s_player diff --git a/src/main.c b/src/main.c index ededacf..52bb211 100644 --- a/src/main.c +++ b/src/main.c @@ -15,30 +15,17 @@ #include #include #include -#include -#include - -void - *ft_zik(void *vargp) -{ - (void)vargp; - system("afplay revelations.mp3"); - return NULL; -} int main(int argc, const char *argv[]) { t_cub *clist; - pthread_t thread_id; if (argc < 2) { ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m"); return (1); } - pthread_create(&thread_id, NULL, ft_zik, NULL); - pthread_join(thread_id, NULL); if (ft_init_cub3d(&clist) < 0) return (2); ft_parse_map(argv[1], clist); -- cgit v1.2.3 From 2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 21 Feb 2020 21:44:26 +0100 Subject: que des maths --- inc/cub3d.h | 1 - inc/cub3d_structs.h | 10 ++++++++-- src/ft_get_sprite.c | 20 +++++++++++++++++++- src/ft_raycasting.c | 12 ++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/inc/cub3d.h b/inc/cub3d.h index 09ea32e..87f6ef3 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -83,6 +83,5 @@ void ft_draw_circle(int32_t a, int32_t b, int32_t color, t_cub *cl); void ft_draw_texture(t_cub *cl, int x, int y, int tex_y); int8_t ft_check_not_found(const char *path); -void ft_calc_tex(t_cub *clist); # endif diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 7731563..72cc377 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -49,14 +49,19 @@ typedef struct s_rgb typedef struct s_sprite { - int32_t s_x; - int32_t s_y; + int32_t s_pos_x; + int32_t s_pos_y; + double s_x; + double s_y; int32_t s_h; int32_t s_w; int32_t s_start_x; int32_t s_start_y; int32_t s_tex_y; + double sprite_transform_x; + double sprite_transform_y; double sprite_dist; + double inv_c_m; } t_sprite; typedef struct s_player @@ -128,6 +133,7 @@ typedef struct s_cub struct s_rgb f_rgb; struct s_rgb c_rgb; struct s_img tlist[5]; + struct s_sprite sp_list; } t_cub; # endif diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 43de290..806489f 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -17,8 +17,26 @@ void ft_get_sprite_spawn(t_cub *clist) { + size_t x; + size_t y; - (void)clist; + x = 1; + y = 1; + while (clist->mlist->map[y]) + { + while (clist->mlist->map[y][x]) + { + if (ft_ischarset("2", clist->mlist->map[y][x])) + { + clist->sp_list.s_pos_x = x + 0.5; + clist->sp_list.s_pos_y = y + 0.5; + return ; + } + x++; + } + x = 1; + y++; + } } int8_t diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index dd2be64..589d2da 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -16,6 +16,17 @@ #include void + ft_calc_sprite(t_cub *cl) +{ + cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x; + cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist->pos_y; + cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x - cl->plist->dir_y * cl->plist->plane_y); + cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m * (cl->plist->dir_y * cl->sp_list.s_x - cl->plist->dir_x * cl->sp_list.s_y); + cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y); + +} + +static void ft_calc_tex(t_cub *clist) { if (clist->rlist.side == 0) @@ -83,6 +94,7 @@ void cl->rlist.wall_b = wl->y_size - 1; ft_choose_tex(cl); ft_calc_tex(cl); + ft_calc_sprite(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } -- cgit v1.2.3 From d2f53e38cbf711e35035a4576070a5211a1d055d Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sat, 22 Feb 2020 20:56:50 +0100 Subject: shpritz --- Makefile | 5 +++-- inc/cub3d.h | 1 + inc/cub3d_structs.h | 3 +++ src/ft_draw_sprite.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/ft_raycasting.c | 20 ++++++++++++++++++-- 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/ft_draw_sprite.c diff --git a/Makefile b/Makefile index 90a09d7..c0773e3 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ SRCS_NAME += ft_draw_textures.c SRCS_NAME += ft_key_release.c SRCS_NAME += ft_convert_keycode.c SRCS_NAME += ft_key_loop.c +SRCS_NAME += ft_draw_sprite.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# @@ -151,14 +152,14 @@ endif @$(MAKE) --no-print-directory -C ${LFT_DIR} clean ${RM} ${OBJS_DIR} #--------------------------------------------------------------------------------------------------# -fclean: clean +fclean: clean @$(MAKE) --no-print-directory -C ${LFT_DIR} fclean ${RM} ${NAME} ${RM} ${NAME}.dSYM #--------------------------------------------------------------------------------------------------# re: fclean all #--------------------------------------------------------------------------------------------------# -run: all +run: all @./${NAME} "map/map_one.cub" #--------------------------------------------------------------------------------------------------# .PHONY: all clean clean fclean re run default diff --git a/inc/cub3d.h b/inc/cub3d.h index 87f6ef3..2d9853c 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -83,5 +83,6 @@ void ft_draw_circle(int32_t a, int32_t b, int32_t color, t_cub *cl); void ft_draw_texture(t_cub *cl, int x, int y, int tex_y); int8_t ft_check_not_found(const char *path); +void ft_draw_sprite(t_cub *cl, int i); # endif diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 72cc377..4c397b2 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -49,6 +49,7 @@ typedef struct s_rgb typedef struct s_sprite { + int32_t s_screen_x; int32_t s_pos_x; int32_t s_pos_y; double s_x; @@ -57,6 +58,8 @@ typedef struct s_sprite int32_t s_w; int32_t s_start_x; int32_t s_start_y; + int32_t s_end_x; + int32_t s_end_y; int32_t s_tex_y; double sprite_transform_x; double sprite_transform_y; diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c new file mode 100644 index 0000000..38c1fd9 --- /dev/null +++ b/src/ft_draw_sprite.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +void +ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) +{ + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; +} + +void +ft_draw_sprite(t_cub *cl, int x) +{ + int ver_it;/*stripe*/ + int hor_it;/*y*/ + int tex_x; + int tex_y; + int d; + + ver_it = cl->sp_list.s_start_x; + while (ver_it < cl->sp_list.s_end_x) + { + tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; + hor_it = cl->sp_list.s_start_y; + while (hor_it < cl->sp_list.s_end_y) + { + d = hor_it * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; + tex_y = ((d * cl->tlist[4].img_h) / cl->sp_list.s_h) / 256; + ft_draw_verline_sprite(cl, x, hor_it, tex_y); + } + ver_it++; + } +} diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 589d2da..b42e0b7 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -13,6 +13,7 @@ #include #include #include +#include #include void @@ -23,7 +24,21 @@ void cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x - cl->plist->dir_y * cl->plist->plane_y); cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m * (cl->plist->dir_y * cl->sp_list.s_x - cl->plist->dir_x * cl->sp_list.s_y); cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y); - + cl->sp_list.s_screen_x = (int)((cl->wlist->y_size / 2) * (1 + cl->sp_list.sprite_transform_x / cl->sp_list.sprite_transform_y)); + cl->sp_list.s_h = abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y)); /*sprite height*/ + cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_start_y < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_end_y > (int)cl->wlist->y_size) + cl->sp_list.s_end_y = cl->wlist->y_size - 1;; + cl->sp_list.s_w = abs((int)(cl->wlist->x_size * cl->sp_list.sprite_transform_y)); /*sprite width*/ + cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x; + if (cl->sp_list.s_start_x < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size; + if (cl->sp_list.s_end_x < (int)cl->wlist->x_size) + cl->sp_list.s_end_x = cl->wlist->x_size - 1; } static void @@ -35,7 +50,7 @@ static void else clist->rlist.wall_hit_x = (clist->plist->pos_y) + clist->rlist.wall_dist * clist->rlist.x_ray_dir; - clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); + clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x * (double)clist->tlist[clist->w_side].img_w); if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) @@ -95,6 +110,7 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_calc_sprite(cl); + ft_draw_sprite(cl , i); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } -- cgit v1.2.3 From 9fc4434c0deac6a3537183266adb9e85f3883db8 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 10:20:20 +0100 Subject: tests --- src/ft_detect.c | 3 +-- src/ft_draw_sprite.c | 12 ++++++++---- src/ft_raycasting.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ft_detect.c b/src/ft_detect.c index fc49a2d..10d7147 100644 --- a/src/ft_detect.c +++ b/src/ft_detect.c @@ -74,8 +74,7 @@ void cl->rlist.sqy += cl->mlist->y_step; cl->rlist.side = 1; } - if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1' - || cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '2') + if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1') cl->rlist.hit = 1; } } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 38c1fd9..e7df49b 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -29,15 +30,18 @@ ft_draw_sprite(t_cub *cl, int x) int d; ver_it = cl->sp_list.s_start_x; - while (ver_it < cl->sp_list.s_end_x) + ver_it = (ver_it < 0) ? -ver_it : ver_it ; + while (ver_it < cl->sp_list.s_end_x - 1) { tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y) + while (hor_it < cl->sp_list.s_end_y - 1) { - d = hor_it * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; - tex_y = ((d * cl->tlist[4].img_h) / cl->sp_list.s_h) / 256; + d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; + tex_y = ((d * cl->tlist[4].img_w) / cl->sp_list.s_h) / 256; ft_draw_verline_sprite(cl, x, hor_it, tex_y); + hor_it++; + printf("hor_it : %d ver it : %d", hor_it, ver_it); } ver_it++; } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index b42e0b7..dd68cd3 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -110,8 +110,8 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_calc_sprite(cl); - ft_draw_sprite(cl , i); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); + ft_draw_sprite(cl , i); i++; } } -- cgit v1.2.3 From 84a92b0d2824a97c3358f8ce86290aa8a718618e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 18:19:58 +0100 Subject: very bad --- map/img/pillar.xpm | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ map/map_one.cub | 4 +-- src/ft_draw_sprite.c | 53 +++++++++++++++--------------- src/ft_key_loop.c | 2 +- 4 files changed, 121 insertions(+), 29 deletions(-) create mode 100644 map/img/pillar.xpm diff --git a/map/img/pillar.xpm b/map/img/pillar.xpm new file mode 100644 index 0000000..4a0c656 --- /dev/null +++ b/map/img/pillar.xpm @@ -0,0 +1,91 @@ +/* XPM */ +static char *_8e53538c4e441a6b69ed6027602859e[] = { +/* columns rows colors chars-per-pixel */ +"64 64 21 1 ", +" c black", +". c #202020", +"X c #2C2C2C", +"o c gray22", +"O c gray25", +"+ c #484848", +"@ c #4C4C4C", +"# c gray33", +"$ c gray36", +"% c #646464", +"& c gray44", +"* c #7C7C7C", +"= c gray55", +"- c #989898", +"; c gray66", +": c #B4B4B4", +"> c #C0C0C0", +", c #D0D0D0", +"< c gainsboro", +"1 c #ECECEC", +"2 c gray99", +/* pixels */ +" ;;;;=======&&&&% ", +" ;;<<,,,>>>::;;--==*&&%#+## ", +" >22111<<<,,,>>::;-&>=*&%#+OooX ", +" 12222111222<<,>>::;--=**+#+Ooo.X ", +" <112222221<,>>::;;-=**&%%%%oOoX.XX ", +" <<1122211,,,>>;,;;-=**&%%#O+XX..XX ", +" ><<2122111<<,,>>::;-=*&%#+OXo..XXX ", +" >>211221122<<,>>;;-=*&%#OoX...XX ", +" :1122221<,>;:-=*&%#+OXoX.... ", +" :>>2221<,>:;-=*&%#+OoXX..X ", +" ->1221<,>:;-=*&#%+OoX..X ", +" ->1221<,>:;-=*&%#+OoX..X ", +" ->2221<,>:;=;*&%#+OXo..X ", +" ->2221<,>:=-;*&%#+OoX..X ", +" ->2221<,>:;-=*&%O%OoX..X ", +" ->2221<,>:;-=*&%#%OoX..X ", +" ->11<,>:;-=*&%#+O+X....X ", +" -=;:;;==*&&%%#+OoX...... ", +" <2<1221<,>:;-=*&#%+o.X ", +" ><2222<,>:;-=*&%#+#oXX.o ", +" ><2221<,,:;-*=&%#+OoX..X ", +" ->2221<:1:;-=&*%#+OoX..X ", +" ->2221<>1:;-=*&%#+OXo..X ", +" ->2221<,,:;-=*&#%+OoX .X ", +" ->2221<,>:;-=*&%#+X+X..X ", +" -;2221:2>:;-=*&%#+OoX..X ", +" -<2221<,>:;-*-&%#+oOX..X ", +" ->2221<:<:;-=*&%+#OoX..X ", +" ->2221<,>:;=-*&%#+OXo..X ", +" *-<1<,>:;-=*&%#+OoX..... ", +" *-;-==**&&%%#+OoX.. ", +" ;,22222><,>:;-=*&%#+oXXo ", +" ->2221<1>:;-=*&%#+OoX..X ", +" ->2221<,>:;=-*%*#+OXO .X ", +" ->2221<:1:;-=*&%#O+oX..X ", +" ->22<2<,>:;-=*&%+#Oo.X.X ", +" ->2121<:>;:-*=&%##OoX... ", +" ->2221:2>:;-=*&%#+oOX..X ", +" ->22212,>:;-=&*%#+OoX..X ", +" ->22<2<,>:;=-*&%#O+Xo..X ", +" ->2221<,:<;-=*&#%+OoX..X ", +" ->2221,1>:;-=&*%#+OXo..X ", +" *>1211<,>:--=*&%+#OoX..o ", +" ;,<>>>:;-&-&%#+OoX.... ", +" ;1:>,>-=*&#%%#+OoX...... ", +" -,212221<,>:=-=*&%#+o.XX ", +" ->2221<,>:;-*-&%#+OXO..X ", +" ->222,2,>-<-=*&%#+OoX..X ", +" ->2221<,>:;-*-&%+#OoX..X ", +" ->2221<,>:;-=*&#%+OoX..X ", +" ->2221<,>->-=*%&#+OoX..X ", +" ->2221<,;<;-=*&%#O#oX..X ", +" ->122,2,>:;-=*&%#+OoX..X ", +" ->122,2,>:;-=*&%+#OoX..X ", +" :<>2221<,>:-:=*&%#+OoXo..X ", +" :1122221<,>:;-=*&%#+OXoX...XX ", +" >>212221122<<,>>;;-=*&%#OoX...XXXO+@##$$%% ", +" ><<2122111<<,,>>::;-=*&%#+OXo..XXXooO++@##$%% ", +" <<1122211,,,>>::;;=;**&%%#O+XX..XXooooO++@#$$% ", +" <112222221<,>>::;;-=**&%%&%@@oX.XXooooO++@#$$% ", +" 12222111222<<,>>::;--=**&$O$oo.XoooOO+@@#$$% ", +" >22111<<<,,,>:,:;--=*=&%$+OooXOOO+++@#$$% ", +" ;;<<,,,>>>::;;--==*&&%#+OO+#$$$%%%%%% ", +" ;;;;=======&&&&%#OO+#$%% " +}; diff --git a/map/map_one.cub b/map/map_one.cub index 168e1e8..f47183c 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -4,7 +4,7 @@ NO ./map/img/BRIQUASSES.xpm SO ./map/img/BRIQUASSE_3.xpm EA ./map/img/BRIQUASSES_2.xpm WE ./map/img/MURLOL.xpm -S ./map/img/segfot.xpm +S ./map/img/pillar.xpm C 50,100,200 F 50,190,124 @@ -12,7 +12,7 @@ F 50,190,124 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 N 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 +1 E 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index e7df49b..5f7fd31 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -8,41 +8,42 @@ void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 1]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 2]; - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + if (cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y] != 0) + { + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + } + else + { + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)255; + } } void -ft_draw_sprite(t_cub *cl, int x) + ft_draw_sprite(t_cub *cl, int x) { int ver_it;/*stripe*/ int hor_it;/*y*/ - int tex_x; - int tex_y; int d; + int tex_y; ver_it = cl->sp_list.s_start_x; - ver_it = (ver_it < 0) ? -ver_it : ver_it ; - while (ver_it < cl->sp_list.s_end_x - 1) + hor_it = cl->sp_list.s_start_y; + while (hor_it < cl->sp_list.s_end_y) { - tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; - hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y - 1) - { - d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; - tex_y = ((d * cl->tlist[4].img_w) / cl->sp_list.s_h) / 256; - ft_draw_verline_sprite(cl, x, hor_it, tex_y); - hor_it++; - printf("hor_it : %d ver it : %d", hor_it, ver_it); - } - ver_it++; + d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = (d <= 0) ? (-d) : (d); + tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256; + ft_draw_verline_sprite(cl, x, hor_it, tex_y); + hor_it++; } } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index b902e33..aa7017f 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -46,8 +46,8 @@ int { (*fun_ptr[cl->key_input[i]])(cl); ft_collision(old_y, old_x, cl->plist, cl->mlist); - ft_draw_scene(cl); i++; } + ft_draw_scene(cl); return (0); } -- cgit v1.2.3 From 6a56c9beea934597431643994f85479bc1792466 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 19:01:52 +0100 Subject: oy --- src/ft_draw_sprite.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5f7fd31..c90c9ac 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -8,9 +8,7 @@ void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { - if (cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * - cl->tlist[4].img_h * tex_y] != 0) - { + if (cl->tlist[4].tex_x) cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * cl->tlist[4].img_h * tex_y]; @@ -21,28 +19,22 @@ ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * cl->tlist[4].img_h * tex_y + 2]; cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; - } - else - { - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)255; - } } void ft_draw_sprite(t_cub *cl, int x) { - int ver_it;/*stripe*/ int hor_it;/*y*/ int d; int tex_y; - ver_it = cl->sp_list.s_start_x; hor_it = cl->sp_list.s_start_y; while (hor_it < cl->sp_list.s_end_y) { - d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; - d = (d <= 0) ? (-d) : (d); + d = hor_it * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = (d <= 0) ? (-d) : (d); tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256; + (tex_y < 0) ? (tex_y = 0) : 0; ft_draw_verline_sprite(cl, x, hor_it, tex_y); hor_it++; } -- cgit v1.2.3