diff options
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 4 | ||||
-rw-r--r-- | map/map_one.cub | 4 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 30 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 1 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 4 | ||||
-rw-r--r-- | src/ft_raycasting.c | 63 |
7 files changed, 52 insertions, 55 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 8eebc00..24ea92a 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -93,5 +93,6 @@ void ft_music(t_cub *cl); void ft_calc_sprite(t_cub *cl); void ft_calc_sprite_norme(t_cub *cl); void ft_draw_sprite(t_cub *cl); +void ft_get_sprite_spawn(t_cub *cl); # endif diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index a173e8c..91a1ee9 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -50,6 +50,8 @@ typedef struct s_rgb typedef struct s_sprite { int32_t s_screen_x; + int32_t x; + int32_t y; int32_t s_pos_x; int32_t s_pos_y; double s_x; @@ -137,7 +139,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; + struct s_sprite sprites; } t_cub; # endif diff --git a/map/map_one.cub b/map/map_one.cub index 05cb705..5a322c2 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -10,8 +10,8 @@ C 50,100,200 F 50,190,124 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 2 0 0 0 0 0 0 0 0 0 0 0 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 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 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 7e7114f..28ffb10 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,32 +16,24 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -/* -void - ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) -{ - if (cl->tlist[4].tex_x) -} -*/ + void ft_draw_sprite(t_cub *cl) { - int itx; - int ity; int d; int tex_x; int tex_y; - itx = cl->sp_list.s_start_x; - while (itx < cl->sp_list.s_end_x) + cl->sprites.x = cl->sprites.s_start_x; + while (cl->sprites.x < cl->sprites.s_end_x) { - tex_x = (int)((itx - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) - * cl->tlist[4].img_w / cl->sp_list.s_w); - ity = cl->sp_list.s_start_y; - while (ity < cl->sp_list.s_end_y) + tex_x = (int)((cl->sprites.x - (-cl->sprites.s_w / 2 + cl->sprites.s_screen_x)) + * cl->tlist[4].img_w / cl->sprites.s_w); + cl->sprites.y = cl->sprites.s_start_y; + while (cl->sprites.y < cl->sprites.s_end_y) { - d = ity * 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 = cl->sprites.y * 256 - cl->wlist->y_size * 128 + cl->sprites.s_h * 128; + tex_y = ((d * cl->tlist[4].img_h) / cl->sprites.s_h) / 256; if (*(cl->tlist[4].ptr + tex_x + tex_y * cl->tlist[4].sizeline / 4)) { cl->img.ptr[tex_x * 4 + (cl->img.sizeline * tex_y)] = @@ -49,8 +41,8 @@ void cl->tlist[4].img_h * tex_y]; /*puts("qwe");*/ } - ity++; + cl->sprites.y++; } - itx++; + cl->sprites.x++; } } diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 617ec22..774a80e 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -82,6 +82,7 @@ void plist->start_x = plist->pos_x; plist->start_y = plist->pos_y; ft_get_start_side(clist->mlist->map[y][x], clist->plist); + ft_get_sprite_spawn(clist); return ; } x++; diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 806489f..76629c5 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -28,8 +28,8 @@ void { 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; + clist->sprites.s_pos_x = x + 0.5; + clist->sprites.s_pos_y = y + 0.5; return ; } x++; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 5bf0785..be4a815 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -20,44 +20,45 @@ 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_y + cl->sprites.s_x = cl->sprites.s_pos_x - cl->plist->pos_x; + cl->sprites.s_y = cl->sprites.s_pos_y - cl->plist->pos_y; + cl->sprites.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * 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)); + cl->sprites.sprite_transform_x = cl->sprites.inv_c_m + * (cl->plist->dir_y * cl->sprites.s_x + - cl->plist->dir_x * cl->sprites.s_y); + cl->sprites.sprite_transform_y = cl->sprites.inv_c_m + * (-cl->plist->plane_y * cl->sprites.s_x + + cl->plist->plane_x * cl->sprites.s_y); + cl->sprites.s_screen_x = (int)((cl->wlist->x_size / 2) + * (1 + cl->sprites.sprite_transform_x + / cl->sprites.sprite_transform_y)); + cl->sprites.s_h = + abs((int)(cl->wlist->y_size * cl->sprites.sprite_transform_y)); ft_calc_sprite_norme(cl); } void ft_calc_sprite_norme(t_cub *cl) { - 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; - /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/ - /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/ - ft_draw_sprite(cl); + cl->sprites.s_start_y = -cl->sprites.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sprites.s_start_y < 0) + cl->sprites.s_start_y = 0; + cl->sprites.s_end_y = cl->sprites.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sprites.s_end_y > (int)cl->wlist->y_size) + cl->sprites.s_end_y = cl->wlist->y_size - 1; + cl->sprites.s_w = abs((int)(cl->wlist->y_size + / cl->sprites.sprite_transform_y)); /*sprite width*/ + cl->sprites.s_start_x = -cl->sprites.s_w / 2 + cl->sprites.s_screen_x; + if (cl->sprites.s_start_x < 0) + cl->sprites.s_start_x = 0; + cl->sprites.s_end_x = cl->sprites.s_w / 2 + cl->sprites.s_screen_x; + printf("%d\n", cl->sprites.s_w); + if (cl->sprites.s_end_x > (int)cl->wlist->x_size) + cl->sprites.s_end_x = cl->wlist->x_size - 1; + /*ft_printf("start x: %d\nend x : %d\n", cl->sprites.s_start_x, cl->sprites.s_end_x);*/ + /*ft_printf("start y: %d\nend y : %d\n", cl->sprites.s_start_y, cl->sprites.s_end_y);*/ + /*ft_draw_sprite(cl);*/ } |